diff --git a/docs/WEB_UI_PORT_DEBUG.md b/docs/WEB_UI_PORT_DEBUG.md index bb93c508..342c03fd 100755 --- a/docs/WEB_UI_PORT_DEBUG.md +++ b/docs/WEB_UI_PORT_DEBUG.md @@ -1,12 +1,14 @@ # Debugging inaccessible UI -When opening an issue please : +When opening an issue please: 1. Include a screenshot of what you see when accessing `HTTP:///20211` (or your custom port) 1. [Follow steps 1, 2, 3, 4 on this page](https://github.com/jokob-sk/NetAlertX/blob/main/docs/DEBUG_TIPS.md) 1. Execute the following in the container to see the processes and their ports and submit a screenshot of the result: 1. `sudo apt-get install lsof` 1. `sudo lsof -i` +1. Try running the `nginx` command in the container + 1. if you get `nginx: [emerg] bind() to 0.0.0.0:20211 failed (98: Address in use)` try using a different port number ![lsof ports](/docs/img/WEB_UI_PORT_DEBUG/container_port.png) \ No newline at end of file diff --git a/front/img/NetAlertX_logo.png b/front/img/NetAlertX_logo.png index a3bfaec7..0ccc86fb 100755 Binary files a/front/img/NetAlertX_logo.png and b/front/img/NetAlertX_logo.png differ diff --git a/front/img/NetAlertX_logo_notification.png b/front/img/NetAlertX_logo_notification.png index 5a18b9fe..9c9e2b08 100755 Binary files a/front/img/NetAlertX_logo_notification.png and b/front/img/NetAlertX_logo_notification.png differ diff --git a/front/img/NetAlertX_logo_notification_old.png b/front/img/NetAlertX_logo_notification_old.png new file mode 100755 index 00000000..5a18b9fe Binary files /dev/null and b/front/img/NetAlertX_logo_notification_old.png differ diff --git a/front/img/NetAlertX_logo_old.png b/front/img/NetAlertX_logo_old.png new file mode 100755 index 00000000..a3bfaec7 Binary files /dev/null and b/front/img/NetAlertX_logo_old.png differ diff --git a/front/img/svg/netalertx_red_1_backup.svg b/front/img/svg/netalertx_red_1_backup.svg new file mode 100755 index 00000000..9a435953 --- /dev/null +++ b/front/img/svg/netalertx_red_1_backup.svg @@ -0,0 +1,365 @@ + + + + + + + + + + + + + + + A + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/front/php/templates/language/de_de.json b/front/php/templates/language/de_de.json old mode 100644 new mode 100755 diff --git a/front/php/templates/language/it_it.json b/front/php/templates/language/it_it.json old mode 100644 new mode 100755 diff --git a/front/php/templates/language/ru_ru.json b/front/php/templates/language/ru_ru.json old mode 100644 new mode 100755 diff --git a/front/plugins/_publisher_mqtt/config.json b/front/plugins/_publisher_mqtt/config.json index 64cbb1df..3fe65744 100755 --- a/front/plugins/_publisher_mqtt/config.json +++ b/front/plugins/_publisher_mqtt/config.json @@ -587,26 +587,6 @@ } ] }, - { - "function": "PRESENCE_SENSOR_TYPE", - "events": [], - "type": "text.select", - "default_value": "binary_sensor", - "options": ["binary_sensor", "device_tracker"], - "localized": ["name", "description"], - "name": [ - { - "language_code": "en_us", - "string": "Presence Sensor Type" - } - ], - "description": [ - { - "language_code": "en_us", - "string": "The type of the sensor that should be generated for the is_present sensor. Inserted into the homeassistant/{MQTT_PRESENCE_SENSOR_TYPE}/mac_44_ef_44_ef_44_ef/is_present/ topic. See the Plugin readme for details." - } - ] - }, { "function": "QOS", "type": "integer.select", diff --git a/front/plugins/_publisher_mqtt/mqtt.py b/front/plugins/_publisher_mqtt/mqtt.py index 3d42041a..19710373 100755 --- a/front/plugins/_publisher_mqtt/mqtt.py +++ b/front/plugins/_publisher_mqtt/mqtt.py @@ -79,6 +79,7 @@ def check_config(): #------------------------------------------------------------------------------- +# Sensor configs are tracking which sensors in NetAlertX exist and if a config has changed class sensor_config: def __init__(self, deviceId, deviceName, sensorType, sensorName, icon, mac): self.deviceId = deviceId @@ -189,45 +190,91 @@ def create_sensor(mqtt_client, deviceId, deviceName, sensorType, sensorName, ico global mqtt_sensors - new_sensor_config = sensor_config(deviceId, deviceName, sensorType, sensorName, icon, mac) - - # save if new - if new_sensor_config.isNew: - mylog('verbose', [f"[{pluginName}] Publishing sensor number {len(mqtt_sensors)}"]) - publish_sensor(mqtt_client, new_sensor_config) + # check previous configs + sensorConfig = sensor_config(deviceId, deviceName, sensorType, sensorName, icon, mac) + + mylog('verbose', [f"[{pluginName}] Publishing sensor number {len(mqtt_sensors)}"]) + + state_topic = '' + topic = '' + + # binary sensor only sensor + if sensorConfig.sensorType == 'binary_sensor' or sensorConfig.sensorType == 'sensor': + + topic = f'homeassistant/{sensorConfig.sensorType}/{sensorConfig.deviceId}/{sensorConfig.sensorName}/config' + state_topic = f'system-sensors/{sensorConfig.sensorType}/{sensorConfig.deviceId}/state' + + + message = { + "name" : sensorConfig.sensorName, + "state_topic" : state_topic, + "value_template" : "{{value_json."+sensorConfig.sensorName+"}}", + "unique_id" : sensorConfig.deviceId+'_sensor_'+sensorConfig.sensorName, + "device": + { + "identifiers" : [sensorConfig.deviceId+"_sensor"], + "manufacturer" : "NetAlertX", + "name" : sensorConfig.deviceName + }, + "icon": f'mdi:{sensorConfig.icon}' + } + + + + elif sensorConfig.sensorType == 'device_tracker': + + + topic = f'homeassistant/device_tracker/{sensorConfig.deviceId}/config' + state_topic = f'system-sensors/device_tracker/{sensorConfig.deviceId}/state' + unique_id = f'{sensorConfig.deviceId}_{sensorConfig.sensorType}_{sensorConfig.sensorName}' + + message = { + "state_topic": state_topic, + "name": sensorConfig.sensorName, + "payload_home": "home", + "payload_not_home": "away", + "unique_id" : unique_id, + "icon": f'mdi:{sensorConfig.icon}', + "device": + { + "identifiers" : [sensorConfig.deviceId+"_sensor", unique_id], + "manufacturer" : "NetAlertX", + "name" : sensorConfig.deviceName + }, + } + + + + # mosquitto_pub -h 127.0.0.1 -t homeassistant/device_tracker/a4567d663eaf/config -m '{"state_topic": "a4567d663eaf/state", "name": "My Tracker", "payload_home": "home", "payload_not_home": "not_home"}' + # mosquitto_pub -h 127.0.0.1 -t homeassistant/device_tracker/a4567d663eaf/config -m '{"json_attributes_topic": "a4567d663eaf/attributes", "name": "My Tracker"}' + # mosquitto_pub -h 127.0.0.1 -t a4567d663eaf/state -m 'home' -#------------------------------------------------------------------------------- -def publish_sensor(mqtt_client, sensorConfig): - global mqtt_sensors + # # create device tracker attributes + # publish_mqtt(mqtt_client, f'homeassistant/device_tracker/a4567d663eaf/config', + # { + # "json_attributes_topic": f"{deviceId}/attributes", + # "name": deviceNameDisplay + # } + # ) - icon = "mdi:" + sensorConfig.icon - - message = { - "name" : sensorConfig.sensorName, - "state_topic" : "system-sensors/"+sensorConfig.sensorType+'/'+sensorConfig.deviceId+"/state", - "value_template" : "{{value_json."+sensorConfig.sensorName+"}}", - "unique_id" : sensorConfig.deviceId+'_sensor_'+sensorConfig.sensorName, - "device": - { - "identifiers" : [sensorConfig.deviceId+"_sensor"], - "manufacturer" : "NetAlertX", - "name" : sensorConfig.deviceName - }, - "icon": icon - } - - topic='homeassistant/'+sensorConfig.sensorType+'/'+sensorConfig.deviceId+'/'+sensorConfig.sensorName+'/config' + # send if new TODO uncomment + # if sensorConfig.isNew: # add the sensor to the global list to keep track of succesfully added sensors if publish_mqtt(mqtt_client, topic, message): - # hack - delay adding to the queue in case the process is + # hack - delay adding to the queue in case the process is time.sleep(get_setting_value('MQTT_DELAY_SEC')) # restarted and previous publish processes aborted - # (it takes ~2s to update a sensor config on the broker) - mqtt_sensors.append(sensorConfig) + # (it takes ~2s to update a sensor config on the broker) + mqtt_sensors.append(sensorConfig) + + return state_topic + + + #------------------------------------------------------------------------------- def mqtt_create_client(): @@ -279,8 +326,7 @@ def mqtt_start(db): deviceName = get_setting_value('MQTT_DEVICE_NAME') - deviceId = get_setting_value('MQTT_DEVICE_ID') - presenceSenType = get_setting_value('MQTT_PRESENCE_SENSOR_TYPE') + deviceId = get_setting_value('MQTT_DEVICE_ID') # General stats @@ -316,40 +362,57 @@ def mqtt_start(db): mylog('verbose', [f"[{pluginName}] Estimated delay: ", (sec_delay), 's ', '(', round(sec_delay/60,1) , 'min)' ]) - # debug_index = 0 + debug_index = 0 for device in devices: - - # Create devices in Home Assistant - send config messages - deviceId = 'mac_' + device["dev_MAC"].replace(" ", "").replace(":", "_").lower() - deviceNameDisplay = re.sub('[^a-zA-Z0-9-_\s]', '', device["dev_Name"]) - create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'last_ip', 'ip-network', device["dev_MAC"]) - create_sensor(mqtt_client, deviceId, deviceNameDisplay, presenceSenType, 'is_present', 'wifi', device["dev_MAC"]) - create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'mac_address', 'folder-key-network', device["dev_MAC"]) - create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'is_new', 'bell-alert-outline', device["dev_MAC"]) - create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'vendor', 'cog', device["dev_MAC"]) - create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'first_connection', 'calendar-start', device["dev_MAC"]) - create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'last_connection', 'calendar-end', device["dev_MAC"]) - - # update device sensors in home assistant + # TODO remove + if 'Moto' in device["dev_Name"]: + + + # Create devices in Home Assistant - send config messages + deviceId = 'mac_' + device["dev_MAC"].replace(" ", "").replace(":", "_").lower() + deviceNameDisplay = re.sub('[^a-zA-Z0-9-_\s]', '', device["dev_Name"]) - publish_mqtt(mqtt_client, 'system-sensors/sensor/'+deviceId+'/state', - { - "last_ip": device["dev_LastIP"], - "is_new": str(device["dev_NewDevice"]), - "vendor": sanitize_string(device["dev_Vendor"]), - "mac_address": str(device["dev_MAC"]), - "last_connection": str(device["dev_LastConnection"]), - "first_connection": str(device["dev_FirstConnection"]) - } - ) + state_topic = create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'last_ip', 'ip-network', device["dev_MAC"]) + state_topic = create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'mac_address', 'folder-key-network', device["dev_MAC"]) + state_topic = create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'is_new', 'bell-alert-outline', device["dev_MAC"]) + state_topic = create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'vendor', 'cog', device["dev_MAC"]) + state_topic = create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'first_connection', 'calendar-start', device["dev_MAC"]) + state_topic = create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'sensor', 'last_connection', 'calendar-end', device["dev_MAC"]) + + # bulk update device sensors in home assistant + + publish_mqtt(mqtt_client, state_topic, + { + "last_ip": device["dev_LastIP"], + "is_new": str(device["dev_NewDevice"]), + "vendor": sanitize_string(device["dev_Vendor"]), + "mac_address": str(device["dev_MAC"]), + "last_connection": str(device["dev_LastConnection"]), + "first_connection": str(device["dev_FirstConnection"]) + } + ) + + # create and update is_present sensor + state_topic = create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'binary_sensor', 'is_present', 'wifi', device["dev_MAC"]) + publish_mqtt(mqtt_client, state_topic, + { + "is_present": to_binary_sensor(str(device["dev_PresentLastScan"])) + } + ) + + # handle device_tracker + state_topic = create_sensor(mqtt_client, deviceId, deviceNameDisplay, 'device_tracker', 'is_home', 'home', device["dev_MAC"]) + + # are only valid states + state = 'away' + if to_binary_sensor(str(device["dev_PresentLastScan"])) == "ON": + state = 'home' + + publish_mqtt(mqtt_client, state_topic, state) + - publish_mqtt(mqtt_client, f'system-sensors/{presenceSenType}/{deviceId}/state', - { - "is_present": to_binary_sensor(str(device["dev_PresentLastScan"])) - } - ) # delete device / topic # homeassistant/sensor/mac_44_ef_bf_c4_b1_af/is_present/config diff --git a/front/plugins/notification_processing/README.md b/front/plugins/notification_processing/README.md index 1dbdc6d1..44f40398 100755 --- a/front/plugins/notification_processing/README.md +++ b/front/plugins/notification_processing/README.md @@ -1,6 +1,17 @@ ## Overview -Plugin supplying settings for Notification Processing. +Plugin supplying settings for Notification Processing. + +### Notify on: `NTFPRCS_INCLUDED_SECTIONS`: + +- `new_devices` - if a new device is detected +- `down_devices` - if a device with **Alert down** enabled (on a specific Device) disconnects +- `down_reconnected` - if a device, previously marked down and notified on, reconnects +- `events` - if an event for a device that has **Alert All Events** enabled, is triggered +- `plugins` - if an event for a plugin, is triggered + + +Check the [Notifications guide](/docs/NOTIFICATIONS.md) for more details. ### Usage diff --git a/server/helper.py b/server/helper.py index bf1960b7..06efa775 100755 --- a/server/helper.py +++ b/server/helper.py @@ -700,7 +700,7 @@ def sanitize_string(input): if isinstance(input, bytes): input = input.decode('utf-8') input = bytes_to_string(re.sub(r'[^a-zA-Z0-9-_\s]', '', str(input))) - return value + return input #------------------------------------------------------------------------------- diff --git a/server/networkscan.py b/server/networkscan.py index 9a746871..69e9ecbb 100755 --- a/server/networkscan.py +++ b/server/networkscan.py @@ -61,6 +61,7 @@ def process_scan (db): skip_repeated_notifications (db) # Clear current scan as processed + # TODO comment below for CurrentScan debugging db.sql.execute ("DELETE FROM CurrentScan") # Commit changes