mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-04-05 14:35:17 +00:00
rename globals. call to globalVars.
This commit is contained in:
parent
f8fcda94b6
commit
e938cdcd6d
27 changed files with 300 additions and 300 deletions
|
|
@ -60,7 +60,7 @@ def bosMonRequest(httprequest, params, headers):
|
|||
#
|
||||
# BosMon/HTTP-Request
|
||||
#
|
||||
httprequest.request("POST", "/telegramin/"+globals.config.get("BosMon", "bosmon_channel")+"/input.xml", params, headers)
|
||||
httprequest.request("POST", "/telegramin/"+globalVars.config.get("BosMon", "bosmon_channel")+"/input.xml", params, headers)
|
||||
except:
|
||||
logging.error("request to BosMon failed")
|
||||
logging.debug("request to BosMon failed", exc_info=True)
|
||||
|
|
@ -110,12 +110,12 @@ def run(typ,freq,data):
|
|||
headers['Content-type'] = "application/x-www-form-urlencoded"
|
||||
headers['Accept'] = "text/plain"
|
||||
# if an user is set in the config.ini we will use HTTP-Authorization
|
||||
if globals.config.get("BosMon", "bosmon_user"):
|
||||
if globalVars.config.get("BosMon", "bosmon_user"):
|
||||
# generate b64encoded autorization-token for HTTP-request
|
||||
headers['Authorization'] = "Basic {0}".format(base64.b64encode("{0}:{1}".format(globals.config.get("BosMon", "bosmon_user"), globals.config.get("BosMon", "bosmon_password"))))
|
||||
headers['Authorization'] = "Basic {0}".format(base64.b64encode("{0}:{1}".format(globalVars.config.get("BosMon", "bosmon_user"), globalVars.config.get("BosMon", "bosmon_password"))))
|
||||
logging.debug("connect to BosMon")
|
||||
# open connection to BosMon-Server
|
||||
httprequest = httplib.HTTPConnection(globals.config.get("BosMon", "bosmon_server"), globals.config.get("BosMon", "bosmon_port"), timeout=5)
|
||||
httprequest = httplib.HTTPConnection(globalVars.config.get("BosMon", "bosmon_server"), globalVars.config.get("BosMon", "bosmon_port"), timeout=5)
|
||||
# debug-level to shell (0=no debug|1)
|
||||
httprequest.set_debuglevel(0)
|
||||
except:
|
||||
|
|
|
|||
|
|
@ -71,18 +71,18 @@ def run(typ,freq,data):
|
|||
#
|
||||
logging.debug("send FFAgent %s", typ)
|
||||
|
||||
if globals.config.get("FFAgent", "live") == "1":
|
||||
if globalVars.config.get("FFAgent", "live") == "1":
|
||||
url = "https://api.service.ff-agent.com/v1/WebService/triggerAlarm"
|
||||
else:
|
||||
url = "https://free.api.service.ff-agent.com/v1/WebService/triggerAlarm"
|
||||
|
||||
serverCertFile = globals.config.get("FFAgent", "serverCertFile")
|
||||
clientCertFile = globals.config.get("FFAgent", "clientCertFile")
|
||||
clientCertPass = globals.config.get("FFAgent", "clientCertPass")
|
||||
webApiToken = globals.config.get("FFAgent", "webApiToken")
|
||||
webApiKey = globals.config.get("FFAgent", "webApiKey")
|
||||
accessToken = globals.config.get("FFAgent", "accessToken")
|
||||
selectiveCallCode = globals.config.get("FFAgent", "selectiveCallCode")
|
||||
serverCertFile = globalVars.config.get("FFAgent", "serverCertFile")
|
||||
clientCertFile = globalVars.config.get("FFAgent", "clientCertFile")
|
||||
clientCertPass = globalVars.config.get("FFAgent", "clientCertPass")
|
||||
webApiToken = globalVars.config.get("FFAgent", "webApiToken")
|
||||
webApiKey = globalVars.config.get("FFAgent", "webApiKey")
|
||||
accessToken = globalVars.config.get("FFAgent", "accessToken")
|
||||
selectiveCallCode = globalVars.config.get("FFAgent", "selectiveCallCode")
|
||||
|
||||
# data["description"]
|
||||
msg_split = data["msg"].split(';')
|
||||
|
|
@ -105,7 +105,7 @@ def run(typ,freq,data):
|
|||
"alarmMessage" : ""
|
||||
}
|
||||
|
||||
if globals.config.get("FFAgent", "test") == "1":
|
||||
if globalVars.config.get("FFAgent", "test") == "1":
|
||||
alarmData = {
|
||||
"alarmDate" : "",
|
||||
"keyword" : "Test",
|
||||
|
|
@ -135,7 +135,7 @@ def run(typ,freq,data):
|
|||
"hmac": hmac.new(webApiKey, webApiToken + selectiveCallCode + accessToken + alarmData, digestmod=hashlib.sha256).hexdigest()
|
||||
}
|
||||
|
||||
if globals.config.get("FFAgent", "live") == "1":
|
||||
if globalVars.config.get("FFAgent", "live") == "1":
|
||||
r = requests.post(url, data=alarmData, headers=headers, verify=serverCertFile, cert=(clientCertFile, clientCertPass))
|
||||
else:
|
||||
r = requests.post(url, data=alarmData, headers=alarmHeaders, verify=serverCertFile)
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ def isSignal(poc_id):
|
|||
@exception: none
|
||||
"""
|
||||
# If RIC is Signal return True, else False
|
||||
if globals.config.get("MySQL", "signal_ric"):
|
||||
if poc_id in globals.config.get("MySQL", "signal_ric"):
|
||||
if globalVars.config.get("MySQL", "signal_ric"):
|
||||
if poc_id in globalVars.config.get("MySQL", "signal_ric"):
|
||||
logging.info("RIC %s is signal", poc_id)
|
||||
return True
|
||||
else:
|
||||
|
|
@ -91,7 +91,7 @@ def run(typ,freq,data):
|
|||
# Connect to MySQL
|
||||
#
|
||||
logging.debug("connect to MySQL")
|
||||
connection = mysql.connector.connect(host = globals.config.get("MySQL","dbserver"), user = globals.config.get("MySQL","dbuser"), passwd = globals.config.get("MySQL","dbpassword"), db = globals.config.get("MySQL","database"), charset='utf8')
|
||||
connection = mysql.connector.connect(host = globalVars.config.get("MySQL","dbserver"), user = globalVars.config.get("MySQL","dbuser"), passwd = globalVars.config.get("MySQL","dbpassword"), db = globalVars.config.get("MySQL","database"), charset='utf8')
|
||||
cursor = connection.cursor()
|
||||
except:
|
||||
logging.error("cannot connect to MySQL")
|
||||
|
|
@ -104,18 +104,18 @@ def run(typ,freq,data):
|
|||
logging.debug("Insert %s", typ)
|
||||
|
||||
if typ == "FMS":
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableFMS")+" (time, fms, status, direction, directionText, tsi, description) VALUES (FROM_UNIXTIME(%s),%s,%s,%s,%s,%s,%s)", (data["timestamp"], data["fms"], data["status"], data["direction"], data["directionText"], data["tsi"], data["description"]))
|
||||
cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tableFMS")+" (time, fms, status, direction, directionText, tsi, description) VALUES (FROM_UNIXTIME(%s),%s,%s,%s,%s,%s,%s)", (data["timestamp"], data["fms"], data["status"], data["direction"], data["directionText"], data["tsi"], data["description"]))
|
||||
|
||||
elif typ == "ZVEI":
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableZVEI")+" (time, zvei, description) VALUES (FROM_UNIXTIME(%s),%s,%s)", (data["timestamp"], data["zvei"], data["description"]))
|
||||
cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tableZVEI")+" (time, zvei, description) VALUES (FROM_UNIXTIME(%s),%s,%s)", (data["timestamp"], data["zvei"], data["description"]))
|
||||
|
||||
elif typ == "POC":
|
||||
if isSignal(data["ric"]):
|
||||
cursor.execute("UPDATE "+globals.config.get("MySQL","tableSIG")+" SET time = NOW() WHERE ric = "+data["ric"])
|
||||
cursor.execute("UPDATE "+globalVars.config.get("MySQL","tableSIG")+" SET time = NOW() WHERE ric = "+data["ric"])
|
||||
if cursor.rowcount == 0:
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableSIG")+" (time,ric) VALUES (NOW(),"+data["ric"]+")")
|
||||
cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tableSIG")+" (time,ric) VALUES (NOW(),"+data["ric"]+")")
|
||||
else:
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tablePOC")+" (time, ric, function, functionChar, msg, bitrate, description) VALUES (FROM_UNIXTIME(%s),%s,%s,%s,%s,%s,%s)", (data["timestamp"], data["ric"], data["function"], data["functionChar"], data["msg"], data["bitrate"], data["description"]))
|
||||
cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tablePOC")+" (time, ric, function, functionChar, msg, bitrate, description) VALUES (FROM_UNIXTIME(%s),%s,%s,%s,%s,%s,%s)", (data["timestamp"], data["ric"], data["function"], data["functionChar"], data["msg"], data["bitrate"], data["description"]))
|
||||
|
||||
else:
|
||||
logging.warning("Invalid Typ: %s", typ)
|
||||
|
|
|
|||
|
|
@ -67,27 +67,27 @@ def run(typ,freq,data):
|
|||
logging.debug("send Pushover %s", typ)
|
||||
|
||||
if data["function"] == '1':
|
||||
priority = globals.config.get("Pushover", "SubA")
|
||||
priority = globalVars.config.get("Pushover", "SubA")
|
||||
elif data["function"] == '2':
|
||||
priority = globals.config.get("Pushover", "SubB")
|
||||
priority = globalVars.config.get("Pushover", "SubB")
|
||||
elif data["function"] == '3':
|
||||
priority = globals.config.get("Pushover", "SubC")
|
||||
priority = globalVars.config.get("Pushover", "SubC")
|
||||
elif data["function"] == '4':
|
||||
priority = globals.config.get("Pushover", "SubD")
|
||||
priority = globalVars.config.get("Pushover", "SubD")
|
||||
else:
|
||||
priority = 0
|
||||
|
||||
conn = httplib.HTTPSConnection("api.pushover.net:443")
|
||||
conn.request("POST", "/1/messages.json",
|
||||
urllib.urlencode({
|
||||
"token": globals.config.get("Pushover", "api_key"),
|
||||
"user": globals.config.get("Pushover", "user_key"),
|
||||
"token": globalVars.config.get("Pushover", "api_key"),
|
||||
"user": globalVars.config.get("Pushover", "user_key"),
|
||||
"message": "<b>"+data["description"]+"</b><br>"+data["msg"].replace(";", "<br>"),
|
||||
"html": globals.config.get("Pushover", "html"),
|
||||
"title": globals.config.get("Pushover", "title"),
|
||||
"html": globalVars.config.get("Pushover", "html"),
|
||||
"title": globalVars.config.get("Pushover", "title"),
|
||||
"priority": priority,
|
||||
"retry": globals.config.get("Pushover", "retry"),
|
||||
"expire": globals.config.get("Pushover", "expire")
|
||||
"retry": globalVars.config.get("Pushover", "retry"),
|
||||
"expire": globalVars.config.get("Pushover", "expire")
|
||||
}),{"Content-type": "application/x-www-form-urlencoded"})
|
||||
|
||||
except:
|
||||
|
|
|
|||
|
|
@ -64,20 +64,20 @@ test2 = 123456
|
|||
```
|
||||
|
||||
#### 3.2 Read data from config.ini
|
||||
To read yout configuration data you must import the `globals.py` where the global config-object is located:
|
||||
To read yout configuration data you must import the `globalVars.py` where the global config-object is located:
|
||||
```python
|
||||
from includes import globalVars # Global variables
|
||||
```
|
||||
|
||||
Now you can get your configuration data with:
|
||||
```python
|
||||
VALUE = globals.config.get("SECTION", "OPTION") #Gets any value
|
||||
VALUE = globalVars.config.get("SECTION", "OPTION") #Gets any value
|
||||
```
|
||||
or better, use this:
|
||||
```python
|
||||
VALUE = globals.config.getint("SECTION", "OPTION") #Value must be an Integer
|
||||
VALUE = globals.config.getfloat("SECTION", "OPTION") #Value must be an Float
|
||||
VALUE = globals.config.getboolean("SECTION", "OPTION") #Value must be an Boolean
|
||||
VALUE = globalVars.config.getint("SECTION", "OPTION") #Value must be an Integer
|
||||
VALUE = globalVars.config.getfloat("SECTION", "OPTION") #Value must be an Float
|
||||
VALUE = globalVars.config.getboolean("SECTION", "OPTION") #Value must be an Boolean
|
||||
```
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -89,18 +89,18 @@ def run(typ,freq,data):
|
|||
logging.debug("Plugin SMS enabled")
|
||||
|
||||
# get number of cases and build a RIC-Array
|
||||
i = globals.config.get("SMS","quantity")
|
||||
i = globalVars.config.get("SMS","quantity")
|
||||
aRic = []
|
||||
|
||||
# build the array
|
||||
for x in range (1, int(i) + 1):
|
||||
# check the number of subrics
|
||||
subric = globals.config.get("SMS","subric" + str(x))
|
||||
subric = globalVars.config.get("SMS","subric" + str(x))
|
||||
if len(subric) > 1: # we have more than one subric
|
||||
subric_list = subric.split(",")
|
||||
for y in range (0, len(subric_list)):
|
||||
sric = subric_list[y].replace(' ','')
|
||||
full_ric = globals.config.get("SMS","ric" + str(x)) + sric
|
||||
full_ric = globalVars.config.get("SMS","ric" + str(x)) + sric
|
||||
case = x
|
||||
tmp = []
|
||||
tmp.append(full_ric)
|
||||
|
|
@ -109,7 +109,7 @@ def run(typ,freq,data):
|
|||
else:
|
||||
#get ric AND subric at once with ONE subric
|
||||
tmp = []
|
||||
tmp.append(globals.config.get("SMS","ric" + str(x)) + subric)
|
||||
tmp.append(globalVars.config.get("SMS","ric" + str(x)) + subric)
|
||||
tmp.append(x)
|
||||
aRic.append(tmp) # 2D-Array...
|
||||
|
||||
|
|
@ -130,8 +130,8 @@ def run(typ,freq,data):
|
|||
case = aRic[index[0]][1]
|
||||
logging.debug("Enabling case %s", case)
|
||||
|
||||
text = globals.config.get("SMS","text" + str(case))
|
||||
number = globals.config.get("SMS","phonenumber" + str(case))
|
||||
text = globalVars.config.get("SMS","text" + str(case))
|
||||
number = globalVars.config.get("SMS","phonenumber" + str(case))
|
||||
|
||||
#just for debug
|
||||
logging.debug("Aktivierter Text: %s", text)
|
||||
|
|
|
|||
|
|
@ -70,11 +70,11 @@ def run(typ,freq,data):
|
|||
conn = httplib.HTTPSConnection("gateway.sms77.de:443")
|
||||
conn.request("POST", "",
|
||||
urllib.urlencode({
|
||||
"u": globals.config.get("Sms77", "user"),
|
||||
"p": globals.config.get("Sms77", "password"),
|
||||
"to": globals.config.get("Sms77", "to"),
|
||||
"from": globals.config.get("Sms77", "from"),
|
||||
"type": globals.config.get("Sms77", "type"),
|
||||
"u": globalVars.config.get("Sms77", "user"),
|
||||
"p": globalVars.config.get("Sms77", "password"),
|
||||
"to": globalVars.config.get("Sms77", "to"),
|
||||
"from": globalVars.config.get("Sms77", "from"),
|
||||
"type": globalVars.config.get("Sms77", "type"),
|
||||
"text": data["description"]+"<br>"+data["msg"].replace(";", "<br>")
|
||||
}),{"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
|
||||
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@ def onLoad():
|
|||
global GoogleAPIKey
|
||||
|
||||
configHandler.checkConfig("Telegram")
|
||||
BOTTokenAPIKey = globals.config.get("Telegram","BOTTokenAPIKey")
|
||||
BOTChatIDAPIKey = globals.config.get("Telegram","BOTChatIDAPIKey")
|
||||
RICforLocationAPIKey = globals.config.get("Telegram","RICforLocationAPIKey")
|
||||
GoogleAPIKey = globals.config.get("Telegram","GoogleAPIKey")
|
||||
BOTTokenAPIKey = globalVars.config.get("Telegram","BOTTokenAPIKey")
|
||||
BOTChatIDAPIKey = globalVars.config.get("Telegram","BOTChatIDAPIKey")
|
||||
RICforLocationAPIKey = globalVars.config.get("Telegram","RICforLocationAPIKey")
|
||||
GoogleAPIKey = globalVars.config.get("Telegram","GoogleAPIKey")
|
||||
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -59,13 +59,13 @@ def doSendmail(server, subject, mailtext):
|
|||
"""
|
||||
try:
|
||||
msg = MIMEText(mailtext, 'plain', 'UTF-8')
|
||||
msg['From'] = globals.config.get("eMail", "from")
|
||||
msg['To'] = globals.config.get("eMail", "to")
|
||||
msg['From'] = globalVars.config.get("eMail", "from")
|
||||
msg['To'] = globalVars.config.get("eMail", "to")
|
||||
msg['Subject'] = subject
|
||||
msg['Date'] = formatdate()
|
||||
msg['Message-Id'] = make_msgid()
|
||||
msg['Priority'] = globals.config.get("eMail", "priority")
|
||||
server.sendmail(globals.config.get("eMail", "from"), globals.config.get("eMail", "to").split(), msg.as_string())
|
||||
msg['Priority'] = globalVars.config.get("eMail", "priority")
|
||||
server.sendmail(globalVars.config.get("eMail", "from"), globalVars.config.get("eMail", "to").split(), msg.as_string())
|
||||
except:
|
||||
logging.error("send eMail failed")
|
||||
logging.debug("send eMail failed", exc_info=True)
|
||||
|
|
@ -103,17 +103,17 @@ def run(typ,freq,data):
|
|||
#
|
||||
# connect to SMTP-Server
|
||||
#
|
||||
server = smtplib.SMTP(globals.config.get("eMail", "smtp_server"), globals.config.get("eMail", "smtp_port"))
|
||||
server = smtplib.SMTP(globalVars.config.get("eMail", "smtp_server"), globalVars.config.get("eMail", "smtp_port"))
|
||||
# debug-level to shell (0=no debug|1)
|
||||
server.set_debuglevel(0)
|
||||
|
||||
# if tls is enabled, starttls
|
||||
if globals.config.get("eMail", "tls"):
|
||||
if globalVars.config.get("eMail", "tls"):
|
||||
server.starttls()
|
||||
|
||||
# if user is given, login
|
||||
if globals.config.get("eMail", "user"):
|
||||
server.login(globals.config.get("eMail", "user"), globals.config.get("eMail", "password"))
|
||||
if globalVars.config.get("eMail", "user"):
|
||||
server.login(globalVars.config.get("eMail", "user"), globalVars.config.get("eMail", "password"))
|
||||
|
||||
except:
|
||||
logging.error("cannot connect to eMail")
|
||||
|
|
@ -127,12 +127,12 @@ def run(typ,freq,data):
|
|||
logging.debug("Start FMS to eMail")
|
||||
try:
|
||||
# read subject-structure from config.ini
|
||||
subject = globals.config.get("eMail", "fms_subject")
|
||||
subject = globalVars.config.get("eMail", "fms_subject")
|
||||
# replace wildcards with helper function
|
||||
subject = wildcardHandler.replaceWildcards(subject, data)
|
||||
|
||||
# read mailtext-structure from config.ini
|
||||
mailtext = globals.config.get("eMail", "fms_message")
|
||||
mailtext = globalVars.config.get("eMail", "fms_message")
|
||||
# replace wildcards with helper function
|
||||
mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True)
|
||||
|
||||
|
|
@ -147,12 +147,12 @@ def run(typ,freq,data):
|
|||
logging.debug("Start ZVEI to eMail")
|
||||
try:
|
||||
# read subject-structure from config.ini
|
||||
subject = globals.config.get("eMail", "zvei_subject")
|
||||
subject = globalVars.config.get("eMail", "zvei_subject")
|
||||
# replace wildcards with helper function
|
||||
subject = wildcardHandler.replaceWildcards(subject, data)
|
||||
|
||||
# read mailtext-structure from config.ini
|
||||
mailtext = globals.config.get("eMail", "zvei_message")
|
||||
mailtext = globalVars.config.get("eMail", "zvei_message")
|
||||
# replace wildcards with helper function
|
||||
mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True)
|
||||
|
||||
|
|
@ -167,12 +167,12 @@ def run(typ,freq,data):
|
|||
logging.debug("Start POC to eMail")
|
||||
try:
|
||||
# read subject-structure from config.ini
|
||||
subject = globals.config.get("eMail", "poc_subject")
|
||||
subject = globalVars.config.get("eMail", "poc_subject")
|
||||
# replace wildcards with helper function
|
||||
subject = wildcardHandler.replaceWildcards(subject, data)
|
||||
|
||||
# read mailtext-structure from config.ini
|
||||
mailtext = globals.config.get("eMail", "poc_message")
|
||||
mailtext = globalVars.config.get("eMail", "poc_message")
|
||||
# replace wildcards with helper function
|
||||
mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ def run(typ,freq,data):
|
|||
# connect to firEmergency
|
||||
#
|
||||
firSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
firSocket.connect((globals.config.get("firEmergency", "firserver"), globals.config.getint("firEmergency", "firport")))
|
||||
firSocket.connect((globalVars.config.get("firEmergency", "firserver"), globalVars.config.getint("firEmergency", "firport")))
|
||||
except:
|
||||
logging.error("cannot connect to firEmergency")
|
||||
logging.debug("cannot connect to firEmergency", exc_info=True)
|
||||
|
|
|
|||
|
|
@ -66,13 +66,13 @@ def run(typ,freq,data):
|
|||
# Create URL
|
||||
#
|
||||
if typ == "FMS":
|
||||
url = globals.config.get("httpRequest", "fms_url") #Get URL
|
||||
url = globalVars.config.get("httpRequest", "fms_url") #Get URL
|
||||
url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function
|
||||
elif typ == "ZVEI":
|
||||
url = globals.config.get("httpRequest", "zvei_url") #Get URL
|
||||
url = globalVars.config.get("httpRequest", "zvei_url") #Get URL
|
||||
url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function
|
||||
elif typ == "POC":
|
||||
url = globals.config.get("httpRequest", "poc_url") #Get URL
|
||||
url = globalVars.config.get("httpRequest", "poc_url") #Get URL
|
||||
url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function
|
||||
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -68,15 +68,15 @@ def run(typ,freq,data):
|
|||
#
|
||||
# SOCK_DGRAM is the socket type to use for UDP sockets
|
||||
# SOCK_STREAM is the socket type to use for TCP sockets
|
||||
if globals.config.get("jsonSocket", "protocol") == "TCP":
|
||||
if globalVars.config.get("jsonSocket", "protocol") == "TCP":
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.connect((globals.config.get("jsonSocket", "server"), globals.config.getint("jsonSocket", "port")))
|
||||
sock.connect((globalVars.config.get("jsonSocket", "server"), globalVars.config.getint("jsonSocket", "port")))
|
||||
else:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
except:
|
||||
logging.error("cannot initialize %s-socket", globals.config.get("jsonSocket", "protocol"))
|
||||
logging.debug("cannot initialize %s-socket", globals.config.get("jsonSocket", "protocol"), exc_info=True)
|
||||
logging.error("cannot initialize %s-socket", globalVars.config.get("jsonSocket", "protocol"))
|
||||
logging.debug("cannot initialize %s-socket", globalVars.config.get("jsonSocket", "protocol"), exc_info=True)
|
||||
# Without connection, plugin couldn't work
|
||||
return
|
||||
|
||||
|
|
@ -84,22 +84,22 @@ def run(typ,freq,data):
|
|||
# toDo is equals for all types, so only check if typ is supported
|
||||
supportedTypes = ["FMS", "ZVEI", "POC"]
|
||||
if typ in supportedTypes:
|
||||
logging.debug("Start %s to %s", typ, globals.config.get("jsonSocket", "protocol"))
|
||||
logging.debug("Start %s to %s", typ, globalVars.config.get("jsonSocket", "protocol"))
|
||||
try:
|
||||
# dump data to json-string
|
||||
sendData = json.dumps(data)
|
||||
# send data
|
||||
sock.sendto(sendData, (globals.config.get("jsonSocket", "server"), globals.config.getint("jsonSocket", "port")))
|
||||
sock.sendto(sendData, (globalVars.config.get("jsonSocket", "server"), globalVars.config.getint("jsonSocket", "port")))
|
||||
except:
|
||||
logging.error("%s to %s failed", typ, globals.config.get("jsonSocket", "protocol"))
|
||||
logging.debug("%s to %s failed", typ, globals.config.get("jsonSocket", "protocol"), exc_info=True)
|
||||
logging.error("%s to %s failed", typ, globalVars.config.get("jsonSocket", "protocol"))
|
||||
logging.debug("%s to %s failed", typ, globalVars.config.get("jsonSocket", "protocol"), exc_info=True)
|
||||
return
|
||||
|
||||
else:
|
||||
logging.warning("Invalid Typ: %s", typ)
|
||||
|
||||
finally:
|
||||
logging.debug("close %s-Connection", globals.config.get("jsonSocket", "protocol"))
|
||||
logging.debug("close %s-Connection", globalVars.config.get("jsonSocket", "protocol"))
|
||||
try:
|
||||
sock.close()
|
||||
except:
|
||||
|
|
|
|||
|
|
@ -93,17 +93,17 @@ def onLoad():
|
|||
|
||||
# load config:
|
||||
configHandler.checkConfig("notifyMyAndroid")
|
||||
application = stringConverter.convertToUnicode(globals.config.get("notifyMyAndroid","appName"))
|
||||
usecsv = globals.config.getboolean("notifyMyAndroid","usecsv")
|
||||
application = stringConverter.convertToUnicode(globalVars.config.get("notifyMyAndroid","appName"))
|
||||
usecsv = globalVars.config.getboolean("notifyMyAndroid","usecsv")
|
||||
|
||||
# if no csv should use, we take the APIKey directly
|
||||
if usecsv == False:
|
||||
APIKey = globals.config.get("notifyMyAndroid","APIKey")
|
||||
APIKey = globalVars.config.get("notifyMyAndroid","APIKey")
|
||||
else:
|
||||
# import the csv-file
|
||||
try:
|
||||
logging.debug("-- loading nma.csv")
|
||||
with open(globals.script_path+'/csv/nma.csv') as csvfile:
|
||||
with open(globalVars.script_path+'/csv/nma.csv') as csvfile:
|
||||
# DictReader expected structure described in first line of csv-file
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
|
|
@ -216,7 +216,7 @@ def run(typ,freq,data):
|
|||
|
||||
# if not using csv-import, all is simple...
|
||||
if usecsv == False:
|
||||
response = nma.pushWithAPIKey(APIKey, application, event, msg, priority=globals.config.getint("notifyMyAndroid","priority"))
|
||||
response = nma.pushWithAPIKey(APIKey, application, event, msg, priority=globalVars.config.getint("notifyMyAndroid","priority"))
|
||||
checkResponse(response, APIKey)
|
||||
else:
|
||||
if "FMS" in typ:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue