mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-06 17:15:38 -08:00
Remove EVENT_LEVEL and add INCLUDED_SECTIONS
This commit is contained in:
@@ -54,6 +54,13 @@ def main ():
|
|||||||
global log_timestamp
|
global log_timestamp
|
||||||
global sql_connection
|
global sql_connection
|
||||||
global sql
|
global sql
|
||||||
|
global includedSections
|
||||||
|
|
||||||
|
# Which sections to include. Include everything by default
|
||||||
|
try:
|
||||||
|
includedSections = INCLUDED_SECTIONS
|
||||||
|
except NameError:
|
||||||
|
includedSections = ['internet', 'new_devices', 'down_devices', 'events']
|
||||||
|
|
||||||
# Empty stdout and stderr .log files for debugging if needed
|
# Empty stdout and stderr .log files for debugging if needed
|
||||||
write_file (LOG_PATH + '/stderr.log', '')
|
write_file (LOG_PATH + '/stderr.log', '')
|
||||||
@@ -1302,7 +1309,7 @@ def email_reporting ():
|
|||||||
|
|
||||||
|
|
||||||
for eventAlert in sql :
|
for eventAlert in sql :
|
||||||
mail_section_Internet = True
|
mail_section_Internet = 'internet' in includedSections
|
||||||
# collect "internet" (IP changes) for the webhook json
|
# collect "internet" (IP changes) for the webhook json
|
||||||
json_internet = add_json_list (eventAlert, json_internet)
|
json_internet = add_json_list (eventAlert, json_internet)
|
||||||
|
|
||||||
@@ -1334,7 +1341,7 @@ def email_reporting ():
|
|||||||
ORDER BY eve_DateTime""")
|
ORDER BY eve_DateTime""")
|
||||||
|
|
||||||
for eventAlert in sql :
|
for eventAlert in sql :
|
||||||
mail_section_new_devices = True
|
mail_section_new_devices = 'new_devices' in includedSections
|
||||||
# collect "new_devices" for the webhook json
|
# collect "new_devices" for the webhook json
|
||||||
json_new_devices = add_json_list (eventAlert, json_new_devices)
|
json_new_devices = add_json_list (eventAlert, json_new_devices)
|
||||||
|
|
||||||
@@ -1365,7 +1372,7 @@ def email_reporting ():
|
|||||||
ORDER BY eve_DateTime""")
|
ORDER BY eve_DateTime""")
|
||||||
|
|
||||||
for eventAlert in sql :
|
for eventAlert in sql :
|
||||||
mail_section_devices_down = True
|
mail_section_devices_down = 'down_devices' in includedSections
|
||||||
# collect "down_devices" for the webhook json
|
# collect "down_devices" for the webhook json
|
||||||
json_down_devices = add_json_list (eventAlert, json_down_devices)
|
json_down_devices = add_json_list (eventAlert, json_down_devices)
|
||||||
|
|
||||||
@@ -1398,7 +1405,7 @@ def email_reporting ():
|
|||||||
ORDER BY eve_DateTime""")
|
ORDER BY eve_DateTime""")
|
||||||
|
|
||||||
for eventAlert in sql :
|
for eventAlert in sql :
|
||||||
mail_section_events = True
|
mail_section_events = 'events' in includedSections
|
||||||
# collect "events" for the webhook json
|
# collect "events" for the webhook json
|
||||||
json_events = add_json_list (eventAlert, json_events)
|
json_events = add_json_list (eventAlert, json_events)
|
||||||
|
|
||||||
@@ -1614,19 +1621,13 @@ def send_webhook (_json, _html):
|
|||||||
except NameError: # variable not defined, use a default
|
except NameError: # variable not defined, use a default
|
||||||
webhookRequestMethod = 'GET'
|
webhookRequestMethod = 'GET'
|
||||||
|
|
||||||
# Event level reporting (int, 0=none, 1=internet only, 2=new devices & 1, 3=down devices & 2, 4= events & 3 i.e. everything)
|
|
||||||
try:
|
|
||||||
eventLevel = EVENT_LEVEL
|
|
||||||
except NameError: # variable not defined, use a default
|
|
||||||
eventLevel = 4 # report on everything
|
|
||||||
|
|
||||||
# use data type based on specified payload type
|
# use data type based on specified payload type
|
||||||
if webhookPayload == 'json':
|
if webhookPayload == 'json':
|
||||||
payloadData = _json
|
payloadData = _json
|
||||||
if webhookPayload == 'html':
|
if webhookPayload == 'html':
|
||||||
payloadData = _html
|
payloadData = _html
|
||||||
if webhookPayload == 'text':
|
if webhookPayload == 'text':
|
||||||
payloadData = to_text(_json, eventLevel)
|
payloadData = to_text(_json)
|
||||||
|
|
||||||
#Define slack-compatible payload
|
#Define slack-compatible payload
|
||||||
_json_payload = { "text": payloadData } if webhookPayload == 'text' else {
|
_json_payload = { "text": payloadData } if webhookPayload == 'text' else {
|
||||||
@@ -1826,21 +1827,21 @@ def logResult (stdout, stderr):
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
def to_text(_json, eventLevel):
|
def to_text(_json):
|
||||||
payloadData = ""
|
payloadData = ""
|
||||||
if len(_json['internet']) > 0 and eventLevel > 0:
|
if len(_json['internet']) > 0 and 'internet' in includedSections:
|
||||||
payloadData += "INTERNET\n"
|
payloadData += "INTERNET\n"
|
||||||
for event in _json['internet']:
|
for event in _json['internet']:
|
||||||
payloadData += event[3] + ' on ' + event[2] + '. ' + event[4] + '. New address:' + event[1] + '\n'
|
payloadData += event[3] + ' on ' + event[2] + '. ' + event[4] + '. New address:' + event[1] + '\n'
|
||||||
|
|
||||||
if len(_json['new_devices']) > 0 and eventLevel > 1:
|
if len(_json['new_devices']) > 0 and 'new_devices' in includedSections:
|
||||||
payloadData += "NEW DEVICES:\n"
|
payloadData += "NEW DEVICES:\n"
|
||||||
for event in _json['new_devices']:
|
for event in _json['new_devices']:
|
||||||
if event[4] is None:
|
if event[4] is None:
|
||||||
event[4] = event[11]
|
event[4] = event[11]
|
||||||
payloadData += event[1] + ' - ' + event[4] + '\n'
|
payloadData += event[1] + ' - ' + event[4] + '\n'
|
||||||
|
|
||||||
if len(_json['down_devices']) > 0 and eventLevel > 2:
|
if len(_json['down_devices']) > 0 and 'down_devices' in includedSections:
|
||||||
write_file (LOG_PATH + '/down_devices_example.log', _json['down_devices'])
|
write_file (LOG_PATH + '/down_devices_example.log', _json['down_devices'])
|
||||||
payloadData += 'DOWN DEVICES:\n'
|
payloadData += 'DOWN DEVICES:\n'
|
||||||
for event in _json['down_devices']:
|
for event in _json['down_devices']:
|
||||||
@@ -1848,7 +1849,7 @@ def to_text(_json, eventLevel):
|
|||||||
event[4] = event[11]
|
event[4] = event[11]
|
||||||
payloadData += event[1] + ' - ' + event[4] + '\n'
|
payloadData += event[1] + ' - ' + event[4] + '\n'
|
||||||
|
|
||||||
if len(_json['events']) > 0 and eventLevel > 3:
|
if len(_json['events']) > 0 and 'events' in includedSections:
|
||||||
payloadData += "EVENTS:\n"
|
payloadData += "EVENTS:\n"
|
||||||
for event in _json['events']:
|
for event in _json['events']:
|
||||||
if event[8] != "Internet":
|
if event[8] != "Internet":
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ PRINT_LOG = False
|
|||||||
TIMEZONE = 'Europe/Berlin'
|
TIMEZONE = 'Europe/Berlin'
|
||||||
PIALERT_WEB_PROTECTION = False
|
PIALERT_WEB_PROTECTION = False
|
||||||
PIALERT_WEB_PASSWORD = '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92'
|
PIALERT_WEB_PASSWORD = '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92'
|
||||||
|
INCLUDED_SECTIONS = ['internet', 'new_devices', 'down_devices', 'events']
|
||||||
|
|
||||||
# EMAIL settings
|
# EMAIL settings
|
||||||
# ----------------------
|
# ----------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user