mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-01-20 15:20:16 +01:00
plugin httpRequest
This commit is contained in:
parent
1640a49261
commit
bb0113bb20
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue