mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Scheduler, Systeminfo.php, Plugin obj insertion fixes
This commit is contained in:
0
docs/SETTINGS_SYSTEM.md
Normal file → Executable file
0
docs/SETTINGS_SYSTEM.md
Normal file → Executable file
0
front/php/templates/build.php
Normal file → Executable file
0
front/php/templates/build.php
Normal file → Executable file
@@ -271,6 +271,7 @@
|
||||
"Maintenance_lang_es_es" : "Spanish (ES)",
|
||||
"Maintenance_lang_selector_text" : "The change takes place on the client side, so it affects only the current browser.",
|
||||
"Maintenance_lang_selector_apply" : "Apply",
|
||||
"Maintenance_Status" : "Status",
|
||||
"Maintenance_Tools_Tab_Settings" : "Settings",
|
||||
"Maintenance_Tools_Tab_UISettings" : "UI Settings",
|
||||
"Maintenance_Tools_Tab_Tools" : "Tools",
|
||||
|
||||
0
front/php/templates/version.php
Normal file → Executable file
0
front/php/templates/version.php
Normal file → Executable file
0
front/report.php
Normal file → Executable file
0
front/report.php
Normal file → Executable file
2
front/systeminfo.php
Normal file → Executable file
2
front/systeminfo.php
Normal file → Executable file
@@ -371,7 +371,7 @@ for ($x = 0; $x < sizeof($hdd_devices); $x++) {
|
||||
echo '<div class="row">';
|
||||
echo '<div class="col-sm-4 sysinfo_storage_usage_a">"' . lang('Systeminfo_Storage_Usage_Mount') . ' ' . $hdd_devices_mount[$x] . '"</div>';
|
||||
echo '<div class="col-sm-2 sysinfo_storage_usage_b">' . lang('Systeminfo_Storage_Usage_Total') . ' ' . $temp_total . ' GB</div>';
|
||||
echo '<div class="col-sm-3 sysinfo_storage_usage_b">' . lang('Systeminfo_Storage_Usage_Used') . ' ' . $temp_used . ' GB (' . number_format($hdd_devices_percent[$x], 1, ',', '.') . '%)</div>';
|
||||
echo '<div class="col-sm-3 sysinfo_storage_usage_b">' . lang('Systeminfo_Storage_Usage_Used') . ' ' . $temp_used . ' GB (' . $hdd_devices_percent[$x]. ')</div>';
|
||||
echo '<div class="col-sm-2 sysinfo_storage_usage_b">' . lang('Systeminfo_Storage_Usage_Free') . ' ' . $temp_free . ' GB</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
@@ -223,10 +223,6 @@ def execute_plugin(db, plugin, pluginsState = plugins_state() ):
|
||||
# cleanup - select only lines containing a separator to filter out unnecessary data
|
||||
newLines = list(filter(lambda x: '|' in x, newLines))
|
||||
|
||||
# # regular logging
|
||||
# for line in newLines:
|
||||
# append_line_to_file (pluginsPath + '/plugin.log', line +'\n')
|
||||
|
||||
for line in newLines:
|
||||
columns = line.split("|")
|
||||
# There has to be always 9 columns
|
||||
@@ -521,36 +517,69 @@ def process_plugin_events(db, plugin, pluginsState):
|
||||
# Update the DB
|
||||
# ----------------------------
|
||||
# Update the Plugin_Objects
|
||||
# Create lists to hold the data for bulk insertion
|
||||
objects_to_insert = []
|
||||
events_to_insert = []
|
||||
|
||||
for plugObj in pluginObjects:
|
||||
|
||||
createdTime = plugObj.created
|
||||
createdTime = plugObj.changed if plugObj.status == 'new' else plugObj.created
|
||||
values = (
|
||||
plugObj.pluginPref, plugObj.primaryId, plugObj.secondaryId, createdTime,
|
||||
plugObj.changed, plugObj.watched1, plugObj.watched2, plugObj.watched3,
|
||||
plugObj.watched4, plugObj.status, plugObj.extra, plugObj.userData,
|
||||
plugObj.foreignKey
|
||||
)
|
||||
|
||||
if plugObj.status == 'new':
|
||||
|
||||
createdTime = plugObj.changed
|
||||
|
||||
sql.execute ("INSERT INTO Plugins_Objects (Plugin, Object_PrimaryID, Object_SecondaryID, DateTimeCreated, DateTimeChanged, Watched_Value1, Watched_Value2, Watched_Value3, Watched_Value4, Status, Extra, UserData, ForeignKey) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", (plugObj.pluginPref, plugObj.primaryId , plugObj.secondaryId , createdTime, plugObj.changed , plugObj.watched1 , plugObj.watched2 , plugObj.watched3 , plugObj.watched4 , plugObj.status , plugObj.extra, plugObj.userData, plugObj.foreignKey ))
|
||||
objects_to_insert.append(values)
|
||||
else:
|
||||
sql.execute ("UPDATE Plugins_Objects set Plugin = ?, DateTimeChanged = ?, Watched_Value1 = ?, Watched_Value2 = ?, Watched_Value3 = ?, Watched_Value4 = ?, Status = ?, Extra = ?, ForeignKey = ? WHERE \"Index\" = ?", (plugObj.pluginPref, plugObj.changed, plugObj.watched1, plugObj.watched2, plugObj.watched3, plugObj.watched4, plugObj.status, plugObj.extra, plugObj.foreignKey, plugObj.index))
|
||||
objects_to_insert.append(values + (plugObj.index,)) # Include index for UPDATE
|
||||
|
||||
# Update the Plugins_Events with the new statuses
|
||||
sql.execute ('DELETE FROM Plugins_Events where Plugin = ?', (pluginPref,))
|
||||
|
||||
for plugObj in pluginEvents:
|
||||
|
||||
createdTime = plugObj.created
|
||||
|
||||
# use the same datetime for created and changed if a new entry
|
||||
if plugObj.status == 'new':
|
||||
createdTime = plugObj.changed
|
||||
events_to_insert.append(values)
|
||||
elif plugObj.status in get_plugin_setting_value(plugin, "REPORT_ON"):
|
||||
events_to_insert.append(values)
|
||||
|
||||
# insert only events if they are to be reported on
|
||||
if plugObj.status in get_plugin_setting_value(plugin, "REPORT_ON"):
|
||||
# Bulk insert/update objects
|
||||
if objects_to_insert:
|
||||
sql.executemany(
|
||||
"""
|
||||
INSERT INTO Plugins_Objects
|
||||
("Plugin", "Object_PrimaryID", "Object_SecondaryID", "DateTimeCreated",
|
||||
"DateTimeChanged", "Watched_Value1", "Watched_Value2", "Watched_Value3",
|
||||
"Watched_Value4", "Status", "Extra", "UserData", "ForeignKey", "Index")
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT("Index") DO UPDATE
|
||||
SET "Plugin" = excluded.Plugin,
|
||||
"DateTimeChanged" = excluded.DateTimeChanged,
|
||||
"Watched_Value1" = excluded.Watched_Value1,
|
||||
"Watched_Value2" = excluded.Watched_Value2,
|
||||
"Watched_Value3" = excluded.Watched_Value3,
|
||||
"Watched_Value4" = excluded.Watched_Value4,
|
||||
"Status" = excluded.Status,
|
||||
"Extra" = excluded.Extra,
|
||||
"ForeignKey" = excluded.ForeignKey
|
||||
""", objects_to_insert
|
||||
)
|
||||
|
||||
sql.execute ("INSERT INTO Plugins_Events (Plugin, Object_PrimaryID, Object_SecondaryID, DateTimeCreated, DateTimeChanged, Watched_Value1, Watched_Value2, Watched_Value3, Watched_Value4, Status, Extra, UserData, ForeignKey) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", (plugObj.pluginPref, plugObj.primaryId , plugObj.secondaryId , createdTime, plugObj.changed , plugObj.watched1 , plugObj.watched2 , plugObj.watched3 , plugObj.watched4 , plugObj.status , plugObj.extra, plugObj.userData, plugObj.foreignKey ))
|
||||
# Bulk insert events
|
||||
if events_to_insert:
|
||||
sql.executemany(
|
||||
"""
|
||||
INSERT INTO Plugins_Events
|
||||
("Plugin", "Object_PrimaryID", "Object_SecondaryID", "DateTimeCreated",
|
||||
"DateTimeChanged", "Watched_Value1", "Watched_Value2", "Watched_Value3",
|
||||
"Watched_Value4", "Status", "Extra", "UserData", "ForeignKey")
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", events_to_insert
|
||||
)
|
||||
|
||||
# Delete old events
|
||||
sql.execute('DELETE FROM Plugins_Events where Plugin = ?', (pluginPref,))
|
||||
|
||||
# Commit changes to the database
|
||||
db.commitDB()
|
||||
|
||||
# Commit the transaction
|
||||
conn.commit()
|
||||
|
||||
except Exception as e:
|
||||
# Rollback the transaction in case of an error
|
||||
|
||||
@@ -28,15 +28,15 @@ class schedule_class:
|
||||
# (maybe the following check is unnecessary:)
|
||||
# if the last run is past the last time we run a scheduled Pholus scan
|
||||
# if nowTime > self.last_next_schedule and self.last_run < self.last_next_schedule:
|
||||
if nowTime > self.last_next_schedule and self.last_run < self.last_next_schedule:
|
||||
if nowTime > self.last_next_schedule:
|
||||
mylog('debug',f'[Scheduler] - Scheduler run for {self.service}: YES')
|
||||
self.was_last_schedule_used = True
|
||||
result = True
|
||||
else:
|
||||
mylog('debug',f'[Scheduler] - Scheduler run for {self.service}: NO')
|
||||
mylog('debug',f'[Scheduler] - nowTime {nowTime}')
|
||||
mylog('debug',f'[Scheduler] - self.last_next_schedule {self.last_next_schedule}')
|
||||
mylog('debug',f'[Scheduler] - self.last_run {self.last_run}')
|
||||
# mylog('debug',f'[Scheduler] - nowTime {nowTime}')
|
||||
# mylog('debug',f'[Scheduler] - self.last_next_schedule {self.last_next_schedule}')
|
||||
# mylog('debug',f'[Scheduler] - self.last_run {self.last_run}')
|
||||
|
||||
if self.was_last_schedule_used:
|
||||
self.was_last_schedule_used = False
|
||||
|
||||
Reference in New Issue
Block a user