mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-06 17:15:38 -08:00
💠down_reconnected support v0.6 #611
This commit is contained in:
@@ -60,7 +60,7 @@ Get visibility of what's going on on your WIFI/LAN network. Schedule scans for d
|
||||
|-------------|-------------|
|
||||
| 📥🐳 | [Docker instructions](https://github.com/jokob-sk/NetAlertX/blob/main/dockerfiles/README.md)
|
||||
| 📥💻 | [HW install (experimental 🧪)](https://github.com/jokob-sk/NetAlertX/blob/main/docs/HW_INSTALL.md) |
|
||||
| 📥🟧 | [Unraid App 🧪)](https://unraid.net/community/apps) |
|
||||
| 📥🟧 | [Unraid App](https://unraid.net/community/apps) |
|
||||
| 📚 | [All Documentation](https://github.com/jokob-sk/NetAlertX/blob/main/docs/README.md) (App Usage and Configuration) |
|
||||
|
||||
> Other Alternatives
|
||||
|
||||
@@ -254,13 +254,13 @@ function getString (key) {
|
||||
case 'Norwegian':
|
||||
lang_code = 'nb_no';
|
||||
break;
|
||||
case 'Polish':
|
||||
case 'Polish (pl_pl)':
|
||||
lang_code = 'pl_pl';
|
||||
break;
|
||||
case 'Portuguese (Brazil)':
|
||||
case 'Portuguese (pt_br)':
|
||||
lang_code = 'pt_br';
|
||||
break;
|
||||
case 'Italian':
|
||||
case 'Italian (it_it)':
|
||||
lang_code = 'it_it';
|
||||
break;
|
||||
case 'Russian':
|
||||
|
||||
@@ -10,13 +10,13 @@ $allLanguages = ["en_us","es_es","de_de", "nb_no", "pl_pl", "pt_br", "ru_ru", "f
|
||||
global $db;
|
||||
|
||||
$result = $db->querySingle("SELECT Value FROM Settings WHERE Code_Name = 'UI_LANG'");
|
||||
switch($result){
|
||||
switch($result){
|
||||
case 'Spanish': $pia_lang_selected = 'es_es'; break;
|
||||
case 'German': $pia_lang_selected = 'de_de'; break;
|
||||
case 'Norwegian': $pia_lang_selected = 'nb_no'; break;
|
||||
case 'Polish': $pia_lang_selected = 'pl_pl'; break;
|
||||
case 'Portuguese (Brazil)': $pia_lang_selected = 'pt_br'; break;
|
||||
case 'Italian': $pia_lang_selected = 'it_it'; break;
|
||||
case 'Polish (pl_pl)': $pia_lang_selected = 'pl_pl'; break;
|
||||
case 'Portuguese (pt_br)': $pia_lang_selected = 'pt_br'; break;
|
||||
case 'Italian (it_it)': $pia_lang_selected = 'it_it'; break;
|
||||
case 'Russian': $pia_lang_selected = 'ru_ru'; break;
|
||||
case 'French': $pia_lang_selected = 'fr_fr'; break;
|
||||
case 'Chinese (zh_cn)': $pia_lang_selected = 'zh_cn'; break;
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
{
|
||||
"function": "RUN_SCHD",
|
||||
"type": "text",
|
||||
"default_value":"0 2 * * 3",
|
||||
"default_value":"0 2 * * *",
|
||||
"options": [],
|
||||
"localized": ["name", "description"],
|
||||
"name" : [{
|
||||
|
||||
@@ -61,14 +61,14 @@
|
||||
<table width=100% bgcolor=#3c8dbc cellpadding=5px cellspacing=0 style="font-size: 13px; font-weight: bold; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px;">
|
||||
<tr>
|
||||
<td width=50% style="text-align:center;color: white;" bgcolor="#3c8dbc">
|
||||
<a href="https://github.com/jokob-sk/NetAlertX" target="_blank" style="color: white">NetAlertX</a>
|
||||
<a href=".." target="_blank" style="color: white"> (<SERVER_NAME>)</a>
|
||||
<br><span style="display:inline-block;color: white; transform: rotate(180deg)">©</span>2020 Puche (2022+
|
||||
<a style="color: white" href="mailto:jokob@duck.com?subject=NetAlertX">jokob-sk</a>) | <b>Built on: <BUILD_DATE> </b> | <b> Version: <BUILD_VERSION> </b> |
|
||||
<a href="https://github.com/jokob-sk/NetAlertX/tree/main/docs" target="_blank" style="color: white">
|
||||
<span>Docs <i class="fa fa-circle-question"></i>
|
||||
</a><span>
|
||||
</td>
|
||||
<a href="https://github.com/jokob-sk/NetAlertX" target="_blank" style="color: white">NetAlertX</a>
|
||||
<a href=".." target="_blank" style="color: white"> (<SERVER_NAME>)</a>
|
||||
<br><span style="display:inline-block;color: white; transform: rotate(180deg)">©</span>2022
|
||||
<a style="color: white" href="mailto:jokob@duck.com?subject=NetAlertX">jokob-sk</a> | <b>Built on: <BUILD_DATE> </b> | <b> Version: <BUILD_VERSION> </b> |
|
||||
<a href="https://github.com/jokob-sk/NetAlertX/tree/main/docs" target="_blank" style="color: white">
|
||||
<span>Docs <i class="fa fa-circle-question"></i>
|
||||
</a><span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
|
||||
@@ -67,8 +67,8 @@
|
||||
<td width=50% style="text-align:center;color: white;" bgcolor="#3c8dbc">
|
||||
<a href="https://github.com/jokob-sk/NetAlertX" target="_blank" style="color: white">NetAlertX</a>
|
||||
<a href=".." target="_blank" style="color: white"> (<SERVER_NAME>)</a>
|
||||
<br><span style="display:inline-block;color: white; transform: rotate(180deg)">©</span>2020 Puche (2022+
|
||||
<a style="color: white" href="mailto:jokob@duck.com?subject=NetAlertX">jokob-sk</a>) | <b>Built on: <BUILD_DATE> </b> | <b> Version: <BUILD_VERSION> </b> |
|
||||
<br><span style="display:inline-block;color: white; transform: rotate(180deg)">©</span>2022
|
||||
<a style="color: white" href="mailto:jokob@duck.com?subject=NetAlertX">jokob-sk</a> | <b>Built on: <BUILD_DATE> </b> | <b> Version: <BUILD_VERSION> </b> |
|
||||
<a href="https://github.com/jokob-sk/NetAlertX/tree/main/docs" target="_blank" style="color: white">
|
||||
<span>Docs <i class="fa fa-circle-question"></i>
|
||||
</a><span>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"title_link": "",
|
||||
"text": {
|
||||
"new_devices_meta": {
|
||||
"title": "New devices",
|
||||
"title": "🆕New devices",
|
||||
"columnNames": [
|
||||
"MAC",
|
||||
"Datetime",
|
||||
@@ -62,6 +62,27 @@
|
||||
"Comments"
|
||||
]
|
||||
},
|
||||
"down_reconnected": [
|
||||
{
|
||||
"dev_Name": "Phone - Pixel",
|
||||
"eve_MAC": "74:ac:74:ac:74:ac",
|
||||
"dev_Vendor": "Google",
|
||||
"eve_IP": "192.168.1.167",
|
||||
"DownTime": "2024-05-26 09:06:56+10:00",
|
||||
"ConnectedTime": "2024-05-26 09:13:24+10:00"
|
||||
}
|
||||
],
|
||||
"down_reconnected_meta": {
|
||||
"title": "🔁 Reconnected down devices",
|
||||
"columnNames": [
|
||||
"dev_Name",
|
||||
"eve_MAC",
|
||||
"dev_Vendor",
|
||||
"eve_IP",
|
||||
"DownTime",
|
||||
"ConnectedTime"
|
||||
]
|
||||
},
|
||||
"events": [
|
||||
{
|
||||
"MAC": "74:ac:74:ac:74:ac",
|
||||
|
||||
@@ -168,7 +168,8 @@ def main ():
|
||||
notificationObj = notification.create(final_json, "")
|
||||
|
||||
# run all enabled publisher gateways
|
||||
if notificationObj.HasNotifications:
|
||||
if notificationObj.HasNotifications:
|
||||
|
||||
pluginsState = run_plugin_scripts(db, all_plugins, 'on_notification', pluginsState)
|
||||
notification.setAllProcessed()
|
||||
notification.clearPendingEmailFlag()
|
||||
|
||||
@@ -381,10 +381,12 @@ class DB():
|
||||
|
||||
self.commitDB()
|
||||
|
||||
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# CurrentScan table setup
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
|
||||
# indicates, if CurrentScan table is available
|
||||
self.sql.execute("DROP TABLE IF EXISTS CurrentScan;")
|
||||
self.sql.execute(""" CREATE TABLE CurrentScan (
|
||||
@@ -398,6 +400,33 @@ class DB():
|
||||
);
|
||||
""")
|
||||
|
||||
self.commitDB()
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Create the LatestEventsPerMAC view
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
# Dynamically generated language strings
|
||||
self.sql.execute(""" CREATE VIEW IF NOT EXISTS LatestEventsPerMAC AS
|
||||
WITH RankedEvents AS (
|
||||
SELECT
|
||||
e.*,
|
||||
ROW_NUMBER() OVER (PARTITION BY e.eve_MAC ORDER BY e.eve_DateTime DESC) AS row_num
|
||||
FROM Events AS e
|
||||
)
|
||||
SELECT
|
||||
e.*,
|
||||
d.*,
|
||||
c.*
|
||||
FROM RankedEvents AS e
|
||||
LEFT JOIN Devices AS d ON e.eve_MAC = d.dev_MAC
|
||||
INNER JOIN CurrentScan AS c ON e.eve_MAC = c.cur_MAC
|
||||
WHERE e.row_num = 1;
|
||||
""")
|
||||
|
||||
self.commitDB()
|
||||
|
||||
|
||||
# Init the AppEvent database table
|
||||
AppEvent_obj(self)
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ def importConfigs (db, all_plugins):
|
||||
conf.TIMEZONE = ccd('TIMEZONE', 'Europe/Berlin' , c_d, 'Time zone', 'text', '', 'General')
|
||||
conf.PLUGINS_KEEP_HIST = ccd('PLUGINS_KEEP_HIST', 250 , c_d, 'Keep history entries', 'integer', '', 'General')
|
||||
conf.REPORT_DASHBOARD_URL = ccd('REPORT_DASHBOARD_URL', 'http://netalertx/' , c_d, 'NetAlertX URL', 'text', '', 'General')
|
||||
conf.UI_LANG = ccd('UI_LANG', 'English' , c_d, 'Language Interface', 'text.select', "['English', 'French', 'German', 'Norwegian', 'Russian', 'Spanish', 'Italian', 'Portuguese (Brazil)', 'Polish', 'Chinese (zh_cn)' ]", 'General')
|
||||
conf.UI_LANG = ccd('UI_LANG', 'English' , c_d, 'Language Interface', 'text.select', "['English', 'French', 'German', 'Norwegian', 'Russian', 'Spanish', 'Italian (it_it)', 'Portuguese (pt_br)', 'Polish (pl_pl)', 'Chinese (zh_cn)' ]", 'General')
|
||||
conf.UI_PRESENCE = ccd('UI_PRESENCE', ['online', 'offline', 'archived'] , c_d, 'Include in presence', 'text.multiselect', "['online', 'offline', 'archived']", 'General')
|
||||
conf.UI_DEV_SECTIONS = ccd('UI_DEV_SECTIONS', [] , c_d, 'Show sections', 'text.multiselect', "['Tile Cards', 'Device Presence']", 'General')
|
||||
conf.UI_MY_DEVICES = ccd('UI_MY_DEVICES', ['online', 'offline', 'archived', 'new', 'down'] , c_d, 'Include in My Devices', 'text.multiselect', "['online', 'offline', 'archived', 'new', 'down']", 'General')
|
||||
|
||||
@@ -75,7 +75,7 @@ def void_ghost_disconnections (db):
|
||||
sql.execute("""UPDATE Events SET eve_PairEventRowid = Null,
|
||||
eve_EventType ='VOIDED - ' || eve_EventType
|
||||
WHERE eve_MAC != 'Internet'
|
||||
AND eve_EventType = 'Connected'
|
||||
AND eve_EventType in ('Connected', 'Down Reconnected')
|
||||
AND eve_DateTime = ?
|
||||
AND eve_MAC IN (
|
||||
SELECT Events.eve_MAC
|
||||
@@ -131,12 +131,12 @@ def pair_sessions_events (db):
|
||||
SET eve_PairEventRowid =
|
||||
(SELECT ROWID
|
||||
FROM Events AS EVE2
|
||||
WHERE EVE2.eve_EventType IN ('New Device', 'Connected',
|
||||
WHERE EVE2.eve_EventType IN ('New Device', 'Connected', 'Down Reconnected',
|
||||
'Device Down', 'Disconnected')
|
||||
AND EVE2.eve_MAC = Events.eve_MAC
|
||||
AND EVE2.eve_Datetime > Events.eve_DateTime
|
||||
ORDER BY EVE2.eve_DateTime ASC LIMIT 1)
|
||||
WHERE eve_EventType IN ('New Device', 'Connected')
|
||||
WHERE eve_EventType IN ('New Device', 'Connected', 'Down Reconnected')
|
||||
AND eve_PairEventRowid IS NULL
|
||||
""" )
|
||||
|
||||
@@ -189,15 +189,23 @@ def insert_events (db):
|
||||
WHERE dev_MAC = cur_MAC
|
||||
) """)
|
||||
|
||||
# Check new connections
|
||||
# Check new Connections or Down Reconnections
|
||||
mylog('debug','[Events] - 2 - New Connections')
|
||||
sql.execute (f"""INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime,
|
||||
eve_EventType, eve_AdditionalInfo,
|
||||
eve_PendingAlertEmail)
|
||||
SELECT cur_MAC, cur_IP, '{startTime}', 'Connected', '', dev_AlertEvents
|
||||
FROM Devices, CurrentScan
|
||||
WHERE dev_MAC = cur_MAC
|
||||
AND dev_PresentLastScan = 0 """)
|
||||
sql.execute (f""" INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime,
|
||||
eve_EventType, eve_AdditionalInfo,
|
||||
eve_PendingAlertEmail)
|
||||
SELECT DISTINCT c.cur_MAC, c.cur_IP, '{startTime}',
|
||||
CASE
|
||||
WHEN last_event.eve_EventType = 'Device Down' and last_event.eve_PendingAlertEmail = 0 THEN 'Down Reconnected'
|
||||
ELSE 'Connected'
|
||||
END,
|
||||
'',
|
||||
d.dev_AlertEvents
|
||||
FROM LatestEventsPerMAC AS d
|
||||
JOIN CurrentScan AS c ON d.dev_MAC = c.cur_MAC
|
||||
LEFT JOIN LatestEventsPerMAC AS last_event ON d.dev_MAC = last_event.eve_MAC
|
||||
WHERE d.dev_PresentLastScan = 0
|
||||
""")
|
||||
|
||||
# Check disconnections
|
||||
mylog('debug','[Events] - 3 - Disconnections')
|
||||
|
||||
@@ -255,20 +255,6 @@ class Notification_obj:
|
||||
AND eve_DateTime < datetime('now', '-{get_setting_value('NTFPRCS_alert_down_time')} minutes', '{get_timezone_offset()}')
|
||||
""")
|
||||
|
||||
# Clear the pending email flag for reconnected devices
|
||||
self.db.sql.execute(f"""UPDATE Events_Devices
|
||||
SET eve_PendingAlertEmail = 0
|
||||
WHERE eve_MAC IN (
|
||||
SELECT down_events.eve_MAC
|
||||
FROM Events_Devices AS down_events
|
||||
INNER JOIN Events AS connected_events
|
||||
ON connected_events.eve_MAC = down_events.eve_MAC
|
||||
WHERE down_events.eve_EventType = 'Device Down'
|
||||
AND connected_events.eve_EventType = 'Connected'
|
||||
AND connected_events.eve_DateTime > down_events.eve_DateTime
|
||||
)
|
||||
AND eve_EventType = 'Device Down'
|
||||
""")
|
||||
|
||||
# clear plugin events
|
||||
self.db.sql.execute ("DELETE FROM Plugins_Events")
|
||||
|
||||
@@ -112,16 +112,11 @@ def get_notifications (db):
|
||||
# Compose Reconnected Down Section
|
||||
# - select only Devices, that were previously down and now are Connected
|
||||
sqlQuery = f"""
|
||||
SELECT down_events.dev_Name, down_events.eve_MAC, down_events.dev_Vendor, down_events.eve_IP,
|
||||
down_events.eve_DateTime AS DownTime, connected_events.eve_DateTime AS ConnectedTime
|
||||
FROM Events_Devices AS down_events
|
||||
INNER JOIN Events AS connected_events
|
||||
ON connected_events.eve_MAC = down_events.eve_MAC
|
||||
WHERE down_events.eve_EventType = 'Device Down'
|
||||
AND connected_events.eve_EventType = 'Connected'
|
||||
AND connected_events.eve_DateTime > down_events.eve_DateTime
|
||||
AND down_events.eve_PendingAlertEmail = 1
|
||||
ORDER BY down_events.eve_DateTime;
|
||||
SELECT dev_Name, eve_MAC, dev_Vendor, eve_IP, eve_DateTime, eve_EventType
|
||||
FROM Events_Devices AS reconnected_devices
|
||||
WHERE reconnected_devices.eve_EventType = 'Down Reconnected'
|
||||
AND reconnected_devices.eve_PendingAlertEmail = 1
|
||||
ORDER BY reconnected_devices.eve_DateTime;
|
||||
"""
|
||||
|
||||
# Get the events as JSON
|
||||
@@ -137,8 +132,7 @@ def get_notifications (db):
|
||||
# Compose Events Section
|
||||
sqlQuery = f"""SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices
|
||||
WHERE eve_PendingAlertEmail = 1
|
||||
AND eve_EventType IN ('Connected','Disconnected',
|
||||
'IP Changed')
|
||||
AND eve_EventType IN ('Connected', 'Down Reconnected', 'Disconnected','IP Changed')
|
||||
{get_setting_value('NTFPRCS_event_condition').replace('{s-quote}',"'")}
|
||||
ORDER BY eve_DateTime"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user