mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
cleanup, docs, devSyncHubNode #931
This commit is contained in:
@@ -131,6 +131,34 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"function": "IN_REGEX",
|
||||
"type": {
|
||||
"dataType": "string",
|
||||
"elements": [
|
||||
{
|
||||
"elementType": "input",
|
||||
"elementOptions": [],
|
||||
"transformers": []
|
||||
}
|
||||
]
|
||||
},
|
||||
"default_value": ".*",
|
||||
"options": [],
|
||||
"localized": ["name", "description"],
|
||||
"name": [
|
||||
{
|
||||
"language_code": "en_us",
|
||||
"string": "Inclusion REGEX"
|
||||
}
|
||||
],
|
||||
"description": [
|
||||
{
|
||||
"language_code": "en_us",
|
||||
"string": "REGEX to specify which IPs are included in the scan. Examples: <code>192.168.1.*|10.0.0.1|172.16.5.*</code> (specific IPs or ranges). Use <code>.*</code> to include all IPs."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"function": "RUN_SCHD",
|
||||
"type": {
|
||||
|
||||
@@ -48,6 +48,7 @@ def main():
|
||||
|
||||
timeout = get_setting_value('ICMP_RUN_TIMEOUT')
|
||||
args = get_setting_value('ICMP_ARGS')
|
||||
in_regex = get_setting_value('ICMP_IN_REGEX')
|
||||
|
||||
# Create a database connection
|
||||
db = DB() # instance of class DB
|
||||
@@ -62,9 +63,19 @@ def main():
|
||||
# Retrieve devices
|
||||
all_devices = device_handler.getAll()
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] Devices to PING: {len(all_devices)}'])
|
||||
# Compile the regex for efficiency if it will be used multiple times
|
||||
regex_pattern = re.compile(in_regex)
|
||||
|
||||
for device in all_devices:
|
||||
# Filter devices based on the regex match
|
||||
filtered_devices = [
|
||||
device for device in all_devices
|
||||
if regex_pattern.match(device['devLastIP'])
|
||||
]
|
||||
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] Devices to PING: {len(filtered_devices)}'])
|
||||
|
||||
for device in filtered_devices:
|
||||
is_online, output = execute_scan(device['devLastIP'], timeout, args)
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] ip: "{device['devLastIP']}" is_online: "{is_online}"'])
|
||||
|
||||
@@ -125,8 +125,6 @@ def main():
|
||||
# Mode 2: PULL/GET (HUB)
|
||||
|
||||
# PULLING DEVICES
|
||||
|
||||
file_dir = os.path.join(pluginsPath, 'sync')
|
||||
file_prefix = 'last_result'
|
||||
|
||||
# pull data from nodes if specified
|
||||
@@ -145,7 +143,7 @@ def main():
|
||||
log_file_name = f'{file_prefix}.{node_name}.log'
|
||||
|
||||
# Write decoded data to log file
|
||||
with open(os.path.join(file_dir, log_file_name), 'wb') as log_file:
|
||||
with open(os.path.join(LOG_PATH, log_file_name), 'wb') as log_file:
|
||||
log_file.write(decoded_data)
|
||||
|
||||
message = f'[{pluginName}] Device data from node "{node_name}" written to {log_file_name}'
|
||||
@@ -157,7 +155,7 @@ def main():
|
||||
# Create the file path
|
||||
|
||||
# Get all "last_result" files from the sync folder, decode, rename them, and get the list of files
|
||||
files_to_process = decode_and_rename_files(file_dir, file_prefix)
|
||||
files_to_process = decode_and_rename_files(LOG_PATH, file_prefix)
|
||||
|
||||
if len(files_to_process) > 0:
|
||||
|
||||
@@ -181,11 +179,11 @@ def main():
|
||||
|
||||
# Store e.g. Node_1 from last_result.encoded.Node_1.1.log
|
||||
tmp_SyncHubNodeName = ''
|
||||
if len(file_name.split('.')) > 3:
|
||||
tmp_SyncHubNodeName = file_name.split('.')[2]
|
||||
if len(file_name.split('.')) > 2:
|
||||
tmp_SyncHubNodeName = file_name.split('.')[1]
|
||||
|
||||
|
||||
file_path = f"{INSTALL_PATH}/front/plugins/sync/{file_name}"
|
||||
file_path = f"{LOG_PATH}/{file_name}"
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
data = json.load(f)
|
||||
@@ -197,7 +195,7 @@ def main():
|
||||
|
||||
# Rename the file to "processed_" + current name
|
||||
new_file_name = f"processed_{file_name}"
|
||||
new_file_path = os.path.join(file_dir, new_file_name)
|
||||
new_file_path = os.path.join(LOG_PATH, new_file_name)
|
||||
|
||||
# Overwrite if the new file already exists
|
||||
if os.path.exists(new_file_path):
|
||||
|
||||
@@ -213,7 +213,7 @@ def get_unifi_val(obj, key, default='null'):
|
||||
if result not in ['','None', None, 'null']:
|
||||
return result
|
||||
|
||||
mylog('debug', [f'[{pluginName}] Value not found for key "{key}" in obj "{json.dumps(obj)}"'])
|
||||
mylog('trace', [f'[{pluginName}] Value not found for key "{key}" in obj "{json.dumps(obj)}"'])
|
||||
return default
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user