forked from dabeaz/generators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
netsend.py
39 lines (27 loc) · 935 Bytes
/
netsend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# netsend.py
#
# Consume items and send them to a remote machine
import socket, pickle
class NetConsumer(object):
def __init__(self,addr):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.connect(addr)
def send(self,item):
pitem = pickle.dumps(item)
self.s.sendall(pitem)
def close(self):
self.s.close()
# Example use. This requires you to run receivefrom.py first.
if __name__ == '__main__':
from broadcast import broadcast
from follow import follow
from apachelog import apache_log
# A class that sends 404 requests to another host
class Stat404(NetConsumer):
def send(self,item):
if item['status'] == 404:
NetConsumer.send(self,item)
stat404 = Stat404(("",15000))
lines = follow(open("run/foo/access-log"))
log = apache_log(lines)
broadcast(log,[stat404])