🆕 Delete offline after N hours HRS_TO_KEEP_OFFDEV #865

This commit is contained in:
jokob-sk
2024-10-25 07:59:53 +11:00
parent 840413843b
commit c47ac62e9a
15 changed files with 40 additions and 4 deletions

View File

@@ -311,6 +311,8 @@
"General_icon": "",
"HRS_TO_KEEP_NEWDEV_description": "",
"HRS_TO_KEEP_NEWDEV_name": "",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "",
"HelpFAQ_Cat_Detail_300_head": "",
"HelpFAQ_Cat_Detail_300_text_a": "",

View File

@@ -311,6 +311,8 @@
"General_icon": "",
"HRS_TO_KEEP_NEWDEV_description": "",
"HRS_TO_KEEP_NEWDEV_name": "",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "",
"HelpFAQ_Cat_Detail_300_head": "",
"HelpFAQ_Cat_Detail_300_text_a": "",

View File

@@ -323,6 +323,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "Dies ist eine Wartungseinstellung <b>DELETING devices</b>. Wenn aktiviert (<code>0</code> bedeutet deaktiviert), werden als <b>\"Neues Gerät\"</b> markierte Geräte gelöscht, wenn ihre <b>erste Sitzung</b> länger her ist als in dieser Einstellung angegeben. Verwenden Sie diese Einstellung, wenn Sie <b>Neue Geräte</b> nach <code>X</code> Stunden automatisch löschen wollen.",
"HRS_TO_KEEP_NEWDEV_name": "Neue Geräte löschen nach",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "Detailansicht",
"HelpFAQ_Cat_Detail_300_head": "Was bedeutet ",
"HelpFAQ_Cat_Detail_300_text_a": "meint ein Netzwerkgerät (ein Gerät vom Typ AP, Gateway, Firewall, Hypervisor, Powerline, Switch, WLAN, PLC, Router, USB-LAN-Adapter oder Internet). Benutzerdefinierte Typen können über die <code>NETWORK_DEVICE_TYPES</code> Einstellung hinzugefügt werden.",

View File

@@ -311,6 +311,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "This is a maintenance setting <b>DELETING devices</b>. If enabled (<code>0</code> is disabled), devices marked as <b>New Device</b> will be deleted if their <b>First Session</b> time was older than the specified hours in this setting. Use this setting if you want to auto-delete <b>New Devices</b> after <code>X</code> hours.",
"HRS_TO_KEEP_NEWDEV_name": "Delete new devices after",
"HRS_TO_KEEP_OFFDEV_description": "This is a maintenance setting <b>DELETING devices</b>. If enabled (<code>0</code> is disabled), devices that are <b>Offline</b> and their <b>Last Offline</b> date time is older than the specified hours in this setting. Use this setting if you want to auto-delete <b>Offline Devices</b> after <code>X</code> hours being offline.",
"HRS_TO_KEEP_OFFDEV_name": "Delete offline devices after",
"HelpFAQ_Cat_Detail": "Details",
"HelpFAQ_Cat_Detail_300_head": "What means ",
"HelpFAQ_Cat_Detail_300_text_a": "means a network device (a device of the type AP, Gateway, Firewall, Hypervisor, Powerline, Switch, WLAN, PLC, Router,USB LAN Adapter, USB WIFI Adapter, or Internet). Custom types can be added via the <code>NETWORK_DEVICE_TYPES</code> setting.",

View File

@@ -321,6 +321,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "Se trata de una configuración de mantenimiento <b>BORRAR dispositivos</b>. Si está activado (<code>0</code> está desactivado), los dispositivos marcados como <b>Nuevo dispositivo</b> se eliminarán si su fecha de <b>primera sesión</b> es anterior a las horas especificadas en este ajuste. Use este ajuste si desea eliminar automáticamente <b>Nuevos dispositivos</b> después de <code>X</code> horas.",
"HRS_TO_KEEP_NEWDEV_name": "Eliminar nuevos dispositivos después",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "Detalles",
"HelpFAQ_Cat_Detail_300_head": "¿Qué significa? ",
"HelpFAQ_Cat_Detail_300_text_a": "significa un dispositivo de red (un dispositivo del tipo AP, Gateway, Firewall, Hypervisor, Powerline, Switch, WLAN, PLC, Router,Adaptador LAN USB, Adaptador WIFI USB o Internet). Los tipos personalizados pueden añadirse mediante el ajuste <code>NETWORK_DEVICE_TYPES</code>.",

