🔌Plugin execution order

This commit is contained in:
jokob-sk
2024-07-14 20:48:10 +10:00
parent 942908d074
commit 68fb1b7cbb
17 changed files with 51 additions and 25 deletions

View File

@@ -2,6 +2,7 @@
"code_name": "__template",
"unique_prefix": "TMP",
"plugin_type": "device_scanner",
"execution_order" : "Layer_0",
"enabled": true,
"data_source": "script",
"mapped_to_table": "CurrentScan",

View File

@@ -1,6 +1,7 @@
{
"code_name": "arp_scan",
"unique_prefix": "ARPSCAN",
"execution_order" : "Layer_2",
"plugin_type": "device_scanner",
"enabled": true,
"data_source": "script",

View File

@@ -2,6 +2,7 @@
"code_name": "dhcp_leases",
"unique_prefix": "DHCPLSS",
"plugin_type": "device_scanner",
"execution_order" : "Layer_3",
"enabled": true,
"data_source": "script",
"data_filters": [
@@ -513,12 +514,23 @@
],
"transformers": []
},
{
"elementType": "button",
"elementOptions": [
{ "sourceSuffixes": ["_in"] },
{ "separator": "" },
{ "cssClasses": "col-xs-12" },
{ "onClick": "addList(this, false)" },
{ "getStringKey": "Gen_Add" }
],
"transformers": []
},
{
"elementType": "button",
"elementOptions": [
{ "sourceSuffixes": [] },
{ "separator": "" },
{ "cssClasses": "col-sm-3" },
{ "cssClasses": "col-xs-6" },
{ "onClick": "removeAllOptions(this)" },
{ "getStringKey": "Gen_Remove_All" }
],
@@ -529,23 +541,12 @@
"elementOptions": [
{ "sourceSuffixes": [] },
{ "separator": "" },
{ "cssClasses": "col-sm-3" },
{ "cssClasses": "col-xs-6" },
{ "onClick": "removeFromList(this)" },
{ "getStringKey": "Gen_Remove_Last" }
],
"transformers": []
},
{
"elementType": "button",
"elementOptions": [
{ "sourceSuffixes": ["_in"] },
{ "separator": "" },
{ "cssClasses": "col-sm-2" },
{ "onClick": "addList(this, false)" },
{ "getStringKey": "Gen_Add" }
],
"transformers": []
},
{
"elementType": "select",
"elementOptions": [

View File

@@ -2,6 +2,7 @@
"code_name": "dhcp_servers",
"unique_prefix": "DHCPSRVS",
"plugin_type": "other",
"execution_order" : "Layer_3",
"enabled": true,
"data_source": "script",
"show_ui": true,

View File

@@ -2,6 +2,7 @@
"code_name": "internet_ip",
"unique_prefix": "INTRNT",
"plugin_type": "device_scanner",
"execution_order" : "Layer_3",
"enabled": true,
"mapped_to_table": "CurrentScan",
"data_filters": [

View File

@@ -4,6 +4,7 @@
"plugin_type": "other",
"enabled": true,
"data_source": "script",
"execution_order" : "Layer_3",
"show_ui": true,
"localized": ["display_name", "description", "icon"],
"display_name": [

View File

@@ -2,6 +2,7 @@
"code_name": "nmap_dev_scan",
"unique_prefix": "NMAPDEV",
"plugin_type": "device_scanner",
"execution_order" : "Layer_3",
"enabled": true,
"data_source": "script",
"mapped_to_table": "CurrentScan",

View File

@@ -2,6 +2,7 @@
"code_name": "nmap_scan",
"unique_prefix": "NMAP",
"plugin_type": "other",
"execution_order" : "Layer_4",
"enabled": true,
"data_source": "script",
"data_filters": [

View File

@@ -2,6 +2,7 @@
"code_name": "nslookup_scan",
"unique_prefix": "NSLOOKUP",
"plugin_type": "other",
"execution_order" : "Layer_4",
"enabled": true,
"data_source": "script",
"show_ui": true,

View File

@@ -2,6 +2,7 @@
"code_name": "omada_sdn_imp",
"unique_prefix": "OMDSDN",
"plugin_type": "device_scanner",
"execution_order" : "Layer_1",
"enabled": true,
"data_source": "script",
"mapped_to_table": "CurrentScan",

View File

@@ -2,6 +2,7 @@
"code_name": "pihole_scan",
"unique_prefix": "PIHOLE",
"plugin_type": "device_scanner",
"execution_order" : "Layer_2",
"enabled": true,
"data_source": "sqlite-db-query",
"mapped_to_table": "CurrentScan",

View File

@@ -2,6 +2,7 @@
"code_name": "snmp_discovery",
"unique_prefix": "SNMPDSC",
"plugin_type": "device_scanner",
"execution_order" : "Layer_1",
"enabled": true,
"data_source": "script",
"data_filters": [

View File

@@ -3,6 +3,7 @@
"show_ui": true,
"unique_prefix": "UNFIMP",
"plugin_type": "device_scanner",
"execution_order" : "Layer_1",
"data_source": "script",
"localized": ["display_name", "description", "icon"],
"display_name": [

View File

@@ -96,33 +96,33 @@ def print_scan_stats(db):
mylog('verbose', f'[Scan Stats] IP Changes.............: {stats[0]["ip_changes"]}')
# if str(stats[0]["new_devices"]) != '0':
mylog('debug', f' ================ DEVICES table content ================')
mylog('trace', f' ================ DEVICES table content ================')
sql.execute('select * from Devices')
rows = sql.fetchall()
for row in rows:
row_dict = dict(row)
mylog('debug', f' {row_dict}')
mylog('trace', f' {row_dict}')
mylog('debug', f' ================ CurrentScan table content ================')
mylog('trace', f' ================ CurrentScan table content ================')
sql.execute('select * from CurrentScan')
rows = sql.fetchall()
for row in rows:
row_dict = dict(row)
mylog('debug', f' {row_dict}')
mylog('trace', f' {row_dict}')
mylog('debug', f' ================ Events table content where eve_PendingAlertEmail = 1 ================')
mylog('trace', f' ================ Events table content where eve_PendingAlertEmail = 1 ================')
sql.execute('select * from Events where eve_PendingAlertEmail = 1')
rows = sql.fetchall()
for row in rows:
row_dict = dict(row)
mylog('debug', f' {row_dict}')
mylog('trace', f' {row_dict}')
mylog('debug', f' ================ Events table COUNT ================')
mylog('trace', f' ================ Events table COUNT ================')
sql.execute('select count(*) from Events')
rows = sql.fetchall()
for row in rows:
row_dict = dict(row)
mylog('debug', f' {row_dict}')
mylog('trace', f' {row_dict}')
mylog('verbose', '[Scan Stats] Scan Method Statistics:')

View File

@@ -133,7 +133,7 @@ def importConfigs (db, all_plugins):
conf.LOADED_PLUGINS = ccd('LOADED_PLUGINS', [] , c_d, 'Loaded plugins', '{"dataType":"array", "elements": [{"elementType" : "select", "elementOptions" : [{"multiple":"true"}] ,"transformers": []}]}', '[]', 'General')
conf.SCAN_SUBNETS = ccd('SCAN_SUBNETS', ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interface=eth0'] , c_d, 'Subnets to scan', '{"dataType": "array","elements": [ {"elementType": "input","elementOptions": [{ "placeholder": "192.168.1.0/24 --interface=eth1" },{ "suffix": "_in" },{ "cssClasses": "col-sm-10" },{ "prefillValue": "null" }],"transformers": [] }, {"elementType": "button","elementOptions": [{ "sourceSuffixes": ["_in"] },{ "separator": "" },{ "cssClasses": "col-xs-12" },{ "onClick": "addList(this, false)" },{ "getStringKey": "Gen_Add" }],"transformers": [] }, {"elementType": "button","elementOptions": [{ "sourceSuffixes": [] },{ "separator": "" },{ "cssClasses": "col-xs-6" },{ "onClick": "removeAllOptions(this)" },{ "getStringKey": "Gen_Remove_All" }],"transformers": []},{"elementType": "button","elementOptions": [{ "sourceSuffixes": [] },{ "separator": "" },{ "cssClasses": "col-xs-6" },{ "onClick": "removeFromList(this)" },{ "getStringKey": "Gen_Remove_Last" }],"transformers": []}, {"elementType": "select","elementOptions": [{ "multiple": "true" },{ "readonly": "true" },{ "editable": "true" }],"transformers": [] }]}', '[]', 'General')
conf.LOG_LEVEL = ccd('LOG_LEVEL', 'verbose' , c_d, 'Log verboseness', '{"dataType":"string", "elements": [{"elementType" : "select", "elementOptions" : [] ,"transformers": []}]}', "['none', 'minimal', 'verbose', 'debug']", 'General')
conf.LOG_LEVEL = ccd('LOG_LEVEL', 'verbose' , c_d, 'Log verboseness', '{"dataType":"string", "elements": [{"elementType" : "select", "elementOptions" : [] ,"transformers": []}]}', "['none', 'minimal', 'verbose', 'debug', 'trace']", 'General')
conf.TIMEZONE = ccd('TIMEZONE', 'Europe/Berlin' , c_d, 'Time zone', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General')
conf.PLUGINS_KEEP_HIST = ccd('PLUGINS_KEEP_HIST', 250 , c_d, 'Keep history entries', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', '[]', 'General')
conf.REPORT_DASHBOARD_URL = ccd('REPORT_DASHBOARD_URL', 'http://netalertx/' , c_d, 'NetAlertX URL', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General')

View File

@@ -22,7 +22,7 @@ def timeNowTZ():
#-------------------------------------------------------------------------------
# More verbose as the numbers go up
debugLevels = [
('none', 0), ('minimal', 1), ('verbose', 2), ('debug', 3)
('none', 0), ('minimal', 1), ('verbose', 2), ('debug', 3), ('trace', 4)
]
currentLevel = 0

View File

@@ -172,15 +172,25 @@ def resolve_wildcards_arr(commandArr, params):
return commandArr
#-------------------------------------------------------------------------------
# Function to extract layer number from "execution_order"
def get_layer(plugin):
order = plugin.get("execution_order", "Layer_N")
if order == "Layer_N":
return float('inf') # Treat as the last layer if "execution_order" is missing
return int(order.split('_')[1])
#-------------------------------------------------------------------------------
def get_plugins_configs():
pluginsList = [] # Create an empty list to store plugin configurations
pluginsListSorted = [] # Sorted by "execution_order" : "Layer_0" first, Layer_N last
# Get a list of top-level directories in the specified pluginsPath
dirs = next(os.walk(pluginsPath))[1]
# Sort the directories list if needed
dirs.sort() # This will sort the directories alphabetically
# Loop through each directory (plugin folder) in dirs
for d in dirs:
# Check if the directory name does not start with "__" to skip python cache
@@ -194,7 +204,10 @@ def get_plugins_configs():
# Load the contents of the config.json file as a JSON object and append it to pluginsList
pluginsList.append(json.loads(get_file_content(config_path)))
return pluginsList # Return the list of plugin configurations
# Sort pluginsList based on "execution_order"
pluginsListSorted = sorted(pluginsList, key=get_layer)
return pluginsListSorted # Return the sorted list of plugin configurations
#-------------------------------------------------------------------------------