from twisted.internet import protocol, reactor
import socket,os
socket_path = "/var/lib/nagios3/rw/live"
class Echo(protocol.Protocol):
def dataReceived(self, data):
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(socket_path)
s.send(data)
s.shutdown(socket.SHUT_WR)
answer = s.recv(100000000)
self.transport.write(answer)
class EchoFactory(protocol.Factory):
def buildProtocol(self, addr):
return Echo()
reactor.listenTCP(6557, EchoFactory())
reactor.run()
Thursday, July 4, 2013
Bind livestatus unix socket to TCP socket use Python and twisted
Labels:
Linux,
livestatus,
nagios,
python,
twisted
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment