Created
November 20, 2009 10:26
-
-
Save qingfeng/239402 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
/usr/local/bin/curl -F "data=xxx.xxx.xx_ja;0;PING OK" http://<IP>:8888/ | |
/usr/local/bin/curl -F "data=xxx.xxx.xx_ja;PING;0;PING OK" http://<IP>:8888/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.httpserver | |
import tornado.ioloop | |
import tornado.web | |
import time | |
import os | |
CMD_FILE = "/tmp/nagios.cmd" | |
def process_data(data): | |
results = data.split(";") | |
if len(results)==3: | |
c1 = "PROCESS_HOST_CHECK_RESULT" | |
else: | |
c1 = "PROCESS_SERVICE_CHECK_RESULT" | |
msg = "[%s] %s;%s\n" % (int(time.time()),c1,data[0]) | |
return msg | |
def writefifo(msg): | |
try: | |
fd = os.open(CMD_FILE,os.O_RDWR|os.O_NONBLOCK) | |
os.write(fd,msg) | |
finally: | |
try: | |
os.close(fd) | |
except: | |
pass | |
return True | |
class MainHandler(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
def post(self): | |
if 'data' in self.request.arguments: | |
data = self.request.arguments['data'] | |
msg = process_data(data[0]) | |
self.write(msg) | |
writefifo(msg) | |
self.finish() | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
http_server = tornado.httpserver.HTTPServer(application) | |
http_server.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment