turbostat: Fix parsing warnings
[collectd.git] / contrib / network-proxy.py
1 #!/usr/bin/env python
2 # vim: sts=4 sw=4 et
3
4 # Simple unicast proxy to send collectd traffic to another host/port.
5 # Copyright (C) 2007  Pavel Shramov <shramov at mexmat.net>
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the Free
9 # Software Foundation; only version 2 of the License is applicable.
10 #
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14 # more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 # Place, Suite 330, Boston, MA  02111-1307  USA
19
20 """
21 Simple unicast proxy for collectd (>= 4.0).
22 Binds to 'local' address and forwards all traffic to 'remote'.
23 """
24
25 import socket
26 import struct
27
28 """ Local multicast group/port"""
29 local  = ("239.192.74.66", 25826)
30 """ Address to send packets """
31 remote = ("grid.pp.ru", 35826)
32
33 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
34 mreq = struct.pack("4sl", socket.inet_aton(local[0]), socket.INADDR_ANY)
35
36 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
37 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 1)
38 sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
39 sock.bind(local)
40
41 out = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
42
43 if __name__ == "__main__":
44     while True:
45         (buf, addr) = sock.recvfrom(2048)
46         sock.sendto(buf, remote)