From bb0113bb20189c412dbc3a1c8ddda6c2f257056f Mon Sep 17 00:00:00 2001 From: Schrolli Date: Fri, 22 May 2015 10:44:39 +0200 Subject: [PATCH] plugin httpRequest --- plugins/httpRequest/httpRequest.py | 41 +++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/plugins/httpRequest/httpRequest.py b/plugins/httpRequest/httpRequest.py index 8b27b1a..c0655ed 100644 --- a/plugins/httpRequest/httpRequest.py +++ b/plugins/httpRequest/httpRequest.py @@ -23,6 +23,8 @@ import globals # Global variables # usable Loglevels debug|info|warning|error|exception|critical # if you use .exception in Try:Exception: Construct, it logs the Python EX.message too +import httplib #for the HTTP request + def run(typ,freq,data): try: #ConfigParser @@ -32,16 +34,37 @@ def run(typ,freq,data): logging.debug(" - %s = %s", key, val) except: logging.exception("cannot read config file") - -########## User Plugin CODE ########## - if typ == "FMS": - logging.warning("%s not supported", typ) - elif typ == "ZVEI": - logging.warning("%s not supported", typ) - elif typ == "POC": - logging.warning("%s not supported", typ) + +########## User Plugin CODE ########## + try: + logging.debug("send %s HTTP request", typ) + + if typ == "FMS": + httprequest = httplib.HTTPConnection(globals.config.get("httpRequest", "fms_url")) + httprequest.request("HEAD", "/") + elif typ == "ZVEI": + httprequest = httplib.HTTPConnection(globals.config.get("httpRequest", "zvei_url")) + httprequest.request("HEAD", "/") + elif typ == "POC": + httprequest = httplib.HTTPConnection(globals.config.get("httpRequest", "poc_url")) + httprequest.request("HEAD", "/") + else: + logging.warning("Invalid Typ: %s", typ) + + except: + loggin.exception("cannot send HTTP request") else: - logging.warning("Invalid Typ: %s", typ) + + try: + httpresponse = httprequest.getresponse() + if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error + logging.debug("HTTP response: %s - %s" , str(httpresponse.status), str(httpresponse.reason)) + else: + logging.warning("HTTP response: %s - %s" , str(httpresponse.status), str(httpresponse.reason)) + except NameError: #if var httprequest does not exist + logging.exception("no HTTP request been sended") + except: #otherwise + logging.exception("cannot get HTTP response") ########## User Plugin CODE ########## except: