diff --git a/db/pialert.db b/db/pialert.db deleted file mode 100755 index ff4e2731..00000000 Binary files a/db/pialert.db and /dev/null differ diff --git a/front/plugins/undiscoverables/config.json b/front/plugins/undiscoverables/config.json index b997d1e6..c1d9b509 100644 --- a/front/plugins/undiscoverables/config.json +++ b/front/plugins/undiscoverables/config.json @@ -3,6 +3,8 @@ "unique_prefix": "UNDIS", "enabled": true, "data_source": "python-script", + "mapped_to_table": "DHCP_Leases", + "localized": ["display_name", "description", "icon"], "display_name": [ @@ -23,37 +25,33 @@ "string": "This plugin is to import undiscoverable devices from a file." } ], + "params" : [ + { + "name" : "devices", + "type" : "setting", + "value" : "UNDIS_devices_to_import" + }], "settings": [ { - "function": "RUN", - "type": "selecttext", - "default_value": "once", - "options": [ - "disabled", - "once", - "schedule", - "always_after_scan", - "on_new_device" - ], + "function": "RUN", + "type": "selecttext", + "default_value":"disabled", + "options": ["disabled", "once", "always_after_scan"], "localized": ["name", "description"], - "name": [ - { - "language_code": "en_us", - "string": "When to run" - } - ], - "description": [ - { - "language_code": "en_us", - "string": "Enable import of devices from a file. If you select schedule the scheduling settings from below are applied. If you select once the scan is run only once on start of the application (container) or after you update your settings." - } - ] - }, + "name" :[{ + "language_code":"en_us", + "string" : "When to run" + }], + "description": [{ + "language_code":"en_us", + "string" : "When enabled, once is the preferred option. It runs at startup and after every save of the config here.
Changes will only show in the devices after the next scan!" + }] + }, { "function": "CMD", - "type": "text", - "default_value": "python3 /home/pi/pialert/front/plugins/undiscoverables/script.py", + "type": "readonly", + "default_value": "python3 /home/pi/pialert/front/plugins/undiscoverables/script.py devices={devices}", "options": [], "localized": ["name", "description"], "name": [ @@ -65,43 +63,21 @@ "description": [ { "language_code": "en_us", - "string": "Command to run" - } - ] - }, - { - "function": "RUN_SCHD", - "type": "text", - "default_value": "0 2 * * *", - "options": [], - "localized": ["name", "description"], - "name": [ - { - "language_code": "en_us", - "string": "Schedule" - } - ], - "description": [ - { - "language_code": "en_us", - "string": "Only enabled if you select schedule in the DHCPLSS_RUN setting. Make sure you enter the schedule in the correct cron-like format (e.g. validate at crontab.guru). For example entering 0 4 * * * will run the scan after 4 am in the TIMEZONE you set above. Will be run NEXT time the time passes." + "string": "Command to run. This can not be changed" } ] }, + { "function": "RUN_TIMEOUT", "type": "integer", - "default_value": 5, + "default_value": 10, "options": [], "localized": ["name", "description"], "name": [ { "language_code": "en_us", "string": "Run timeout" - }, - { - "language_code": "de_de", - "string": "Wartezeit" } ], "description": [ @@ -113,14 +89,9 @@ }, { "function": "WATCH", - "type": "multiselect", - "default_value": ["Watched_Value1", "Watched_Value4"], - "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" - ], + "type": "lable", + "default_value": [], + "options": [], "localized": ["name", "description"], "name": [ { @@ -131,14 +102,14 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect. " + "string": "Undiscoverable Devices can not change their status, no watch is enabled." } ] }, { "function": "REPORT_ON", - "type": "multiselect", - "default_value": ["new", "watched-changed"], + "type": "lable", + "default_value": [], "options": ["new", "watched-changed", "watched-not-changed"], "localized": ["name", "description"], "name": [ @@ -150,9 +121,97 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "No notifications will be sent." } ] - } + }, + { + "function": "devices_to_import", + "type": "list", + "default_value":["dummy_router"], + "options": [], + "localized": ["name", "description"], + "name" : [{ + "language_code":"en_us", + "string" : "UnDiscoverable Devices" + }], + "description": [{ + "language_code":"en_us", + "string" : "Devices to be added to the devices list." + }] + } + ], + + "database_column_definitions": + [ + { + "column": "Watched_Value1", + "mapped_to_column": "DHCP_Name", + "css_classes": "col-sm-2", + "show": true, + "type": "label", + "default_value":"", + "options": [], + "localized": ["name"], + "name":[{ + "language_code":"en_us", + "string" : "Device Name" + }] + }, + { + "column": "Object_PrimaryID", + "mapped_to_column": "DHCP_MAC", + "css_classes": "col-sm-2", + "show": true, + "type": "devicemac", + "default_value":"", + "options": [], + "localized": ["name"], + "name":[{ + "language_code":"en_us", + "string" : "MAC address" + }] + }, + { + "column": "Object_SecondaryID", + "mapped_to_column": "DHCP_IP", + "css_classes": "col-sm-2", + "show": true, + "type": "deviceip", + "default_value":"", + "options": [], + "localized": ["name"], + "name":[{ + "language_code":"en_us", + "string" : "IP" + }] + } , + { + "column": "DateTimeCreated", + "css_classes": "col-sm-2", + "show": true, + "type": "label", + "default_value":"", + "options": [], + "localized": ["name"], + "name":[{ + "language_code":"en_us", + "string" : "Created" + }] + }, + { + "column": "DateTimeChanged", + "mapped_to_column": "DHCP_DateTime", + "css_classes": "col-sm-2", + "show": true, + "type": "label", + "default_value":"", + "options": [], + "localized": ["name"], + "name":[{ + "language_code":"en_us", + "string" : "Changed" + }] + } ] } diff --git a/front/plugins/undiscoverables/script.py b/front/plugins/undiscoverables/script.py index fa51e221..93d38310 100644 --- a/front/plugins/undiscoverables/script.py +++ b/front/plugins/undiscoverables/script.py @@ -1,35 +1,39 @@ #!/usr/bin/env python -# Based on the work of https://github.com/leiweibau/Pi.Alert +# test script by running python script.py devices=test,dummy -# python3 /home/pi/pialert/front/plugins/website_monitor/script.py urls=http://google.com,http://bing.com - -import sys +import os import pathlib +import argparse from plugin_helper import Plugin_Objects -sys.dont_write_bytecode = True - curPath = str(pathlib.Path(__file__).parent.resolve()) -log_file = curPath + '/script.log' -result_file = curPath + '/last_result.log' +log_file = os.path.join(curPath , 'script.log') +result_file = os.path.join(curPath , 'last_result.log') -FAKE_DEVICES = ["routerXX","hubZZ"] def main(): - print("Hello") - devices = Plugin_Objects( result_file ) + parser = argparse.ArgumentParser(description='Import devices from dhcp.leases files') + parser.add_argument('devices', action="store", help="absolute dhcp.leases file paths to check separated by ','") + values = parser.parse_args() + + undis_devices = Plugin_Objects( result_file ) + if values.devices: + for fake_dev in values.devices.split('=')[1].split(','): + undis_devices.add_object( + primaryId=fake_dev, # MAC + secondaryId="0.0.0.0", # IP Address + watched1=fake_dev, # Device Name + watched2="", + watched3="", + watched4="UNDIS", # used as ScanMethod + extra="1", # used as dummy ScanCycle + foreignKey="") - for fake_dev in FAKE_DEVICES: - devices.add_object(fake_dev, fake_dev, fake_dev, fake_dev, "", "", "", "") - - #for obj in devices.objects: - # print(obj.write()) - - devices.write_result_file() + undis_devices.write_result_file() return 0