MQTT rework v0.4, install scripts rework, Traefik docs 📦
This commit is contained in:
0
front/php/templates/language/de_de.json
Normal file → Executable file
0
front/php/templates/language/de_de.json
Normal file → Executable file
@@ -66,14 +66,14 @@
|
||||
{
|
||||
"column": "Object_PrimaryID",
|
||||
"css_classes": "col-sm-2",
|
||||
"show": false,
|
||||
"show": true,
|
||||
"type": "url",
|
||||
"default_value":"",
|
||||
"options": [],
|
||||
"localized": ["name"],
|
||||
"name":[{
|
||||
"language_code": "en_us",
|
||||
"string" : "N/A"
|
||||
"string" : "MQTT Device ID"
|
||||
}]
|
||||
},
|
||||
{
|
||||
@@ -86,7 +86,7 @@
|
||||
"localized": ["name"],
|
||||
"name":[{
|
||||
"language_code": "en_us",
|
||||
"string" : "Sensor ID"
|
||||
"string" : "Sensor Name"
|
||||
}]
|
||||
},
|
||||
{
|
||||
@@ -134,7 +134,7 @@
|
||||
},
|
||||
{
|
||||
"column": "Watched_Value2",
|
||||
"css_classes": "col-sm-8",
|
||||
"css_classes": "col-sm-2",
|
||||
"show": true,
|
||||
"type": "label",
|
||||
"default_value":"",
|
||||
@@ -155,20 +155,20 @@
|
||||
"localized": ["name"],
|
||||
"name":[{
|
||||
"language_code": "en_us",
|
||||
"string" : "Sensor name"
|
||||
"string" : "Hash"
|
||||
}]
|
||||
},
|
||||
{
|
||||
"column": "Watched_Value4",
|
||||
"css_classes": "col-sm-2",
|
||||
"show": true,
|
||||
"show": false,
|
||||
"type": "label",
|
||||
"default_value":"",
|
||||
"options": [],
|
||||
"localized": ["name"],
|
||||
"name":[{
|
||||
"language_code": "en_us",
|
||||
"string" : "Hash"
|
||||
"string" : "N/A"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -10,6 +10,7 @@ from datetime import datetime
|
||||
import time
|
||||
import re
|
||||
from paho.mqtt import client as mqtt_client
|
||||
import hashlib
|
||||
|
||||
|
||||
# Replace these paths with the actual paths to your Pi.Alert directories
|
||||
@@ -18,8 +19,8 @@ sys.path.extend(["/home/pi/pialert/front/plugins", "/home/pi/pialert/pialert"])
|
||||
# PiAlert modules
|
||||
import conf
|
||||
from const import apiPath
|
||||
from plugin_helper import getPluginObject
|
||||
from plugin_utils import Plugin_Objects
|
||||
from plugin_utils import getPluginObject
|
||||
from plugin_helper import Plugin_Objects
|
||||
from logger import mylog, append_line_to_file
|
||||
from helper import timeNowTZ, noti_obj, get_setting_value, bytes_to_string, sanitize_string
|
||||
from notification import Notification_obj
|
||||
@@ -32,6 +33,8 @@ RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log')
|
||||
|
||||
# Initialize the Plugin obj output file
|
||||
plugin_objects = Plugin_Objects(RESULT_FILE)
|
||||
# Create an MD5 hash object
|
||||
md5_hash = hashlib.md5()
|
||||
|
||||
pluginName = 'MQTT'
|
||||
|
||||
@@ -81,19 +84,31 @@ class sensor_config:
|
||||
self.sensorType = sensorType
|
||||
self.sensorName = sensorName
|
||||
self.icon = icon
|
||||
self.hash = str(hash(str(deviceId) + str(deviceName)+ str(sensorType)+ str(sensorName)+ str(icon)))
|
||||
self.isNew = getPluginObject({"Plugin":"MQTT", "Watched_Value4":hash}) is None
|
||||
|
||||
# Define your input string
|
||||
input_string = str(deviceId) + str(deviceName) + str(sensorType) + str(sensorName) + str(icon)
|
||||
|
||||
# Hash the input string and convert the hash to a string
|
||||
# Update the hash object with the bytes of the input string
|
||||
md5_hash.update(input_string.encode('utf-8'))
|
||||
|
||||
# Get the hexadecimal representation of the MD5 hash
|
||||
md5_hash_hex = md5_hash.hexdigest()
|
||||
hash_value = str(md5_hash_hex)
|
||||
|
||||
self.hash = hash_value
|
||||
self.isNew = getPluginObject({"Plugin":"MQTT", "Watched_Value4":hash_value}) is None
|
||||
|
||||
# Log sensor
|
||||
global plugin_objects
|
||||
|
||||
plugin_objects.add_object(
|
||||
primaryId = pluginName,
|
||||
secondaryId = deviceId,
|
||||
primaryId = deviceId,
|
||||
secondaryId = sensorName,
|
||||
watched1 = deviceName,
|
||||
watched2 = sensorType,
|
||||
watched3 = sensorName,
|
||||
watched4 = hash,
|
||||
watched3 = hash,
|
||||
watched4 = 'null',
|
||||
extra = 'null',
|
||||
foreignKey = deviceId
|
||||
)
|
||||
|
||||
@@ -18,8 +18,12 @@ CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
||||
LOG_FILE = os.path.join(CUR_PATH, 'script.log')
|
||||
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log')
|
||||
|
||||
|
||||
pluginName= 'DHCPLSS'
|
||||
|
||||
# -------------------------------------------------------------
|
||||
def main():
|
||||
mylog('verbose', ['[DHCPLSS] In script'])
|
||||
mylog('verbose', [f'[{pluginName}] In script'])
|
||||
last_run_logfile = open(RESULT_FILE, 'a')
|
||||
last_run_logfile.write("")
|
||||
|
||||
@@ -32,42 +36,49 @@ def main():
|
||||
if values.paths:
|
||||
for path in values.paths.split('=')[1].split(','):
|
||||
plugin_objects = get_entries(path, plugin_objects)
|
||||
mylog('verbose', [f'[DHCPLSS] {len(plugin_objects)} Entries found in "{path}"'])
|
||||
mylog('verbose', [f'[{pluginName}] {len(plugin_objects)} Entries found in "{path}"'])
|
||||
|
||||
plugin_objects.write_result_file()
|
||||
|
||||
# -------------------------------------------------------------
|
||||
def get_entries(path, plugin_objects):
|
||||
if 'pihole' in path:
|
||||
|
||||
|
||||
with open(path, 'r') as f:
|
||||
for line in f:
|
||||
row = line.rstrip().split()
|
||||
if len(row) == 5:
|
||||
plugin_objects.add_object(
|
||||
primaryId = handleEmpty(row[1]),
|
||||
secondaryId = handleEmpty(row[2]),
|
||||
watched1 = handleEmpty('True'),
|
||||
watched2 = handleEmpty(row[3]),
|
||||
watched3 = handleEmpty(row[4]),
|
||||
watched4 = handleEmpty('True'),
|
||||
extra = handleEmpty(path),
|
||||
foreignKey = handleEmpty(row[1])
|
||||
)
|
||||
|
||||
# Check if the path exists
|
||||
if os.path.exists(path) == False:
|
||||
mylog('none', [f'[{pluginName}] Error: "{path}" does not exist.'])
|
||||
else:
|
||||
leases = DhcpLeases(path)
|
||||
leasesList = leases.get()
|
||||
for lease in leasesList:
|
||||
plugin_objects.add_object(
|
||||
primaryId = handleEmpty(lease.ethernet),
|
||||
secondaryId = handleEmpty(lease.ip),
|
||||
watched1 = handleEmpty(lease.active),
|
||||
watched2 = handleEmpty(lease.hostname),
|
||||
watched3 = handleEmpty(lease.hardware),
|
||||
watched4 = handleEmpty(lease.binding_state),
|
||||
extra = handleEmpty(path),
|
||||
foreignKey = handleEmpty(lease.ethernet)
|
||||
)
|
||||
# Handle pihole specific dhcp.leases files
|
||||
if 'pihole' in path:
|
||||
|
||||
with open(path, 'r') as f:
|
||||
for line in f:
|
||||
row = line.rstrip().split()
|
||||
if len(row) == 5:
|
||||
plugin_objects.add_object(
|
||||
primaryId = handleEmpty(row[1]),
|
||||
secondaryId = handleEmpty(row[2]),
|
||||
watched1 = handleEmpty('True'),
|
||||
watched2 = handleEmpty(row[3]),
|
||||
watched3 = handleEmpty(row[4]),
|
||||
watched4 = handleEmpty('True'),
|
||||
extra = handleEmpty(path),
|
||||
foreignKey = handleEmpty(row[1])
|
||||
)
|
||||
else:
|
||||
# Handle generic dhcp.leases files
|
||||
leases = DhcpLeases(path)
|
||||
leasesList = leases.get()
|
||||
for lease in leasesList:
|
||||
plugin_objects.add_object(
|
||||
primaryId = handleEmpty(lease.ethernet),
|
||||
secondaryId = handleEmpty(lease.ip),
|
||||
watched1 = handleEmpty(lease.active),
|
||||
watched2 = handleEmpty(lease.hostname),
|
||||
watched3 = handleEmpty(lease.hardware),
|
||||
watched4 = handleEmpty(lease.binding_state),
|
||||
extra = handleEmpty(path),
|
||||
foreignKey = handleEmpty(lease.ethernet)
|
||||
)
|
||||
return plugin_objects
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user