diff --git a/back/pialert.py b/back/pialert.py index 80d9f598..647cb48a 100755 --- a/back/pialert.py +++ b/back/pialert.py @@ -294,7 +294,7 @@ def commitDB (): def ccd(key, default, config, name, inputtype, options, group, events=[], desc = "", regex = ""): result = default - # use existing value if already supplied, otehrwise default value is used + # use existing value if already supplied, otherwise default value is used if key in config: result = config[key] @@ -3825,7 +3825,7 @@ def execute_plugin(plugin): else: set_RUN_TIMEOUT = set["value"] - mylog('debug', [' [Plugins] Timeout: ', set_RUN_TIMEOUT]) + mylog('debug', [' [Plugins] Timeout: ', set_RUN_TIMEOUT]) # Prepare custom params params = [] @@ -3852,18 +3852,18 @@ def execute_plugin(plugin): params.append( [param["name"], resolved] ) - # ------- prepare params -------- - # prepare command from plugin settings, custom parameters - command = resolve_wildcards(set_CMD, params).split() - # build SQL query parameters to insert into the DB sqlParams = [] # python-script if plugin['data_source'] == 'python-script': + # ------- prepare params -------- + # prepare command from plugin settings, custom parameters + command = resolve_wildcards_arr(set_CMD.split(), params) # Execute command mylog('verbose', [' [Plugins] Executing: ', set_CMD]) + mylog('debug', [' [Plugins] Resolved : ', command]) try: # try runnning a subprocess with a forced timeout in case the subprocess hangs @@ -4164,8 +4164,7 @@ def combine_plugin_objects(old, new): # Replace {wildcars} with parameters def resolve_wildcards(command, params): - mylog('debug', [' [Plugins]: Pre-Resolved CMD: ', command]) - + mylog('debug', [' [Plugins]: Pre-Resolved CMD: ', command]) for param in params: mylog('debug', [' [Plugins]: key : {', param[0], '}']) @@ -4176,6 +4175,26 @@ def resolve_wildcards(command, params): return command +#------------------------------------------------------------------------------- +# Replace {wildcars} with parameters +def resolve_wildcards_arr(commandArr, params): + + mylog('debug', [' [Plugins]: Pre-Resolved CMD: '] + commandArr) + + for param in params: + # mylog('debug', [' [Plugins]: key : {', param[0], '}']) + # mylog('debug', [' [Plugins]: resolved: ', param[1]]) + + i = 0 + + for comPart in commandArr: + + commandArr[i] = comPart.replace('{' + param[0] + '}', param[1]).replace('{s-quote}',"'") + + i += 1 + + return commandArr + #------------------------------------------------------------------------------- # Flattens a setting to make it passable to a script def plugin_param_from_glob_set(globalSetting): @@ -4254,13 +4273,16 @@ def flatten_array(arr): tmp = '' + mylog('debug', arr) + for arrayItem in arr: # only one column flattening is supported if isinstance(arrayItem, list): arrayItem = str(arrayItem[0]) tmp += arrayItem + ',' - tmp = tmp.replace("'","").replace(' ','') # No single quotes or empty spaces allowed + # tmp = tmp.replace("'","").replace(' ','') # No single quotes or empty spaces allowed + tmp = tmp.replace("'","") # No single quotes allowed return tmp[:-1] # Remove last comma ',' diff --git a/front/php/server/devices.php b/front/php/server/devices.php index 67b4e805..e0d3a88f 100755 --- a/front/php/server/devices.php +++ b/front/php/server/devices.php @@ -619,8 +619,6 @@ function getDevicesList() { // init ordered columns for($i = 0; $i < count($orderedColumns); $i++) { - - $oldVal = $columnOrderMapping[$i][2]; $columnOrderMapping[$i][2] = $orderedColumns[$i]; } diff --git a/front/plugins/snmp_discovery/config.json b/front/plugins/snmp_discovery/config.json index 4f888894..4e4034d9 100755 --- a/front/plugins/snmp_discovery/config.json +++ b/front/plugins/snmp_discovery/config.json @@ -232,7 +232,7 @@ { "function": "CMD", "type": "text", - "default_value":"python3 /home/pi/pialert/front/plugins/snmp_discovery/script.py routers='{routers}' ", + "default_value":"python3 /home/pi/pialert/front/plugins/snmp_discovery/script.py routers={s-quote}{routers}{s-quote}", "options": [], "localized": ["name", "description"], "name" : [{ diff --git a/front/plugins/snmp_discovery/script.py b/front/plugins/snmp_discovery/script.py index 4bbc3791..8e362c25 100755 --- a/front/plugins/snmp_discovery/script.py +++ b/front/plugins/snmp_discovery/script.py @@ -71,6 +71,8 @@ def get_entries(newEntries): for router in routers: # snmpwalk -v 2c -c public -OXsq 192.168.1.1 .1.3.6.1.2.1.3.1.1.2 + print(router) + timeoutSec = 10 # snmpwalkArgs = ['snmpwalk', '-v', '2c', '-c', 'public', '-OXsq', router, '.1.3.6.1.2.1.3.1.1.2']