View File

@@ -311,6 +311,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "Paramètre de maintenance. S'il est activé (<code>0</code> s'il est désactivé), les appareils marqués comme <b>Nouvel appareil</b> seront supprimés si leur durée depuis la <b>première session</b> est plus ancienne que le nombre d'heures paramétré. Utilisez ce paramétrage si vous voulez supprimer automatiquement les <b>Nouveaux appareils</b> après <code>X</code> heures.",
"HRS_TO_KEEP_NEWDEV_name": "Supprimer les nouveaux appareils après",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "Détails",
"HelpFAQ_Cat_Detail_300_head": "Que signifie ",
"HelpFAQ_Cat_Detail_300_text_a": "signifie que cela représente un équipement réseau (Access Point, Gateway, Firewall, Hyperviseur, Powerline, Switch, WLAN, CPL, adaptateur Ethernet USB, adaptateur Wifi USB, Internet). Les types d'appareils personnalisés peuvent être ajoutés via le paramètre <code>NETWORK_DEVICE_TYPES</code>.",

View File

@@ -311,6 +311,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "Questa è un'impostazione di manutenzione <b>ELIMINAZIONE dispositivi</b>. Se abilitata (<code>0</code> è disabilitata), tutti i dispositivi marcati con <b>Nuovo dispositivo</b> verranno eliminati se l'orario della <b>Prima sessione</b> è precedente all'orario di questa impostazione. Usa questa impostazione se vuoi eliminare automaticamente i <b>Nuovi dispositivi</b> dopo <code>X</code> ore.",
"HRS_TO_KEEP_NEWDEV_name": "Elimina nuovi dispositivi dopo",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "Dettagli",
"HelpFAQ_Cat_Detail_300_head": "Cosa significa ",
"HelpFAQ_Cat_Detail_300_text_a": "indica un dispositivo di rete (un dispositivo di tipo AP, Gateway, Firewall, Hypervisor, Powerline, Switch, WLAN, PLC, Router, USB LAN Adapter, USB WIFI Adapter, o Internet). Tipi personalizzati possono essere aggiunti attraverso l'impostazione <code>NETWORK_DEVICE_TYPES</code>.",

View File

@@ -311,6 +311,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "Dette er en vedlikeholdsinnstilling. Hvis aktivert (<code>0</code> er deaktivert), vil enheter merket som <b>Ny Enhet</b> bli slettet hvis tiden deres for <b>Første økt</b> var eldre enn de angitte timene i denne innstilling. Bruk denne innstillingen hvis du vil automatisk slette <b>Nye Enheter</b> etter <code>X</code> timer.",
"HRS_TO_KEEP_NEWDEV_name": "Behold nye enheter for",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "Detaljer",
"HelpFAQ_Cat_Detail_300_head": "Hva betyr ",
"HelpFAQ_Cat_Detail_300_text_a": "betyr en nettverksenhet (en enhet av typen AP, Gateway, Brannmur, Hypervisor, Powerline, Switch, WLAN, PLS, ruter, USB LAN-adapter, USB WIFI-adapter eller Internett). Egendefinerte typer kan legges til via <code>NETWORK_DEVICE_TYPES</code>-innstillingen.",

View File

