Merge pull request #372 from Schrolli91/v2.4

V2.4
This commit is contained in:
Bastian Schroll 2018-08-16 20:25:38 +02:00 committed by GitHub
commit 56f62c33e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 195 additions and 116 deletions

2
.gitignore vendored
View file

@ -9,3 +9,5 @@ log/
\.pydevproject
\.settings/
\.idea/

View file

@ -1,7 +1,20 @@
# Changelog
### __[v2.4]__ - 17.08.2018
##### Added
- Config Eintrag um Port für MySQL Plugin festzulegen [#345](https://github.com/Schrolli91/BOSWatch/pull/345)
- FMS und ZVEI Support für Pushover Plugin [#352](https://github.com/Schrolli91/BOSWatch/pull/352)
- Benutzerdefinierte Nachrichten für Pushover Plugin in config [#352](https://github.com/Schrolli91/BOSWatch/pull/352)
##### Changed
- multicastAlarm Plugin - RICs die von multicastAlarm genutzt werden, müssen nicht mehr in der config bei allow_ric bzw. filter_range_start/filter_range_end berücksichtigt werden. [#357](https://github.com/Schrolli91/BOSWatch/pull/357)
- FFAgent Plugin - Debug Logging für die alarmHeaders eingebaut zwecks Troubleshooting [#354](https://github.com/Schrolli91/BOSWatch/pull/354)
- multicastAlarm Plugin - Buffer nach jedem Alarm löschen - erlaubt in kombination mit "doubleFilter_check_msg" die Verwendung in Netzen, die zwischen multicastAlarm RICs auch normale Alarme senden. #370(https://github.com/Schrolli91/BOSWatch/pull/370)
##### Fixed
- Fehler beim Auslesen der netIdent_RIC im MySQL Plugin [#347](https://github.com/Schrolli91/BOSWatch/pull/347)
- FFAgent Plugin - Typo bei alarmHeaders für Live Betrieb gefixt [#354](https://github.com/Schrolli91/BOSWatch/pull/354)
### __[2.3]__ - 22.12.2017
### __[v2.3]__ - 22.12.2017
##### Added
- zuschaltbare POCSAG Multicast-Alarm Funktionalität [#307](https://github.com/Schrolli91/BOSWatch/pull/307)
- Flag in Config um nur letzte Net Ident oder gesamte Historie zu speichern [#317](https://github.com/Schrolli91/BOSWatch/pull/317)
@ -48,7 +61,7 @@
Zum schreiben des Changelog's siehe:
http://keepachangelog.com/de/1.0.0/
### __[version]__ - date
### __[v#.#]__ - date
##### Added
##### Changed
##### Deprecated

View file

@ -174,8 +174,10 @@ template = 0
[MySQL]
# MySQL configuration
#default port: 3306
dbserver = localhost
dbuser = root
dbport = 3306
dbuser = boswatch
dbpassword = root
database = boswatch

View file

@ -174,7 +174,9 @@ template = 0
[MySQL]
# MySQL configuration
#default port: 3306
dbserver = localhost
dbport = 3306
dbuser = boswatch
dbpassword = root
database = boswatch

View file

@ -144,7 +144,7 @@ multicastAlarm = 0
# time limit for alarms that do not belong to the multicastAlarm sequence in seconds
multicastAlarm_ignore_time = 15
# multicastAlarm delimiter RIC (usually used as a starting point for a alarm sequence) (can be empty)
# multicastAlarm delimiter RIC (usually used as a starting point for a alarm sequence). Needs to be empty if multicastAlarms are interrupted by normal alarms.
multicastAlarm_delimiter_ric =
# multicastAlarm RIC that is used to send the text message
@ -191,7 +191,9 @@ template = 0
[MySQL]
# MySQL configuration
#default port: 3306
dbserver = localhost
dbport = 3306
dbuser = boswatch
dbpassword = root
database = boswatch
@ -375,14 +377,24 @@ api_key =
# Pushover Userkey or Groupkey to receive message
user_key =
# Title of the message
title = BOSWatch Message
# Section for POCSAG
# Adapt Pocsag Subric (a,b,c,d) to Pushover Priorities (see https://pushover.net/api#priority)
SubA = 0
SubB = 2
SubC = 1
SubD = 0
SubA = 1
SubB = 1
SubC = 2
SubD = -2
poc_title = Alarm: %RIC%%LPAR%%FUNCCHAR%%RPAR%
poc_message = %DATE% %TIME% - %DESCR%: %MSG%
# Section for ZVEI
zvei_prio = 1
zvei_title = Alarm: %ZVEI%
zvei_message = %DATE% %TIME%: %ZVEI%
# Section for FMS
fms_prio = 1
fms_title = FMS: %FMS%
fms_message = %DATE% %TIME%: %FMS%%BR%Status: %STATUS% - Direction: %DIRT% - TSI: %TSI% %LPAR%%DESCR%%RPAR%
# how often should Pushover re-alert in seconds (emergency-messages)
retry = 30
@ -474,6 +486,7 @@ test2 = 123456
# %RIC% = POCSAG RIC
# %FUNC% = POCSAG function/Subric (1-4)
# %FUNCCHAR% = POCSAG function/Subric als character (a-d)
# %FUNCTEXT% = POCSAG static Subric message (see [POC])
# %MSG% = Message of the POCSAG telegram
# %BITRATE% = Bitrate of the POCSAG telegram
# %DESCR% = Description, if description-module is used

View file

@ -23,16 +23,16 @@ Simple Database Class (C) by Bastian Schroll
function __construct($host, $user, $password, $database, $show_error = 1)
{
$this->show_error = $show_error;
@$this->conn = mysql_connect($host, $user, $password);
@$this->conn = mysqli_connect($host, $user, $password);
if ($this->conn == false)
{
$this->error("Keine Verbindung zum Datenbank Server!", mysql_error());
$this->error("Keine Verbindung zum Datenbank Server!", mysqli_error($this->conn));
return false;
}
if (!@mysql_select_db($database, $this->conn))
if (!@mysqli_select_db($this->conn, $database))
{
$this->error("Datenbank nicht gefunden!", mysql_error());
$this->error("Datenbank nicht gefunden!", mysqli_error($this->conn));
return false;
}
return true;
@ -41,17 +41,17 @@ Simple Database Class (C) by Bastian Schroll
/**
* Database::query()
*
* F<EFBFBD>hrt einen MySQL Query aus
* Fuehrt einen MySQL Query aus
*
* @param mixed $query Auszuf<EFBFBD>hrender Query
* @param mixed $query Auszufuehrender Query
* @return Result-Handler/FALSE
*/
function query($query)
{
$this->result = @mysql_query($query, $this->conn);
$this->result = @mysqli_query($this->conn, $query);
if ($this->result == false)
{
$this->error("Fehlerhafte Datenbank Anfrage!", mysql_error());
$this->error("Fehlerhafte Datenbank Anfrage!", mysqli_error($this->conn));
return false;
}
return $this->result;
@ -60,51 +60,51 @@ Simple Database Class (C) by Bastian Schroll
/**
* Database::fetchAssoc()
*
* Liefert alle gefundnen Datens<EFBFBD>tze als Assoc
* Liefert alle gefundnen Datensaetze als Assoc
*
* @param mixed $result Externer Result-Handler
* @return gefundene Datens<EFBFBD>tze als Assoc
* @return gefundene Datensaetze als Assoc
*/
function fetchAssoc($result = null)
{
if ($result != null)
{
return @mysql_fetch_assoc($result);
return @mysqli_fetch_assoc($result);
} else
{
return @mysql_fetch_assoc($this->result);
return @mysqli_fetch_assoc($this->result);
}
}
/**
* Database::count()
*
* Z<EFBFBD>hlt alle gefundenen Datens<EFBFBD>tze
* Zaehlt alle gefundenen Datensaetze
*
* @param mixed $result Externer Result-Handler
* @return Anzahl gefundener Datens<EFBFBD>tze
* @return Anzahl gefundener Datensaetze
*/
function count($result = null)
{
if ($result != null)
{
return @mysql_num_rows($result);
return @mysqli_num_rows($result);
} else
{
return @mysql_num_rows($this->result);
return @mysqli_num_rows($this->result);
}
}
/**
* Database::closeConnection()
*
* Schlie<EFBFBD>t die bestehende MySQL Verbindung
* Schliesst die bestehende MySQL Verbindung
*
* @return TRUE/FALSE
*/
function closeConnection()
{
if (!@mysql_close($this->conn))
if (!@mysqli_close($this->conn))
{
$this->error("Verbindung zur Datenbank konnte nicht getrennt werden!", mysql_error());
return false;

View file

@ -62,11 +62,23 @@ def isAllowed(poc_id):
return True
else:
allowed = 0
# 5.) Implementation for multicastAlarm
if globalVars.config.get("multicastAlarm", "multicastAlarm_delimiter_ric"):
if poc_id in globalVars.config.get("multicastAlarm", "multicastAlarm_delimiter_ric"):
logging.info("RIC %s as multicastAlarm delimiter", poc_id)
return True
else:
allowed = 0
if globalVars.config.get("multicastAlarm", "multicastAlarm_ric"):
if poc_id in globalVars.config.get("multicastAlarm", "multicastAlarm_ric"):
logging.info("RIC %s as multicastAlarm message", poc_id)
return True
else:
allowed = 0
if allowed == 0:
return False
return True
##
#
# POCSAG decoder function

View file

@ -9,9 +9,9 @@ Global variables
"""
# version info
versionNr = "2.3"
versionNr = "2.4"
branch = "master"
buildDate = "22/12/2017"
buildDate = "17.08.2018"
# Global variables

View file

@ -29,7 +29,7 @@ def newEntrymultiList(data):
timestamp = int(time.time())
# multicastAlarm processing if enabled and delimiter RIC has been received
if data['ric'] == globalVars.config.get("multicastAlarm", "multicastAlarm_delimiter_ric"):
multiList = []
del multiList[:]
logging.debug("delimiter RIC received - buffer cleared")
else:
multiList.append([data, timestamp])
@ -61,3 +61,5 @@ def multicastAlarmExec(freq, data):
except:
logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True)
del multiList[:]
logging.debug("multicastAlarm finished - buffer cleared")

View file

@ -132,9 +132,10 @@ def run(typ,freq,data):
"selectiveCallCode": selectiveCallCode,
"hmac": hmac.new(webApiKey, webApiToken + selectiveCallCode + accessToken + alarmData, digestmod=hashlib.sha256).hexdigest()
}
logging.debug(alarmHeaders)
if globalVars.config.get("FFAgent", "live") == "1":
r = requests.post(url, data=alarmData, headers=headers, verify=serverCertFile, cert=(clientCertFile, clientCertPass))
r = requests.post(url, data=alarmData, headers=alarmHeaders, verify=serverCertFile, cert=(clientCertFile, clientCertPass))
else:
r = requests.post(url, data=alarmData, headers=alarmHeaders, verify=serverCertFile)

View file

@ -91,7 +91,7 @@ def run(typ,freq,data):
# Connect to MySQL
#
logging.debug("connect to MySQL")
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')
connection = mysql.connector.connect(host = globalVars.config.get("MySQL","dbserver"), port = globalVars.config.get("MySQL","dbport"), 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")
@ -111,7 +111,7 @@ def run(typ,freq,data):
elif typ == "POC":
if isSignal(data["ric"]):
if globalVars.config.getint("POC","netIdent_histry"):
if globalVars.config.getint("POC","netIdent_history"):
cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tableSIG")+" (time,ric) VALUES (NOW(), '"+data["ric"]+"');")
else:
cursor.execute("UPDATE "+globalVars.config.get("MySQL","tableSIG")+" SET time = NOW() WHERE ric = '"+data["ric"]+"';")

View file

@ -16,6 +16,8 @@ from includes import globalVars # Global variables
# from includes.helper import timeHandler
from includes.helper import configHandler
from includes.helper import wildcardHandler
##
#
@ -59,11 +61,31 @@ def run(typ,freq,data):
try:
if configHandler.checkConfig("Pushover"): # read and debug the config
try:
if typ == "FMS":
#
# building message for FMS
#
message = globalVars.config.get("Pushover", "fms_message")
title = globalVars.config.get("Pushover", "fms_title")
priority = globalVars.config.get("Pushover", "fms_prio")
logging.debug("Sending message: %s", message)
elif typ == "ZVEI":
#
# building message for ZVEI
#
message = globalVars.config.get("Pushover", "zvei_message")
title = globalVars.config.get("Pushover", "zvei_title")
priority = globalVars.config.get("Pushover", "zvei_prio")
logging.debug("Sending message: %s", message)
elif typ == "POC":
#
# Pushover-Request
#
logging.debug("send Pushover %s", typ)
logging.debug("send Pushover for %s", typ)
if data["function"] == '1':
priority = globalVars.config.get("Pushover", "SubA")
@ -75,15 +97,26 @@ def run(typ,freq,data):
priority = globalVars.config.get("Pushover", "SubD")
else:
priority = 0
message = globalVars.config.get("Pushover", "poc_message")
title = globalVars.config.get("Pushover", "poc_title")
else:
logging.warning("Invalid type: %s", typ)
try:
# replace the wildcards
message = wildcardHandler.replaceWildcards(message, data)
title = wildcardHandler.replaceWildcards(title, data)
# start the connection
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.urlencode({
"token": globalVars.config.get("Pushover", "api_key"),
"user": globalVars.config.get("Pushover", "user_key"),
"message": "<b>"+data["description"]+"</b><br>"+data["msg"].replace(";", "<br>"),
"message": message,
"html": globalVars.config.get("Pushover", "html"),
"title": globalVars.config.get("Pushover", "title"),
"title": title,
"priority": priority,
"retry": globalVars.config.get("Pushover", "retry"),
"expire": globalVars.config.get("Pushover", "expire")
@ -94,7 +127,6 @@ def run(typ,freq,data):
logging.debug("cannot send Pushover request", exc_info=True)
return
else:
try:
#
# check Pushover-Response