mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
MQTT, DHCPLSS work🔌
This commit is contained in:
@@ -395,7 +395,7 @@ $db->close();
|
||||
<!-- ---------------------------Logging-------------------------------------------- -->
|
||||
<div class="tab-pane" id="tab_Logging">
|
||||
<div class="db_info_table">
|
||||
<div class="log-area">
|
||||
<div class="log-area box box-solid box-primary">
|
||||
<div class="row logs-row">
|
||||
<textarea id="pialert_log" class="logs" cols="70" rows="10" wrap='off' readonly >
|
||||
<?php
|
||||
@@ -421,7 +421,18 @@ $db->close();
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="log-area">
|
||||
<div class="log-area box box-solid box-primary ">
|
||||
<div class="row logs-row">
|
||||
<textarea id="nginx_error_log" class="logs" cols="70" rows="10" wrap='off' readonly><?php echo file_get_contents( "/var/log/nginx/error.log" ); ?>
|
||||
</textarea>
|
||||
</div>
|
||||
<div class="row logs-row" >
|
||||
<div>
|
||||
<div class="log-file">nginx/error.log</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="log-area box box-solid box-primary">
|
||||
<div class="row logs-row">
|
||||
<textarea id="pialert_front_log" class="logs" cols="70" rows="10" wrap='off' readonly><?php echo file_get_contents( "./log/pialert_front.log" ); ?>
|
||||
</textarea>
|
||||
@@ -437,7 +448,7 @@ $db->close();
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="log-area">
|
||||
<div class="log-area box box-solid box-primary">
|
||||
<div class="row logs-row">
|
||||
<textarea id="pialert_php_log" class="logs" cols="70" rows="10" wrap='off' readonly><?php echo file_get_contents( "./log/pialert.php_errors.log" ); ?>
|
||||
</textarea>
|
||||
@@ -454,7 +465,7 @@ $db->close();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="log-area">
|
||||
<div class="log-area box box-solid box-primary">
|
||||
|
||||
<div class="row logs-row">
|
||||
<textarea id="pialert_pholus_lastrun_log" class="logs logs-small" cols="70" rows="10" wrap='off' readonly><?php echo file_get_contents( "./log/pialert_pholus_lastrun.log" ); ?>
|
||||
@@ -472,7 +483,7 @@ $db->close();
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="log-area">
|
||||
<div class="log-area box box-solid box-primary">
|
||||
|
||||
<div class="row logs-row">
|
||||
<textarea id="IP_changes_log" class="logs logs-small" cols="70" rows="10" readonly><?php echo file_get_contents( "./log/IP_changes.log" ); ?>
|
||||
@@ -490,7 +501,7 @@ $db->close();
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="log-area">
|
||||
<div class="log-area box box-solid box-primary">
|
||||
<div class="row logs-row">
|
||||
<textarea id="stdout_log" class="logs logs-small" cols="70" rows="10" wrap='off' readonly><?php echo file_get_contents( "./log/stdout.log" ); ?>
|
||||
</textarea>
|
||||
@@ -507,7 +518,7 @@ $db->close();
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="log-area">
|
||||
<div class="log-area box box-solid box-primary">
|
||||
<div class="row logs-row">
|
||||
<textarea id="stderr_log" class="logs logs-small" cols="70" rows="10" wrap='off' readonly><?php echo file_get_contents( "./log/stderr.log" ); ?>
|
||||
</textarea>
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
},
|
||||
{
|
||||
"column": "Watched_Value1",
|
||||
"css_classes": "col-sm-2",
|
||||
"css_classes": "col-sm-3",
|
||||
"show": true,
|
||||
"type": "label",
|
||||
"default_value":"",
|
||||
|
||||
@@ -37,6 +37,7 @@ plugin_objects = Plugin_Objects(RESULT_FILE)
|
||||
md5_hash = hashlib.md5()
|
||||
|
||||
pluginName = 'MQTT'
|
||||
module_name = pluginName
|
||||
|
||||
# globals
|
||||
|
||||
@@ -66,7 +67,6 @@ def main():
|
||||
#-------------------------------------------------------------------------------
|
||||
# MQTT
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def check_config():
|
||||
if get_setting_value('MQTT_BROKER') == '' or get_setting_value('MQTT_PORT') == '' or get_setting_value('MQTT_USER') == '' or get_setting_value('MQTT_PASSWORD') == '':
|
||||
@@ -97,7 +97,12 @@ class sensor_config:
|
||||
hash_value = str(md5_hash_hex)
|
||||
|
||||
self.hash = hash_value
|
||||
self.isNew = getPluginObject({"Plugin":"MQTT", "Watched_Value4":hash_value}) is None
|
||||
|
||||
plugObj = getPluginObject({"Plugin":"MQTT", "Watched_Value3":hash_value})
|
||||
|
||||
mylog('verbose', [f"[{pluginName}] Previous plugin object entry: {json.dumps(plugObj)}"])
|
||||
|
||||
self.isNew = plugObj == {}
|
||||
|
||||
# Log sensor
|
||||
global plugin_objects
|
||||
@@ -150,9 +155,10 @@ def create_generic_device(client):
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
def create_sensor(client, deviceId, deviceName, sensorType, sensorName, icon, mac=""):
|
||||
|
||||
global mqtt_sensors
|
||||
global mqtt_sensors
|
||||
|
||||
new_sensor_config = sensor_config(deviceId, deviceName, sensorType, sensorName, icon, mac)
|
||||
|
||||
@@ -268,8 +274,10 @@ def mqtt_start(db):
|
||||
|
||||
mylog('minimal', [f"[{pluginName}] Estimated delay: ", (sec_delay), 's ', '(', round(sec_delay/60,1) , 'min)' ])
|
||||
|
||||
for device in devices:
|
||||
|
||||
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"])
|
||||
|
||||
@@ -6,6 +6,7 @@ import subprocess
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import chardet
|
||||
|
||||
sys.path.append("/home/pi/pialert/front/plugins")
|
||||
sys.path.append('/home/pi/pialert/pialert')
|
||||
|
||||
@@ -94,8 +94,7 @@ def main():
|
||||
|
||||
|
||||
def execute_pholus_scan(userSubnets, timeoutSec):
|
||||
# output of possible multiple interfaces
|
||||
arpscan_output = ""
|
||||
# output of possible multiple interfaces
|
||||
result_list = []
|
||||
|
||||
timeoutPerSubnet = float(timeoutSec) / len(userSubnets)
|
||||
|
||||
@@ -13,5 +13,5 @@ source myenv/bin/activate
|
||||
update-alternatives --install /usr/bin/python python /usr/bin/python3 10
|
||||
|
||||
# install packages thru pip3
|
||||
pip3 install requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli
|
||||
pip3 install requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet
|
||||
|
||||
|
||||
@@ -204,9 +204,12 @@ def getPluginObject(keyValues):
|
||||
with open(plugins_objects, 'r') as json_file:
|
||||
data = json.load(json_file)
|
||||
|
||||
for item in data.get("data", []):
|
||||
objectEntries = data.get("data", [])
|
||||
|
||||
for item in objectEntries:
|
||||
# Initialize a flag to check if all key-value pairs match
|
||||
all_match = True
|
||||
all_match = True
|
||||
|
||||
for key, value in keyValues.items():
|
||||
if item.get(key) != value:
|
||||
all_match = False
|
||||
@@ -215,14 +218,14 @@ def getPluginObject(keyValues):
|
||||
if all_match:
|
||||
return item
|
||||
|
||||
mylog('debug', [f'[{module_name}] Error - Object not found {json.dumps(keyValues)} '])
|
||||
mylog('verbose', [f'[{module_name}] Error - Object not found {json.dumps(keyValues)} '])
|
||||
|
||||
return None
|
||||
return {}
|
||||
|
||||
except (FileNotFoundError, json.JSONDecodeError, ValueError) as e:
|
||||
# Handle the case when the file is not found, JSON decoding fails, or data is not in the expected format
|
||||
mylog('none', [f'[{module_name}] Error - JSONDecodeError or FileNotFoundError for file {plugins_objects}'])
|
||||
mylog('verbose', [f'[{module_name}] Error - JSONDecodeError or FileNotFoundError for file {plugins_objects}'])
|
||||
|
||||
return None
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user