@@ -311,6 +311,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "To jest ustawienie konserwacyjne. Jeżeli uruchomione (<code>0</code> jest wyłączone), urządzenie oznaczone jako <b>Nowe Urządzenie</b> zostanie usunięte jeżeli czas <b>Pierwszej Sesji</b> jest starszy niż godzina podana w tym ustawieniu. Uzyj tego ustawienia jeżeli chcesz automatycznie usuwać <b>Nowe Urządzenia</b> po <code>X</code> godzinach.",
"HRS_TO_KEEP_NEWDEV_name": "Trzymaj nowe urządzenia przez",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "Szczegóły",
"HelpFAQ_Cat_Detail_300_head": "Co oznacza ",
"HelpFAQ_Cat_Detail_300_text_a": "oznacza urządzenie sieciowe (urządzenie typu AP, Gateway, Zapora sieciowa, Hypervisor, Powerline, Switch, WLAN, PLC, Ruter, Adapter USB LAN, Adapter USB WIFI, oraz Internet). Własny typ może zostać dodany poprzez ustawienie <code>NETWORK_DEVICE_TYPE</code>.",

View File

@@ -311,6 +311,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "Esta é uma configuração de manutenção. Se habilitada (<code>0</code> is disabled), dispositivos marcados como <b>Novo Dispositivo</b> serão excluídos se o tempo de <b>Primeira Sessão</b> for mais antigo que as horas especificadas nesta configuração. Use esta configuração se quiser excluir automaticamente <b>Novos Dispositivos</b> após <code>X</code> horas.",
"HRS_TO_KEEP_NEWDEV_name": "Manter novos dispositivos por",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "Detalhes",
"HelpFAQ_Cat_Detail_300_head": "O que significa ",
"HelpFAQ_Cat_Detail_300_text_a": "Significa um dispositivo de rede (um dispositivo do tipo AP, Gateway, Firewall, Hypervisor, Powerline, Switch, WLAN, PLC, Roteador, Adaptador LAN USB, Adaptador Wi-Fi USB ou Internet). Tipos personalizados podem ser adicionados através da configuração <code>NETWORK_DEVICE_TYPES</code>.",

View File

@@ -311,6 +311,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "Это настройка обслуживания <b>УДАЛЕНИЕ устройств</b>. Если этот параметр включен (<code>0</code> отключен), устройства, помеченные как <b>Новое устройство</b>, будут удалены, если время их <b>Первого сеанса</b> было старше указанных в этой настройке часов. Используйте этот параметр, если вы хотите автоматически удалять <b>Новые устройства</b> через <code>X</code> часов.",
"HRS_TO_KEEP_NEWDEV_name": "Удалить новые устройства после",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "Подробности",
"HelpFAQ_Cat_Detail_300_head": "Что значит ",
"HelpFAQ_Cat_Detail_300_text_a": "означает сетевое устройство (типа AP, шлюз, межсетевой экран, гипервизор, Powerline, коммутатор, WLAN, PLC, маршрутизатор, USB-адаптер локальной сети, USB-адаптер Wi-Fi или Интернет). Пользовательские типы можно добавить с помощью параметра <code>NETWORK_DEVICE_TYPES</code>.",

View File

@@ -311,6 +311,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "",
"HRS_TO_KEEP_NEWDEV_name": "",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "Detaylar",
"HelpFAQ_Cat_Detail_300_head": "",
"HelpFAQ_Cat_Detail_300_text_a": "",

View File

@@ -311,6 +311,8 @@
"General_icon": "<i class=\"fa fa-gears\"></i>",
"HRS_TO_KEEP_NEWDEV_description": "这是一项维护设置。如果启用(<code>0</code> 为禁用),则标记为<b>新设备</b>的设备(如果其<b>首次会话</b>时间早于此设置中指定的小时数)将被删除。如果您想在 <code>X</code> 小时后自动删除<b>新设备</b>,请使用此设置。",
"HRS_TO_KEEP_NEWDEV_name": "保留新设备",
"HRS_TO_KEEP_OFFDEV_description": "",
"HRS_TO_KEEP_OFFDEV_name": "",
"HelpFAQ_Cat_Detail": "详细",
"HelpFAQ_Cat_Detail_300_head": "含义 ",
"HelpFAQ_Cat_Detail_300_text_a": "表示网络设备AP、网关、防火墙、虚拟机管理程序、电力线、交换机、WLAN、PLC、路由器、USB LAN 适配器、USB WIFI 适配器或 Internet 类型的设备)。可以通过 <code>NETWORK_DEVICE_TYPES</code> 设置添加自定义类型。",

