SNMPDSC plugin 0.4
This commit is contained in:
@@ -294,7 +294,7 @@ def commitDB ():
|
|||||||
def ccd(key, default, config, name, inputtype, options, group, events=[], desc = "", regex = ""):
|
def ccd(key, default, config, name, inputtype, options, group, events=[], desc = "", regex = ""):
|
||||||
result = default
|
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:
|
if key in config:
|
||||||
result = config[key]
|
result = config[key]
|
||||||
|
|
||||||
@@ -3852,18 +3852,18 @@ def execute_plugin(plugin):
|
|||||||
params.append( [param["name"], resolved] )
|
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
|
# build SQL query parameters to insert into the DB
|
||||||
sqlParams = []
|
sqlParams = []
|
||||||
|
|
||||||
# python-script
|
# python-script
|
||||||
if plugin['data_source'] == '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
|
# Execute command
|
||||||
mylog('verbose', [' [Plugins] Executing: ', set_CMD])
|
mylog('verbose', [' [Plugins] Executing: ', set_CMD])
|
||||||
|
mylog('debug', [' [Plugins] Resolved : ', command])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# try runnning a subprocess with a forced timeout in case the subprocess hangs
|
# try runnning a subprocess with a forced timeout in case the subprocess hangs
|
||||||
@@ -4166,7 +4166,6 @@ def resolve_wildcards(command, params):
|
|||||||
|
|
||||||
mylog('debug', [' [Plugins]: Pre-Resolved CMD: ', command])
|
mylog('debug', [' [Plugins]: Pre-Resolved CMD: ', command])
|
||||||
|
|
||||||
|
|
||||||
for param in params:
|
for param in params:
|
||||||
mylog('debug', [' [Plugins]: key : {', param[0], '}'])
|
mylog('debug', [' [Plugins]: key : {', param[0], '}'])
|
||||||
mylog('debug', [' [Plugins]: resolved: ', param[1]])
|
mylog('debug', [' [Plugins]: resolved: ', param[1]])
|
||||||
@@ -4176,6 +4175,26 @@ def resolve_wildcards(command, params):
|
|||||||
|
|
||||||
return command
|
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
|
# Flattens a setting to make it passable to a script
|
||||||
def plugin_param_from_glob_set(globalSetting):
|
def plugin_param_from_glob_set(globalSetting):
|
||||||
@@ -4254,13 +4273,16 @@ def flatten_array(arr):
|
|||||||
|
|
||||||
tmp = ''
|
tmp = ''
|
||||||
|
|
||||||
|
mylog('debug', arr)
|
||||||
|
|
||||||
for arrayItem in arr:
|
for arrayItem in arr:
|
||||||
# only one column flattening is supported
|
# only one column flattening is supported
|
||||||
if isinstance(arrayItem, list):
|
if isinstance(arrayItem, list):
|
||||||
arrayItem = str(arrayItem[0])
|
arrayItem = str(arrayItem[0])
|
||||||
|
|
||||||
tmp += arrayItem + ','
|
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 ','
|
return tmp[:-1] # Remove last comma ','
|
||||||
|
|
||||||
|
|||||||
@@ -620,8 +620,6 @@ function getDevicesList() {
|
|||||||
// init ordered columns
|
// init ordered columns
|
||||||
for($i = 0; $i < count($orderedColumns); $i++) {
|
for($i = 0; $i < count($orderedColumns); $i++) {
|
||||||
|
|
||||||
$oldVal = $columnOrderMapping[$i][2];
|
|
||||||
|
|
||||||
$columnOrderMapping[$i][2] = $orderedColumns[$i];
|
$columnOrderMapping[$i][2] = $orderedColumns[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -232,7 +232,7 @@
|
|||||||
{
|
{
|
||||||
"function": "CMD",
|
"function": "CMD",
|
||||||
"type": "text",
|
"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": [],
|
"options": [],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name" : [{
|
"name" : [{
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ def get_entries(newEntries):
|
|||||||
for router in routers:
|
for router in routers:
|
||||||
# snmpwalk -v 2c -c public -OXsq 192.168.1.1 .1.3.6.1.2.1.3.1.1.2
|
# snmpwalk -v 2c -c public -OXsq 192.168.1.1 .1.3.6.1.2.1.3.1.1.2
|
||||||
|
|
||||||
|
print(router)
|
||||||
|
|
||||||
timeoutSec = 10
|
timeoutSec = 10
|
||||||
|
|
||||||
# snmpwalkArgs = ['snmpwalk', '-v', '2c', '-c', 'public', '-OXsq', router, '.1.3.6.1.2.1.3.1.1.2']
|
# snmpwalkArgs = ['snmpwalk', '-v', '2c', '-c', 'public', '-OXsq', router, '.1.3.6.1.2.1.3.1.1.2']
|
||||||
|
|||||||
Reference in New Issue
Block a user