diff --git a/docs/SUBNETS.md b/docs/SUBNETS.md index 0c5a9a9a..877f3319 100755 --- a/docs/SUBNETS.md +++ b/docs/SUBNETS.md @@ -4,6 +4,9 @@ You need to specify the network interface and the network mask. You can also con ## Examples +> [!NOTE] +> Please use the UI to configure settings as that ensures that the config file is in the correct format. Edit `pialert.conf` directly only when really necessary. + * Examples for one and two subnets (❗ Note the `['...', '...']` format): * One subnet: `SCAN_SUBNETS = ['192.168.1.0/24 --interface=eth0']` * Two subnets: `SCAN_SUBNETS = ['192.168.1.0/24 --interface=eth0', '192.168.1.0/24 --interface=eth1 -vlan=107']` diff --git a/front/plugins/notification_processing/config.json b/front/plugins/notification_processing/config.json index cdd32c6d..72e13d0b 100755 --- a/front/plugins/notification_processing/config.json +++ b/front/plugins/notification_processing/config.json @@ -27,101 +27,7 @@ "params" : [ ], - "settings": [ - { - "function": "RUN", - "events": ["run"], - "type": "text.select", - "default_value":"schedule", - "options": ["disabled", "before_notification"], - "localized": ["name", "description"], - "name" :[{ - "language_code":"en_us", - "string" : "When to run" - }, - { - "language_code":"es_es", - "string" : "Cuándo ejecutar" - }, - { - "language_code":"de_de", - "string" : "Wann laufen" - }], - "description": [{ - "language_code":"en_us", - "string" : "When the Notification manipulation should happen. Usually set to before_notification." - }] - }, - { - "function": "CMD", - "type": "readonly", - "default_value": "python3 /home/pi/pialert/front/plugins/notification_processing/script.py", - "options": [], - "localized": ["name", "description"], - "name": [ - { - "language_code": "en_us", - "string": "Command" - }, - { - "language_code": "es_es", - "string": "Comando" - }, - { - "language_code": "de_de", - "string": "Befehl" - } - ], - "description": [ - { - "language_code": "en_us", - "string": "Command to run. This can not be changed" - }, - { - "language_code": "es_es", - "string": "Comando a ejecutar. Esto no se puede cambiar" - }, - { - "language_code": "de_de", - "string": "Befehl zum Ausführen. Dies kann nicht geändert werden" - } - ] - }, - { - "function": "RUN_TIMEOUT", - "type": "integer", - "default_value": 30, - "options": [], - "localized": ["name", "description"], - "name": [ - { - "language_code": "en_us", - "string": "Run timeout" - }, - { - "language_code": "es_es", - "string": "Tiempo límite de ejecución" - }, - { - "language_code": "de_de", - "string": "Zeitüberschreitung" - } - ], - "description": [ - { - "language_code": "en_us", - "string": "Maximum time in seconds to wait for the script to finish. If this time is exceeded the script is aborted." - }, - { - "language_code": "es_es", - "string": "Tiempo máximo en segundos para esperar a que finalice el script. Si se supera este tiempo, el script se cancela." - }, - { - "language_code": "de_de", - "string": "Maximale Zeit in Sekunden, die auf den Abschluss des Skripts gewartet werden soll. Bei Überschreitung dieser Zeit wird das Skript abgebrochen." - } - ] - }, + "settings": [ { "function": "alert_down_time", "type": "integer", @@ -137,7 +43,45 @@ "description": [ { "language_code": "en_us", - "string": "After how many minutes a down device is reported." + "string": "After how many minutes a device is reported as down and a notification is sent." + } + ] + }, + { + "function": "new_dev_condition", + "type": "text", + "default_value": "", + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "New Devices Filter" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "You can specify a SQL where condition to filter out New Devices from notifications. For example AND dev_LastIP NOT LIKE '192.168.3.%' will always exlude New Device notifications for all devices with the IP starting with 192.168.3.%." + } + ] + }, + { + "function": "event_condition", + "type": "text", + "default_value": "", + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "Events Filter" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "You can specify a SQL where condition to filter out Events from notifications. For example AND dev_LastIP NOT LIKE '192.168.3.%' will always exlude New Device notifications for all devices with the IP starting with 192.168.3.%." } ] } diff --git a/pialert/notification.py b/pialert/notification.py index 6d190dfe..31d22a52 100755 --- a/pialert/notification.py +++ b/pialert/notification.py @@ -46,7 +46,7 @@ class Notification_obj: # Create a new DB entry if new notifications available, otherwise skip def create(self, JSON, Extra=""): - JSON, Extra = self.on_before_create(self, JSON, Extra) + JSON, Extra = self.on_before_create(JSON, Extra) # Write output data for debug write_file (logPath + '/report_output.json', json.dumps(JSON)) diff --git a/pialert/reporting.py b/pialert/reporting.py index 6e4afbdc..0498d635 100755 --- a/pialert/reporting.py +++ b/pialert/reporting.py @@ -61,9 +61,10 @@ def get_notifications (db): if 'new_devices' in conf.INCLUDED_SECTIONS: # Compose New Devices Section - sqlQuery = """SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices + sqlQuery = f"""SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices WHERE eve_PendingAlertEmail = 1 AND eve_EventType = 'New Device' + {get_setting_value('NTFPRCS_new_dev_condition')} ORDER BY eve_DateTime""" # Get the events as JSON @@ -73,6 +74,7 @@ def get_notifications (db): "title": "New devices", "columnNames": json_obj.columnNames } + json_new_devices = json_obj.json["data"] if 'down_devices' in conf.INCLUDED_SECTIONS: @@ -105,10 +107,11 @@ def get_notifications (db): if 'events' in conf.INCLUDED_SECTIONS: # Compose Events Section - sqlQuery = """SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices + sqlQuery = f"""SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices WHERE eve_PendingAlertEmail = 1 AND eve_EventType IN ('Connected','Disconnected', 'IP Changed') + {get_setting_value('NTFPRCS_event_condition')} ORDER BY eve_DateTime""" # Get the events as JSON