View File

@@ -34,6 +34,7 @@ def main():
PLUGINS_KEEP_HIST = int(get_setting_value("PLUGINS_KEEP_HIST"))
HRS_TO_KEEP_NEWDEV = int(get_setting_value("HRS_TO_KEEP_NEWDEV"))
HRS_TO_KEEP_OFFDEV = int(get_setting_value("HRS_TO_KEEP_OFFDEV"))
DAYS_TO_KEEP_EVENTS = int(get_setting_value("DAYS_TO_KEEP_EVENTS"))
PHOLUS_DAYS_DATA = get_setting_value("PHOLUS_DAYS_DATA")
CLEAR_NEW_FLAG = get_setting_value("CLEAR_NEW_FLAG")
@@ -42,7 +43,7 @@ def main():
# Execute cleanup/upkeep
cleanup_database(fullDbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, PLUGINS_KEEP_HIST, CLEAR_NEW_FLAG)
cleanup_database(fullDbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, HRS_TO_KEEP_OFFDEV, PLUGINS_KEEP_HIST, CLEAR_NEW_FLAG)
mylog('verbose', [f'[{pluginName}] Cleanup complete'])
@@ -51,7 +52,7 @@ def main():
#===============================================================================
# Cleanup / upkeep database
#===============================================================================
def cleanup_database (dbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, PLUGINS_KEEP_HIST, CLEAR_NEW_FLAG):
def cleanup_database (dbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, HRS_TO_KEEP_OFFDEV, PLUGINS_KEEP_HIST, CLEAR_NEW_FLAG):
"""
Cleaning out old records from the tables that don't need to keep all data.
"""
@@ -144,6 +145,14 @@ def cleanup_database (dbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP
mylog('verbose', [f'[{pluginName}] Query: {query} '])
cursor.execute (query)
# -----------------------------------------------------
# Cleanup Offline Devices
if HRS_TO_KEEP_OFFDEV != 0:
mylog('verbose', [f'[{pluginName}] Devices: Delete all New Devices older than {str(HRS_TO_KEEP_OFFDEV)} hours (HRS_TO_KEEP_OFFDEV setting)'])
query = f"""DELETE FROM Devices WHERE dev_PresentLastScan = 0 AND dev_LastConnection < date('now', '-{str(HRS_TO_KEEP_OFFDEV)} hour'))"""
mylog('verbose', [f'[{pluginName}] Query: {query} '])
cursor.execute (query)
# -----------------------------------------------------
# Clear New Flag
if CLEAR_NEW_FLAG != 0:

View File

@@ -146,6 +146,7 @@ def importConfigs (db, all_plugins):
conf.REPORT_DASHBOARD_URL = ccd('REPORT_DASHBOARD_URL', 'http://netalertx/' , c_d, 'NetAlertX URL', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General')
conf.DAYS_TO_KEEP_EVENTS = ccd('DAYS_TO_KEEP_EVENTS', 90 , c_d, 'Delete events days', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', '[]', 'General')
conf.HRS_TO_KEEP_NEWDEV = ccd('HRS_TO_KEEP_NEWDEV', 0 , c_d, 'Keep new devices for', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', "[]", 'General')
conf.HRS_TO_KEEP_OFFDEV = ccd('HRS_TO_KEEP_OFFDEV', 0 , c_d, 'Keep offline devices for', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', "[]", 'General')
conf.CLEAR_NEW_FLAG = ccd('CLEAR_NEW_FLAG', 0 , c_d, 'Clear new flag', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', "[]", 'General')
conf.API_CUSTOM_SQL = ccd('API_CUSTOM_SQL', 'SELECT * FROM Devices WHERE dev_PresentLastScan = 0' , c_d, 'Custom endpoint', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General')
conf.VERSION = ccd('VERSION', '' , c_d, 'Version', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [{ "readonly": "true" }] ,"transformers": []}]}', '', 'General')