Thanks for your support @slashdoom!
That script guided me to create the one I need.
#!/usr/bin/env python
import argparse
import sys
from napalm import get_network_driver
def open_connection(host,username,password,device_type):
driver = get_network_driver(device_type)
device = driver(host,username,password,optional_args = {'secret': password})
device.open()
return device
def show_policy_map(connection,police):
command = ['sh service-policy police | begin {}'.format(police)]
output = connection.cli(command)
return output
def main(args):
asa = open_connection(args.H, args.u, args.p, 'asa')
text = show_policy_map(asa, args.l)
lista = list(text.values())
lista2 = lista[0].splitlines()
input_exceeded_pkts = lista2[4].split()
output_exceeded_pkts = lista2[9].split()
input_exceeded_bps = lista2[5].split()
#print input_exceeded_bps
output_exceeded_bps = lista2[10].split()
#print output_exceeded_bps
cir = lista2[2].split()
#print cir
w_cir = int(cir[1]) * args.w / 100
#print w_cir
c_cir = int(cir[1]) * args.c / 100
#print c_cir
status = [0, 'OK']
if int(input_exceeded_bps[4]) or int(output_exceeded_bps[4]) >= w_cir: status = [1, 'WARNING']
if int(input_exceeded_bps[4]) or int(output_exceeded_bps[4]) >= c_cir: status = [2, 'CRITICAL']
# Printout input data
# This is the expected format:
# STATUS: 'label'=value[UOM];[warn];[crit];[min];[max]
print("{}: {}|'IN_pkts'={} 'OUT_pkts'={}".format(
status[1],
str(args.l),
input_exceeded_pkts[1],
output_exceeded_pkts[1],
))
return status[0]
if __name__ == '__main__':
# Setup CLI arugments
parser = argparse.ArgumentParser(prog='check_webfilter-input.py')
parser.add_argument('-H', help='hostname', type=str)
parser.add_argument('-w', help='warning threshold (%cir)', type=int)
parser.add_argument('-c', help='critical threshold (%cir)', type=int)
parser.add_argument('-u', help='username', type=str)
parser.add_argument('-p', help='password', type=str)
parser.add_argument('-l', help='police name', type=str)
args = parser.parse_args()
sys.exit(main(args))
A service debug gives:
/opt/librenms$ sudo ./check-services.php -d
DEBUG!
Starting service polling run:
SQL[SELECT D.*,S.*,attrib_value FROM `devices` AS D INNER JOIN `services` AS S ON S.device_id = D.device_id AND D.disabled = 0 LEFT JOIN `devices_attribs` as A ON D.device_id = A.device_id AND A.attrib_type = "override_icmp_disable" ORDER by D.device_id DESC; [] 1.34ms]
Nagios Service - 4
Request: '/opt/librenms/nagios/plugins/check_asa-service-policy' '-H' 'hua-pil-fw1' '-w' '10' '-c' '20' '-u' 'user' '-p' 'pass' '-l' 'WebFilter_rate_limit'
Perf Data - DS: IN_pkts, Value: 3374799, UOM:
Perf Data - DS: OUT_pkts, Value: 107931, UOM:
Response: OK: WebFilter_rate_limit
Service DS: {
"IN_pkts": "",
"OUT_pkts": ""
}
RRD[last hua-pil-fw1/services-4.rrd --daemon unix:/var/run/rrdcached.sock]
RRD[create hua-pil-fw1/services-4.rrd --step 300 DS:IN_pkts:GAUGE:600:0:U DS:OUT_pkts:GAUGE:600:0:U RRA:AVERAGE:0.5:1:2016 RRA:AVERAGE:0.5:6:1440 RRA:AVERAGE:0.5:24:1440 RRA:AVERAGE:0.5:288:1440 RRA:MIN:0.5:1:720 RRA:MIN:0.5:6:1440 RRA:MIN:0.5:24:775 RRA:MIN:0.5:288:797 RRA:MAX:0.5:1:720 RRA:MAX:0.5:6:1440 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 RRA:LAST:0.5:1:1440 -O --daemon unix:/var/run/rrdcached.sock]
RRD[update hua-pil-fw1/services-4.rrd N:3374799:107931 --daemon unix:/var/run/rrdcached.sock]
./check-services.php 2019-05-31 01:38:29 - 1 services polled in 0.855 secs
Now awaiting perf data to be plotted, but until now it show NaN