Paho MQTT Version slection support + JS/CSS fixes #580 🩹
This commit is contained in:
@@ -1055,6 +1055,11 @@ input[readonly] {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pia-top-left-logo
|
||||||
|
{
|
||||||
|
height:50px;
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
Donations
|
Donations
|
||||||
----------------------------------------------------------------------------- */
|
----------------------------------------------------------------------------- */
|
||||||
|
|||||||
@@ -757,18 +757,7 @@ function getGuid() {
|
|||||||
// UI
|
// UI
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Generate work-in-progress icons
|
|
||||||
function workInProgress() {
|
|
||||||
|
|
||||||
if($(".work-in-progress").html().trim() == "")
|
|
||||||
{
|
|
||||||
$(".work-in-progress").append(`
|
|
||||||
<a href="https://github.com/jokob-sk/Pi.Alert/issues" target="_blank">
|
|
||||||
<b class="pointer" title="${getString("Gen_Work_In_Progress")}">🦺</b>
|
|
||||||
</a>
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Loading Spinner overlay
|
// Loading Spinner overlay
|
||||||
@@ -876,7 +865,6 @@ function executeOnce() {
|
|||||||
cacheSettings();
|
cacheSettings();
|
||||||
cacheStrings();
|
cacheStrings();
|
||||||
initDeviceListAll_JSON();
|
initDeviceListAll_JSON();
|
||||||
workInProgress();
|
|
||||||
|
|
||||||
// Set the flag in sessionStorage to indicate that the code has been executed and save time when last time the page for initialized
|
// Set the flag in sessionStorage to indicate that the code has been executed and save time when last time the page for initialized
|
||||||
sessionStorage.setItem(sessionStorageKey, "true");
|
sessionStorage.setItem(sessionStorageKey, "true");
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ if ($ENABLED_DARKMODE === True) {
|
|||||||
|
|
||||||
<!-- ----------------------------------------------------------------------- -->
|
<!-- ----------------------------------------------------------------------- -->
|
||||||
<!-- Layout Boxed Yellow -->
|
<!-- Layout Boxed Yellow -->
|
||||||
<body class="hold-transition <?php echo $pia_skin_selected;?> sidebar-mini" <?php echo $BACKGROUND_IMAGE_PATCH;?> onLoad="show_pia_servertime();" >
|
<body class="hold-transition fixed <?php echo $pia_skin_selected;?> sidebar-mini" <?php echo $BACKGROUND_IMAGE_PATCH;?> onLoad="show_pia_servertime();" >
|
||||||
<!-- Site wrapper -->
|
<!-- Site wrapper -->
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
|
|
||||||
@@ -122,9 +122,14 @@ if ($ENABLED_DARKMODE === True) {
|
|||||||
<!-- Logo -->
|
<!-- Logo -->
|
||||||
<a href="devices.php" class="logo">
|
<a href="devices.php" class="logo">
|
||||||
<!-- mini logo for sidebar mini 50x50 pixels -->
|
<!-- mini logo for sidebar mini 50x50 pixels -->
|
||||||
<span class="logo-mini">P<b>a</b></span>
|
<span class="logo-mini">
|
||||||
|
<img src="img/pialertLogoWhite.png" class="pia-top-left-logo" alt="Pi.Alert Logo"/>
|
||||||
|
</span>
|
||||||
<!-- logo for regular state and mobile devices -->
|
<!-- logo for regular state and mobile devices -->
|
||||||
<span class="logo-lg">Pi<b>.Alert</b></span>
|
<span class="logo-lg">Pi<b>.Alert</b>
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<!-- ----------------------------------------------------------------------- -->
|
<!-- ----------------------------------------------------------------------- -->
|
||||||
@@ -183,7 +188,7 @@ if ($ENABLED_DARKMODE === True) {
|
|||||||
<img src="img/pialertLogoWhite.png" class="img-circle" alt="Pi.Alert Logo" style="border-color:transparent; height: 50px; width: 50px; margin-top:15px;">
|
<img src="img/pialertLogoWhite.png" class="img-circle" alt="Pi.Alert Logo" style="border-color:transparent; height: 50px; width: 50px; margin-top:15px;">
|
||||||
<p style="float: right; width: 200px">
|
<p style="float: right; width: 200px">
|
||||||
<?= lang('About_Title');?>
|
<?= lang('About_Title');?>
|
||||||
<small><?= lang('About_Design');?> Raspberry Pi</small>
|
<small><?= lang('About_Design');?> Docker</small>
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
@@ -208,12 +213,6 @@ if ($ENABLED_DARKMODE === True) {
|
|||||||
<!-- sidebar: style can be found in sidebar.less -->
|
<!-- sidebar: style can be found in sidebar.less -->
|
||||||
<section class="sidebar">
|
<section class="sidebar">
|
||||||
|
|
||||||
<!-- Sidebar user panel (optional) -->
|
|
||||||
<div class="user-panel"> <a href="." class="logo">
|
|
||||||
<img src="img/pialertLogoGray80.png" class="img-responsive" alt="Pi.Alert Logo"/>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- search form (Optional) -->
|
<!-- search form (Optional) -->
|
||||||
<!-- DELETED -->
|
<!-- DELETED -->
|
||||||
|
|
||||||
@@ -248,9 +247,38 @@ if ($ENABLED_DARKMODE === True) {
|
|||||||
<div class="info-icon-nav myhidden" id="version" data-build-time="<?php echo file_get_contents( "buildtimestamp.txt");?>">🆕</div>
|
<div class="info-icon-nav myhidden" id="version" data-build-time="<?php echo file_get_contents( "buildtimestamp.txt");?>">🆕</div>
|
||||||
<a href="maintenance.php"><i class="fa fa-wrench "></i> <span><?= lang('Navigation_Maintenance');?></span></a>
|
<a href="maintenance.php"><i class="fa fa-wrench "></i> <span><?= lang('Navigation_Maintenance');?></span></a>
|
||||||
</li>
|
</li>
|
||||||
<li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('settings.php') ) ){ echo 'active'; } ?>">
|
<!-- <li class="treeview menu-open" style="height: auto;"> -->
|
||||||
<a href="settings.php"><i class="fa fa-cog"></i> <span><?= lang('Navigation_Settings');?></span></a>
|
<li class=" treeview <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('settings.php') ) ){ echo 'active menu-open'; } ?>">
|
||||||
|
<a href="#">
|
||||||
|
<i class="fa fa-cog"></i> <span><?= lang('Navigation_Settings');?></span>
|
||||||
|
<span class="pull-right-container">
|
||||||
|
<i class="fa fa-angle-left pull-right"></i>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<ul class="treeview-menu" style="display: <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('settings.php') ) ){ echo 'block'; } else {echo 'none';} ?>;">
|
||||||
|
<li>
|
||||||
|
<a href="settings.php"> <?= lang("settings_enabled");?> </a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="settings.php#core_content_header"> <?= lang("settings_core_label");?> </a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="settings.php#system_content_header"> <?= lang("settings_system_label");?> </a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="settings.php#device_scanner_content_header"> <?= lang("settings_device_scanners_label");?> </a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="settings.php#other_content_header"> <?= lang("settings_other_scanners_label");?> </a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="settings.php#publisher_content_header"> <?= lang("settings_publishers_label");?> </a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
<li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('workflows.php') ) ){ echo 'active'; } ?>">
|
<li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('workflows.php') ) ){ echo 'active'; } ?>">
|
||||||
<div class="info-icon-nav work-in-progress"> </div>
|
<div class="info-icon-nav work-in-progress"> </div>
|
||||||
<a href="workflows.php"><i class="fa fa-shuffle"></i> <span><?= lang('Navigation_Workflows');?></span></a>
|
<a href="workflows.php"><i class="fa fa-shuffle"></i> <span><?= lang('Navigation_Workflows');?></span></a>
|
||||||
@@ -274,6 +302,19 @@ if ($ENABLED_DARKMODE === True) {
|
|||||||
<script src="js/pialert_common.js"></script>
|
<script src="js/pialert_common.js"></script>
|
||||||
<script defer>
|
<script defer>
|
||||||
|
|
||||||
|
// Generate work-in-progress icons
|
||||||
|
function workInProgress() {
|
||||||
|
|
||||||
|
if($(".work-in-progress").html().trim() == "")
|
||||||
|
{
|
||||||
|
$(".work-in-progress").append(`
|
||||||
|
<a href="https://github.com/jokob-sk/Pi.Alert/issues" target="_blank">
|
||||||
|
<b class="pointer" title="${getString("Gen_Work_In_Progress")}">🦺</b>
|
||||||
|
</a>
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
@@ -295,5 +336,6 @@ if ($ENABLED_DARKMODE === True) {
|
|||||||
|
|
||||||
// Update server state in the header
|
// Update server state in the header
|
||||||
updateState()
|
updateState()
|
||||||
|
workInProgress()
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"API_icon": "<i class=\"fa fa-arrow-down-up-across-line\"></i>",
|
"API_icon": "<i class=\"fa fa-arrow-down-up-across-line\"></i>",
|
||||||
"About_Design": "Designed for:",
|
"About_Design": "Designed for:",
|
||||||
"About_Exit": "Sign out",
|
"About_Exit": "Sign out",
|
||||||
"About_Title": "Open Source Network Guard",
|
"About_Title": "Network security scanner & notification framework",
|
||||||
"AppEvents_DateTimeCreated": "Logged",
|
"AppEvents_DateTimeCreated": "Logged",
|
||||||
"AppEvents_Extra": "Extra",
|
"AppEvents_Extra": "Extra",
|
||||||
"AppEvents_GUID": "Application Event GUID",
|
"AppEvents_GUID": "Application Event GUID",
|
||||||
|
|||||||
0
front/php/templates/language/es_es.json
Normal file → Executable file
0
front/php/templates/language/es_es.json
Normal file → Executable file
@@ -464,13 +464,28 @@
|
|||||||
}],
|
}],
|
||||||
"description": [{
|
"description": [{
|
||||||
"language_code": "en_us",
|
"language_code": "en_us",
|
||||||
"string" : "Quality of service setting for MQTT message sending. <code>0</code> - Low quality to <code>2</code> - High quality. The higher the quality the longer the delay."
|
"string" : "Quality of service setting for MQTT message sending. The higher the quality the longer the delay. <br/> <code>0</code> - Low quality to <code>2</code> - High quality."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"language_code": "es_es",
|
"language_code": "es_es",
|
||||||
"string" : "Configuración de calidad de servicio para el envío de mensajes MQTT. <code>0</code>: baja calidad a <code>2</code>: alta calidad. Cuanto mayor sea la calidad, mayor será el retraso."
|
"string" : "Configuración de calidad de servicio para el envío de mensajes MQTT. <code>0</code>: baja calidad a <code>2</code>: alta calidad. Cuanto mayor sea la calidad, mayor será el retraso."
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"function": "VERSION",
|
||||||
|
"type": "integer.select",
|
||||||
|
"default_value": 1,
|
||||||
|
"options": [ 1, 2 ],
|
||||||
|
"localized": ["name", "description"],
|
||||||
|
"name" : [{
|
||||||
|
"language_code": "en_us",
|
||||||
|
"string" : "Version"
|
||||||
|
}],
|
||||||
|
"description": [{
|
||||||
|
"language_code": "en_us",
|
||||||
|
"string" : "Paho MQTT API version. Depends on the MQTT <a href=\"https://eclipse.dev/paho/files/paho.mqtt.python/html/index.html#callbacks\" target=\"_blank\">version supported by the MQTT broker</a>. Usually set to <code>1</code>."
|
||||||
|
}]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"function": "DELAY_SEC",
|
"function": "DELAY_SEC",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ plugin_objects = Plugin_Objects(RESULT_FILE)
|
|||||||
md5_hash = hashlib.md5()
|
md5_hash = hashlib.md5()
|
||||||
|
|
||||||
pluginName = 'MQTT'
|
pluginName = 'MQTT'
|
||||||
module_name = pluginName
|
|
||||||
|
|
||||||
# globals
|
# globals
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ def main():
|
|||||||
|
|
||||||
# Check if basic config settings supplied
|
# Check if basic config settings supplied
|
||||||
if check_config() == False:
|
if check_config() == False:
|
||||||
mylog('none', [f'[{pluginName}] ⚠ ERROR: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
|
mylog('verbose', [f'[{pluginName}] ⚠ ERROR: Publisher notification gateway not set up correctly. Check your pialert.conf {pluginName}_* variables.'])
|
||||||
return
|
return
|
||||||
|
|
||||||
# Create a database connection
|
# Create a database connection
|
||||||
@@ -72,7 +71,7 @@ def main():
|
|||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def check_config():
|
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') == '':
|
if get_setting_value('MQTT_BROKER') == '' or get_setting_value('MQTT_PORT') == '' or get_setting_value('MQTT_USER') == '' or get_setting_value('MQTT_PASSWORD') == '':
|
||||||
mylog('none', ['[Check Config] ⚠ ERROR: MQTT service not set up correctly. Check your pialert.conf MQTT_* variables.'])
|
mylog('verbose', ['[Check Config] ⚠ ERROR: MQTT service not set up correctly. Check your pialert.conf MQTT_* variables.'])
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@@ -135,23 +134,38 @@ class sensor_config:
|
|||||||
def publish_mqtt(mqtt_client, topic, message):
|
def publish_mqtt(mqtt_client, topic, message):
|
||||||
status = 1
|
status = 1
|
||||||
|
|
||||||
|
message = json.dumps(message).replace("'",'"')
|
||||||
|
qos = get_setting_value('MQTT_QOS')
|
||||||
|
|
||||||
mylog('verbose', [f"[{pluginName}] Sending MQTT topic: {topic}"])
|
mylog('verbose', [f"[{pluginName}] Sending MQTT topic: {topic}"])
|
||||||
mylog('verbose', [f"[{pluginName}] Sending MQTT message: {message}"])
|
mylog('verbose', [f"[{pluginName}] Sending MQTT message: {message}"])
|
||||||
|
# mylog('verbose', [f"[{pluginName}] get_setting_value('MQTT_QOS'): {qos}"])
|
||||||
|
|
||||||
|
if mqtt_connected_to_broker == False:
|
||||||
|
|
||||||
|
mylog('verbose', [f"[{pluginName}] ⚠ ERROR: Not connected to broker, aborting."])
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
while status != 0:
|
while status != 0:
|
||||||
|
|
||||||
|
# mylog('verbose', [f"[{pluginName}] mqtt_client.publish "])
|
||||||
|
# mylog('verbose', [f"[{pluginName}] mqtt_client.is_connected(): {mqtt_client.is_connected()} "])
|
||||||
|
|
||||||
result = mqtt_client.publish(
|
result = mqtt_client.publish(
|
||||||
topic=topic,
|
topic=topic,
|
||||||
payload=message,
|
payload=message,
|
||||||
qos=get_setting_value('MQTT_QOS'),
|
qos=qos,
|
||||||
retain=True,
|
retain=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
status = result[0]
|
status = result[0]
|
||||||
|
|
||||||
|
# mylog('verbose', [f"[{pluginName}] status: {status}"])
|
||||||
|
# mylog('verbose', [f"[{pluginName}] result: {result}"])
|
||||||
|
|
||||||
if status != 0:
|
if status != 0:
|
||||||
mylog('minimal', [f"[{pluginName}] Waiting to reconnect to MQTT broker"])
|
mylog('verbose', [f"[{pluginName}] Waiting to reconnect to MQTT broker"])
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -179,7 +193,7 @@ def create_sensor(mqtt_client, deviceId, deviceName, sensorType, sensorName, ico
|
|||||||
|
|
||||||
# save if new
|
# save if new
|
||||||
if new_sensor_config.isNew:
|
if new_sensor_config.isNew:
|
||||||
mylog('minimal', [f"[{pluginName}] Publishing sensor number {len(mqtt_sensors)}"])
|
mylog('verbose', [f"[{pluginName}] Publishing sensor number {len(mqtt_sensors)}"])
|
||||||
publish_sensor(mqtt_client, new_sensor_config)
|
publish_sensor(mqtt_client, new_sensor_config)
|
||||||
|
|
||||||
|
|
||||||
@@ -190,19 +204,19 @@ def publish_sensor(mqtt_client, sensorConfig):
|
|||||||
|
|
||||||
global mqtt_sensors
|
global mqtt_sensors
|
||||||
|
|
||||||
message = '{ \
|
message = {
|
||||||
"name":"'+sensorConfig.sensorName+'", \
|
"name" : sensorConfig.sensorName,
|
||||||
"state_topic":"system-sensors/'+sensorConfig.sensorType+'/'+sensorConfig.deviceId+'/state", \
|
"state_topic" : "system-sensors/"+sensorConfig.sensorType+'/'+sensorConfig.deviceId+"/state",
|
||||||
"value_template":"{{value_json.'+sensorConfig.sensorName+'}}", \
|
"value_template" : "{{value_json."+sensorConfig.sensorName+"}}",
|
||||||
"unique_id":"'+sensorConfig.deviceId+'_sensor_'+sensorConfig.sensorName+'", \
|
"unique_id" : sensorConfig.deviceId+'_sensor_'+sensorConfig.sensorName,
|
||||||
"device": \
|
"device":
|
||||||
{ \
|
{
|
||||||
"identifiers": ["'+sensorConfig.deviceId+'_sensor"], \
|
"identifiers" : [sensorConfig.deviceId+"_sensor"],
|
||||||
"manufacturer": "PiAlert", \
|
"manufacturer" : "PiAlert",
|
||||||
"name":"'+sensorConfig.deviceName+'" \
|
"name" : sensorConfig.deviceName
|
||||||
}, \
|
},
|
||||||
"icon":"mdi:'+sensorConfig.icon+'" \
|
"icon":"mdi:'+sensorConfig.icon+'"
|
||||||
}'
|
}
|
||||||
|
|
||||||
topic='homeassistant/'+sensorConfig.sensorType+'/'+sensorConfig.deviceId+'/'+sensorConfig.sensorName+'/config'
|
topic='homeassistant/'+sensorConfig.sensorType+'/'+sensorConfig.deviceId+'/'+sensorConfig.sensorName+'/config'
|
||||||
|
|
||||||
@@ -232,13 +246,18 @@ def mqtt_create_client():
|
|||||||
mylog('verbose', [f"[{pluginName}] Connected to broker"])
|
mylog('verbose', [f"[{pluginName}] Connected to broker"])
|
||||||
mqtt_connected_to_broker = True # Signal connection
|
mqtt_connected_to_broker = True # Signal connection
|
||||||
else:
|
else:
|
||||||
mylog('none', [f"[{pluginName}] Connection failed, reason_code: {reason_code}"])
|
mylog('verbose', [f"[{pluginName}] Connection failed, reason_code: {reason_code}"])
|
||||||
mqtt_connected_to_broker = False
|
mqtt_connected_to_broker = False
|
||||||
|
|
||||||
|
|
||||||
global mqtt_client
|
global mqtt_client
|
||||||
|
|
||||||
|
if get_setting_value('MQTT_VERSION') == 1:
|
||||||
|
mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
|
||||||
|
else:
|
||||||
mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||||
|
|
||||||
|
|
||||||
mqtt_client.username_pw_set(get_setting_value('MQTT_USER'), get_setting_value('MQTT_PASSWORD'))
|
mqtt_client.username_pw_set(get_setting_value('MQTT_USER'), get_setting_value('MQTT_PASSWORD'))
|
||||||
mqtt_client.on_connect = on_connect
|
mqtt_client.on_connect = on_connect
|
||||||
mqtt_client.on_disconnect = on_disconnect
|
mqtt_client.on_disconnect = on_disconnect
|
||||||
@@ -266,19 +285,16 @@ def mqtt_start(db):
|
|||||||
# Get the data
|
# Get the data
|
||||||
row = get_device_stats(db)
|
row = get_device_stats(db)
|
||||||
|
|
||||||
columns = ["online","down","all","archived","new","unknown"]
|
|
||||||
|
|
||||||
payload = ""
|
|
||||||
|
|
||||||
# Update the values
|
|
||||||
for column in columns:
|
|
||||||
payload += '"'+column+'": ' + str(row[column]) +','
|
|
||||||
|
|
||||||
# Publish (wrap into {} and remove last ',' from above)
|
# Publish (wrap into {} and remove last ',' from above)
|
||||||
publish_mqtt(mqtt_client, "system-sensors/sensor/pialert/state",
|
publish_mqtt(mqtt_client, "system-sensors/sensor/pialert/state",
|
||||||
'{ \
|
{
|
||||||
'+ payload[:-1] +'\
|
"online": row[0],
|
||||||
}'
|
"down": row[1],
|
||||||
|
"all": row[2],
|
||||||
|
"archived": row[3],
|
||||||
|
"new": row[4],
|
||||||
|
"unknown": row[5]
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate device-specific MQTT messages if enabled
|
# Generate device-specific MQTT messages if enabled
|
||||||
@@ -291,12 +307,12 @@ def mqtt_start(db):
|
|||||||
|
|
||||||
sec_delay = len(devices) * int(get_setting_value('MQTT_DELAY_SEC'))*5
|
sec_delay = len(devices) * int(get_setting_value('MQTT_DELAY_SEC'))*5
|
||||||
|
|
||||||
mylog('minimal', [f"[{pluginName}] Estimated delay: ", (sec_delay), 's ', '(', round(sec_delay/60,1) , 'min)' ])
|
mylog('verbose', [f"[{pluginName}] Estimated delay: ", (sec_delay), 's ', '(', round(sec_delay/60,1) , 'min)' ])
|
||||||
|
|
||||||
|
# debug_index = 0
|
||||||
|
|
||||||
for device in devices:
|
for device in devices:
|
||||||
|
|
||||||
|
|
||||||
# Create devices in Home Assistant - send config messages
|
# Create devices in Home Assistant - send config messages
|
||||||
deviceId = 'mac_' + device["dev_MAC"].replace(" ", "").replace(":", "_").lower()
|
deviceId = 'mac_' + device["dev_MAC"].replace(" ", "").replace(":", "_").lower()
|
||||||
deviceNameDisplay = re.sub('[^a-zA-Z0-9-_\s]', '', device["dev_Name"])
|
deviceNameDisplay = re.sub('[^a-zA-Z0-9-_\s]', '', device["dev_Name"])
|
||||||
@@ -310,18 +326,18 @@ def mqtt_start(db):
|
|||||||
# update device sensors in home assistant
|
# update device sensors in home assistant
|
||||||
|
|
||||||
publish_mqtt(mqtt_client, 'system-sensors/sensor/'+deviceId+'/state',
|
publish_mqtt(mqtt_client, 'system-sensors/sensor/'+deviceId+'/state',
|
||||||
'{ \
|
{
|
||||||
"last_ip": "' + device["dev_LastIP"] +'", \
|
"last_ip": device["dev_LastIP"],
|
||||||
"is_new": "' + str(device["dev_NewDevice"]) +'", \
|
"is_new": str(device["dev_NewDevice"]),
|
||||||
"vendor": "' + sanitize_string(device["dev_Vendor"]) +'", \
|
"vendor": sanitize_string(device["dev_Vendor"]),
|
||||||
"mac_address": "' + str(device["dev_MAC"]) +'" \
|
"mac_address": str(device["dev_MAC"])
|
||||||
}'
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
publish_mqtt(mqtt_client, 'system-sensors/binary_sensor/'+deviceId+'/state',
|
publish_mqtt(mqtt_client, 'system-sensors/binary_sensor/'+deviceId+'/state',
|
||||||
'{ \
|
{
|
||||||
"is_present": "' + to_binary_sensor(str(device["dev_PresentLastScan"])) +'"\
|
"is_present": to_binary_sensor(str(device["dev_PresentLastScan"]))
|
||||||
}'
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# delete device / topic
|
# delete device / topic
|
||||||
|
|||||||
@@ -98,35 +98,35 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
|||||||
|
|
||||||
<div class="content settingswrap " id="accordion_gen">
|
<div class="content settingswrap " id="accordion_gen">
|
||||||
|
|
||||||
<div class ="bg-grey-dark color-palette box panel panel-default col-sm-12 box-default box-info" >
|
<div class ="bg-grey-dark color-palette box panel panel-default col-sm-12 box-default box-info" id="core_content_header" >
|
||||||
<div class ="settings-group col-sm-12">
|
<div class ="settings-group col-sm-12">
|
||||||
<i class="<?= lang("settings_core_icon");?>"></i> <?= lang("settings_core_label");?>
|
<i class="<?= lang("settings_core_icon");?>"></i> <?= lang("settings_core_label");?>
|
||||||
</div>
|
</div>
|
||||||
<div class =" col-sm-12" id="core_content"></div>
|
<div class =" col-sm-12" id="core_content"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class ="bg-grey-dark color-palette box panel panel-default col-sm-12 box-default box-info" >
|
<div class ="bg-grey-dark color-palette box panel panel-default col-sm-12 box-default box-info" id="system_content_header" >
|
||||||
<div class ="settings-group col-sm-12">
|
<div class ="settings-group col-sm-12">
|
||||||
<i class="<?= lang("settings_system_icon");?>"></i> <?= lang("settings_system_label");?>
|
<i class="<?= lang("settings_system_icon");?>"></i> <?= lang("settings_system_label");?>
|
||||||
</div>
|
</div>
|
||||||
<div class =" col-sm-12" id="system_content"></div>
|
<div class =" col-sm-12" id="system_content"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class ="bg-grey-dark color-palette box panel panel-default col-sm-12 box-default box-info" >
|
<div class ="bg-grey-dark color-palette box panel panel-default col-sm-12 box-default box-info" id="device_scanner_content_header" >
|
||||||
<div class ="settings-group col-sm-12">
|
<div class ="settings-group col-sm-12">
|
||||||
<i class="<?= lang("settings_device_scanners_icon");?>"></i> <?= lang("settings_device_scanners_label");?>
|
<i class="<?= lang("settings_device_scanners_icon");?>"></i> <?= lang("settings_device_scanners_label");?>
|
||||||
</div>
|
</div>
|
||||||
<div class =" col-sm-12" id="device_scanner_content"></div>
|
<div class =" col-sm-12" id="device_scanner_content"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class ="bg-grey-dark color-palette box panel panel-default col-sm-12 box-default box-info" >
|
<div class ="bg-grey-dark color-palette box panel panel-default col-sm-12 box-default box-info" id="other_content_header">
|
||||||
<div class ="settings-group col-sm-12">
|
<div class ="settings-group col-sm-12">
|
||||||
<i class="<?= lang("settings_other_scanners_icon");?>"></i> <?= lang("settings_other_scanners_label");?>
|
<i class="<?= lang("settings_other_scanners_icon");?>"></i> <?= lang("settings_other_scanners_label");?>
|
||||||
</div>
|
</div>
|
||||||
<div class =" col-sm-12" id="other_content"></div>
|
<div class =" col-sm-12" id="other_content"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class ="bg-grey-dark color-palette box panel panel-default col-sm-12 box-default box-info" >
|
<div class ="bg-grey-dark color-palette box panel panel-default col-sm-12 box-default box-info" id="publisher_content_header" >
|
||||||
<div class ="settings-group col-sm-12">
|
<div class ="settings-group col-sm-12">
|
||||||
<i class="<?= lang("settings_publishers_icon");?>"></i> <?= lang("settings_publishers_label");?>
|
<i class="<?= lang("settings_publishers_icon");?>"></i> <?= lang("settings_publishers_label");?>
|
||||||
</div>
|
</div>
|
||||||
@@ -757,6 +757,22 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
|||||||
|
|
||||||
document.getElementById('lastImportedTime').innerHTML = humanReadable;
|
document.getElementById('lastImportedTime').innerHTML = humanReadable;
|
||||||
|
|
||||||
|
// Scroll down if ID in URL
|
||||||
|
// Get the ID from the URL
|
||||||
|
var url = window.location.href;
|
||||||
|
var id = url.substring(url.indexOf("#") + 1);
|
||||||
|
|
||||||
|
// Check if the ID exists in the document
|
||||||
|
if ($("#" + id).length > 0) {
|
||||||
|
setTimeout(function() {
|
||||||
|
// Scroll to the element
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: $("#" + id).offset().top - 50
|
||||||
|
}, 1000);
|
||||||
|
},200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,17 +96,17 @@ $total_memorymb = number_format($total_memorymb, 0, '.', '.');
|
|||||||
$mem_used = round(memory_get_usage() / 1048576 * 100, 2);
|
$mem_used = round(memory_get_usage() / 1048576 * 100, 2);
|
||||||
$memory_usage_percent = round(($mem_used / $total_memorymb), 2);
|
$memory_usage_percent = round(($mem_used / $total_memorymb), 2);
|
||||||
//HDD stats
|
//HDD stats
|
||||||
$hdd_result = shell_exec("df | awk '{print $1}'");
|
$hdd_result = shell_exec(" df -P | awk '{print $1}'");
|
||||||
$hdd_devices = explode("\n", trim($hdd_result));
|
$hdd_devices = explode("\n", trim($hdd_result));
|
||||||
$hdd_result = shell_exec("df | awk '{print $2}'");
|
$hdd_result = shell_exec(" df -P | awk '{print $2}'");
|
||||||
$hdd_devices_total = explode("\n", trim($hdd_result));
|
$hdd_devices_total = explode("\n", trim($hdd_result));
|
||||||
$hdd_result = shell_exec("df | awk '{print $3}'");
|
$hdd_result = shell_exec(" df -P | awk '{print $3}'");
|
||||||
$hdd_devices_used = explode("\n", trim($hdd_result));
|
$hdd_devices_used = explode("\n", trim($hdd_result));
|
||||||
$hdd_result = shell_exec("df | awk '{print $4}'");
|
$hdd_result = shell_exec(" df -P | awk '{print $4}'");
|
||||||
$hdd_devices_free = explode("\n", trim($hdd_result));
|
$hdd_devices_free = explode("\n", trim($hdd_result));
|
||||||
$hdd_result = shell_exec("df | awk '{print $5}'");
|
$hdd_result = shell_exec(" df -P | awk '{print $5}'");
|
||||||
$hdd_devices_percent = explode("\n", trim($hdd_result));
|
$hdd_devices_percent = explode("\n", trim($hdd_result));
|
||||||
$hdd_result = shell_exec("df | awk '{print $6}'");
|
$hdd_result = shell_exec(" df -P | awk '{print $6}'");
|
||||||
$hdd_devices_mount = explode("\n", trim($hdd_result));
|
$hdd_devices_mount = explode("\n", trim($hdd_result));
|
||||||
//Network stats
|
//Network stats
|
||||||
// Check Server name
|
// Check Server name
|
||||||
|
|||||||
Reference in New Issue
Block a user