mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
code and documentation tidied up
This commit is contained in:
20
front/plugins/undiscoverables/README.md
Normal file
20
front/plugins/undiscoverables/README.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
## Overview
|
||||||
|
|
||||||
|
A plugin allowing for importing Un-Discoverable devices from the settings page.
|
||||||
|
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
- Go to settings and find Un-Discoverabe Devices in the list of plugins.
|
||||||
|
- Enable the plugin by changing the RUN parameter from disabled to `once` or `always_after_scan`.
|
||||||
|
- Add the name of your device to the list. (remove the sample entry first)
|
||||||
|
- SAVE
|
||||||
|
- wait for the next scan to finish
|
||||||
|
|
||||||
|
#### Example:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Known Limitations
|
||||||
|
- Un-Discoverable Devices always show as offline. That is expected as they can not be discovered by Pi.Alert.
|
||||||
|
- All IPs are set to 0.0.0.0 therefore the "Random MAC" icon might show up.
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
}],
|
}],
|
||||||
"description": [{
|
"description": [{
|
||||||
"language_code":"en_us",
|
"language_code":"en_us",
|
||||||
"string" : "When enabled, once is the preferred option. It runs at startup and after every save of the config here.<br> Changes will only show in the devices after the next scan!"
|
"string" : "When enabled, \"once\" is the preferred option. It runs at startup and after every save of the config here.<br> Changes will only show in the devices <b> after the next scan!</b>"
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
|
from time import strftime
|
||||||
|
|
||||||
from time import sleep, time, strftime
|
|
||||||
import sys
|
|
||||||
import pathlib
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
class Plugin_Object:
|
class Plugin_Object:
|
||||||
|
"""
|
||||||
|
Plugin_Object class to manage one object introduced by the plugin
|
||||||
|
An object typically is a device but could also be a website or something
|
||||||
|
else that is monitored by the plugin.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
primaryId="",
|
primaryId="",
|
||||||
@@ -14,7 +18,7 @@ class Plugin_Object:
|
|||||||
watched3="",
|
watched3="",
|
||||||
watched4="",
|
watched4="",
|
||||||
extra="",
|
extra="",
|
||||||
foreignKey=""
|
foreignKey="",
|
||||||
):
|
):
|
||||||
self.pluginPref = ""
|
self.pluginPref = ""
|
||||||
self.primaryId = primaryId
|
self.primaryId = primaryId
|
||||||
@@ -31,51 +35,62 @@ class Plugin_Object:
|
|||||||
self.foreignKey = foreignKey
|
self.foreignKey = foreignKey
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
line = ("{}|{}|{}|{}|{}|{}|{}|{}|{}\n".format(
|
"""
|
||||||
self.primaryId,
|
write the object details as a string in the
|
||||||
self.secondaryId,
|
format required to write the result file
|
||||||
self.created,
|
"""
|
||||||
self.watched1,
|
line = "{}|{}|{}|{}|{}|{}|{}|{}|{}\n".format(
|
||||||
self.watched2,
|
self.primaryId,
|
||||||
self.watched3,
|
self.secondaryId,
|
||||||
self.watched4,
|
self.created,
|
||||||
self.extra,
|
self.watched1,
|
||||||
self.foreignKey
|
self.watched2,
|
||||||
)
|
self.watched3,
|
||||||
|
self.watched4,
|
||||||
|
self.extra,
|
||||||
|
self.foreignKey,
|
||||||
)
|
)
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Plugin_Objects:
|
class Plugin_Objects:
|
||||||
|
"""
|
||||||
|
Plugin_Objects is the class that manages and holds all the objects created by the plugin.
|
||||||
|
It contains a list of Plugin_Object instances.
|
||||||
|
And can write the required result file.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, result_file):
|
def __init__(self, result_file):
|
||||||
self.result_file = result_file
|
self.result_file = result_file
|
||||||
self.objects = []
|
self.objects = []
|
||||||
|
|
||||||
def add_object ( self, primaryId="",
|
def add_object(
|
||||||
|
self,
|
||||||
|
primaryId="",
|
||||||
secondaryId="",
|
secondaryId="",
|
||||||
watched1="",
|
watched1="",
|
||||||
watched2="",
|
watched2="",
|
||||||
watched3="",
|
watched3="",
|
||||||
watched4="",
|
watched4="",
|
||||||
extra="",
|
extra="",
|
||||||
foreignKey="" ):
|
foreignKey="",
|
||||||
|
):
|
||||||
self.objects.append(Plugin_Object(primaryId,
|
self.objects.append(
|
||||||
secondaryId,
|
Plugin_Object(
|
||||||
watched1,
|
primaryId,
|
||||||
watched2,
|
secondaryId,
|
||||||
watched3,
|
watched1,
|
||||||
watched4,
|
watched2,
|
||||||
extra,
|
watched3,
|
||||||
foreignKey)
|
watched4,
|
||||||
|
extra,
|
||||||
|
foreignKey,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def write_result_file(self):
|
def write_result_file(self):
|
||||||
# print ("writing file: "+self.result_file)
|
# print ("writing file: "+self.result_file)
|
||||||
with open(self.result_file, mode='w') as fp:
|
with open(self.result_file, mode="w") as fp:
|
||||||
for obj in self.objects:
|
for obj in self.objects:
|
||||||
fp.write ( obj.write() )
|
fp.write(obj.write())
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
|
|||||||
@@ -7,36 +7,36 @@ import argparse
|
|||||||
|
|
||||||
from plugin_helper import Plugin_Objects
|
from plugin_helper import Plugin_Objects
|
||||||
|
|
||||||
curPath = str(pathlib.Path(__file__).parent.resolve())
|
CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
||||||
log_file = os.path.join(curPath , 'script.log')
|
LOG_FILE = os.path.join(CUR_PATH , 'script.log')
|
||||||
result_file = os.path.join(curPath , 'last_result.log')
|
RESULT_FILE = os.path.join(CUR_PATH , 'last_result.log')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Import devices from dhcp.leases files')
|
# the script expects a parameter in the format of devices=device1,device2,...
|
||||||
parser.add_argument('devices', action="store", help="absolute dhcp.leases file paths to check separated by ','")
|
parser = argparse.ArgumentParser(description='Import devices from settings')
|
||||||
values = parser.parse_args()
|
parser.add_argument('devices', action="store", help="list of device names separated by ','")
|
||||||
|
values = parser.parse_args()
|
||||||
|
|
||||||
undis_devices = Plugin_Objects( result_file )
|
UNDIS_devices = Plugin_Objects( RESULT_FILE )
|
||||||
|
|
||||||
if values.devices:
|
if values.devices:
|
||||||
for fake_dev in values.devices.split('=')[1].split(','):
|
for fake_dev in values.devices.split('=')[1].split(','):
|
||||||
undis_devices.add_object(
|
UNDIS_devices.add_object(
|
||||||
primaryId=fake_dev, # MAC
|
primaryId=fake_dev, # MAC (Device Name)
|
||||||
secondaryId="0.0.0.0", # IP Address
|
secondaryId="0.0.0.0", # IP Address (always 0.0.0.0)
|
||||||
watched1=fake_dev, # Device Name
|
watched1=fake_dev, # Device Name
|
||||||
watched2="",
|
watched2="",
|
||||||
watched3="",
|
watched3="",
|
||||||
watched4="UNDIS", # used as ScanMethod
|
watched4="",
|
||||||
extra="1", # used as dummy ScanCycle
|
extra="",
|
||||||
foreignKey="")
|
foreignKey="")
|
||||||
|
|
||||||
undis_devices.write_result_file()
|
UNDIS_devices.write_result_file()
|
||||||
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
# BEGIN
|
# BEGIN
|
||||||
|
|||||||
Reference in New Issue
Block a user