mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# !/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -7,18 +7,18 @@ INSTALL_PATH = os.getenv('NETALERTX_APP', '/app')
|
||||
sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
|
||||
pluginName = 'LUCIRPC'
|
||||
|
||||
from plugin_helper import Plugin_Objects
|
||||
from logger import mylog, Logger
|
||||
from helper import get_setting_value
|
||||
from const import logPath
|
||||
import conf
|
||||
from pytz import timezone
|
||||
from plugin_helper import Plugin_Objects # noqa: E402 [flake8 lint suppression]
|
||||
from logger import mylog, Logger # noqa: E402 [flake8 lint suppression]
|
||||
from helper import get_setting_value # noqa: E402 [flake8 lint suppression]
|
||||
from const import logPath # noqa: E402 [flake8 lint suppression]
|
||||
import conf # noqa: E402 [flake8 lint suppression]
|
||||
from pytz import timezone # noqa: E402 [flake8 lint suppression]
|
||||
|
||||
try:
|
||||
from openwrt_luci_rpc import OpenWrtRpc
|
||||
except:
|
||||
mylog('error', [f'[{pluginName}] Failed import openwrt_luci_rpc'])
|
||||
exit()
|
||||
except ImportError as e:
|
||||
mylog('error', [f'[{pluginName}] Failed import openwrt_luci_rpc: {e}'])
|
||||
exit(1)
|
||||
|
||||
conf.tz = timezone(get_setting_value('TIMEZONE'))
|
||||
|
||||
@@ -30,13 +30,14 @@ RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
|
||||
|
||||
plugin_objects = Plugin_Objects(RESULT_FILE)
|
||||
|
||||
def main():
|
||||
mylog('verbose', [f'[{pluginName}] start script.'])
|
||||
|
||||
def main():
|
||||
mylog('verbose', [f'[{pluginName}] start script.'])
|
||||
|
||||
device_data = get_device_data()
|
||||
|
||||
for entry in device_data:
|
||||
mylog('verbose', [f'[{pluginName}] found: ', str(entry.mac).lower()])
|
||||
mylog('verbose', [f'[{pluginName}] found: ', str(entry.mac).lower()])
|
||||
|
||||
name = str(entry.hostname)
|
||||
|
||||
@@ -45,36 +46,38 @@ def main():
|
||||
|
||||
plugin_objects.add_object(
|
||||
primaryId = str(entry.mac).lower(),
|
||||
secondaryId = entry.ip,
|
||||
secondaryId = entry.ip,
|
||||
watched1 = entry.host,
|
||||
watched2 = name,
|
||||
watched3 = "",
|
||||
watched3 = "",
|
||||
watched4 = "",
|
||||
extra = pluginName,
|
||||
extra = pluginName,
|
||||
foreignKey = str(entry.mac).lower())
|
||||
|
||||
plugin_objects.write_result_file()
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] Script finished'])
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] Script finished'])
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def get_device_data():
|
||||
router = OpenWrtRpc(
|
||||
get_setting_value("LUCIRPC_host"),
|
||||
get_setting_value("LUCIRPC_user"),
|
||||
get_setting_value("LUCIRPC_password"),
|
||||
get_setting_value("LUCIRPC_ssl"),
|
||||
get_setting_value("LUCIRPC_user"),
|
||||
get_setting_value("LUCIRPC_password"),
|
||||
get_setting_value("LUCIRPC_ssl"),
|
||||
get_setting_value("LUCIRPC_verify_ssl")
|
||||
)
|
||||
)
|
||||
|
||||
if router.is_logged_in():
|
||||
mylog('verbose', [f'[{pluginName}] login successfully.'])
|
||||
mylog('verbose', [f'[{pluginName}] login successfully.'])
|
||||
else:
|
||||
mylog('error', [f'[{pluginName}] login fail.'])
|
||||
|
||||
mylog('error', [f'[{pluginName}] login fail.'])
|
||||
|
||||
device_data = router.get_all_connected_devices(only_reachable=get_setting_value("LUCIRPC_only_reachable"))
|
||||
return device_data
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user