def run(api, ts=False): """ Returns IRQ LLD JSON :param api: initialized librouteros' connect() :param ts: Use timestamps :return: """ if ts: unixtime = " {time} ".format(time=int(time.time())) else: unixtime = " " irqstats = api(cmd='/system/resource/irq/print') peers = [] for irqitem in irqstats: peers.append({ '{#IRQ}': irqitem.get('users').replace(",", "__"), }) # Composing JSON to return json_data = {'data': peers} # Return JSON print "{host} {key}{unixtime}{value}".format(host='-', key='mikrotik.irq.discovery', unixtime=unixtime, value=zabbix_escape( json.dumps(json_data)))
def run(api, ts=False): """ Returns Radius LLD JSON :param api: initialized librouteros' connect() :param ts: Use timestamps :return: """ if ts: unixtime = " {time} ".format(time=int(time.time())) else: unixtime = " " radservers = api(cmd='/radius/print') servers = [] for s in radservers: servers.append({ '{#MTIK_RADIUS_ID}': strip(s.get('.id'), '*'), '{#MTIK_RADIUS_COMMENT}': s.get('comment', s.get('.id')), '{#MTIK_RADIUS_ADDRESS}': s.get('address'), }) # Composing JSON to return json_data = {'data': servers} # Return JSON print "{host} {key}{unixtime}{value}".format( host='-', key='mikrotik.radius-out.discovery', unixtime=unixtime, value=zabbix_escape(json.dumps(json_data)))
def run(api, ts=False, log=getLogger(__name__)): """ Returns BGP LLD JSON :param api: initialized librouteros' connect() :param ts: Use timestamps :return: """ if ts: unixtime = " {time} ".format(time=int(time.time())) else: unixtime = " " bgpstats = api(cmd='/routing/bgp/peer/print') peers = [] for bgpitem in bgpstats: peers.append({ '{#PEERNAME}': bgpitem.get('name'), '{#PEERCOMMENT}': bgpitem.get('comment', ''), '{#PEERAS}': bgpitem.get('remote-as'), '{#PEERLOCALADDR}': bgpitem.get('local-address'), '{#PEERREMOTEADDR}': bgpitem.get('remote-address'), '{#PEERREMOTEID}': bgpitem.get('remote-id'), }) # Composing JSON to return json_data = {'data': peers} # Return JSON print "{host} {key}{unixtime}{value}".format(host='-', key='mikrotik.bgp.discovery', unixtime=unixtime, value=zabbix_escape( json.dumps(json_data)))
def run(api, ts=False, log=getLogger(__name__)): """ Returns Firewall Rules LLD JSON :param api: initialized librouteros' connect() :param ts: Use timestamps :return: """ pp = pprint.PrettyPrinter(indent=4) if ts: unixtime = " {time} ".format(time=int(time.time())) else: unixtime = " " # Fetch firewall stats tables = ["filter", "nat", "mangle", "raw"] lld = [] for t in tables: log.debug("Processing {table} firewall table".format(table=t)) cmd = '/ip/firewall/{table}/print'.format(table=t) log.debug(pp.pformat(cmd)) stats = api(cmd=cmd, stats=True) for rule in stats: # We don't want ALL the rules here. We want only those, which has ZBX at the beginning of the comment comment = rule.get('comment', '') if not comment.startswith('ZBX'): continue lld.append({ '{#MTIK_FW_RULE_ID}': t + '_' + strip(rule.get('.id'), '*'), '{#MTIK_FW_RULE_COMMENT}': rule.get('comment', rule.get('.id')) }) # Composing JSON to return json_data = {'data': lld} # Return JSON print "{host} {key}{unixtime}{value}".format( host='-', key='mikrotik.firewall.discovery', unixtime=unixtime, value=zabbix_escape(json.dumps(json_data)))
def run(api, ts=False): """ Returns IRQ Counters :param api: initialized librouteros' connect() :param ts: Use timestamps :return: """ if ts: unixtime = " {time} ".format(time=int(time.time())) else: unixtime = " " irqstats = api(cmd='/system/resource/irq/print') for irqitem in irqstats: print "{host} \"{key}\"{unixtime}{value}".format( host='-', key='mikrotik.irq[' + irqitem.get('users').replace(",", "__") + ']', unixtime=unixtime, value=zabbix_escape(irqitem['count']))
def run(api, ts=False): """ Returns BGP Counters :param api: initialized librouteros' connect() :param ts: Use timestamps :return: """ if ts: unixtime = " {time} ".format(time=int(time.time())) else: unixtime = " " bgpstats = api(cmd='/routing/bgp/peer/print') # The list of BGP values to monitor values_to_monitor = [ 'remote-as', # Remote AS for peer 'prefix-count', # Accepted Prefixes 'disabled', # Administrative status # 'uptime', # Established time for peer 'comment', # Printing the comment 'updates-received', # Updates Received 'updates-sent', # Updates Sent 'withdrawn-received', # Withdrawn Received 'withdrawn-sent' # Withdrawn Sent ] for bgpitem in bgpstats: for val in values_to_monitor: print "{host} \"{key}\"{unixtime}{value}".format( host='-', key='mikrotik.bgp.node[{name},{val}]'.format( name=bgpitem['name'], val=val), unixtime=unixtime, value=zabbix_escape(bgpitem.get(val, 0))) # operational status if bgpitem['state'] == "idle": bgp_state = 1 elif bgpitem['state'] == "connect": bgp_state = 2 elif bgpitem['state'] == "active": bgp_state = 3 elif bgpitem['state'] == "opensent": bgp_state = 4 elif bgpitem['state'] == "openconfirm": bgp_state = 5 elif bgpitem['state'] == "established": bgp_state = 6 else: bgp_state = 0 print "{host} \"{key}\"{unixtime}{value}".format( host='-', key='mikrotik.bgp.node[{name},state]'.format(name=bgpitem['name']), unixtime=unixtime, value=zabbix_escape(bgp_state)) # Established time for peer print "{host} \"{key}\"{unixtime}{value}".format( host='-', key='mikrotik.bgp.node[{name},uptime]'.format( name=bgpitem['name']), unixtime=unixtime, #value=bgpitem['uptime'] value=zabbix_escape(time_convert(bgpitem['uptime'])))
def run(api, ts=False): """ Returns Radius Counters :param api: initialized librouteros' connect() :param ts: Use timestamps :return: """ if ts: unixtime = " {time} ".format(time=int(time.time())) else: unixtime = " " # Fetch Incoming (CoA) stats # ({ u'acks': 263085, u'bad-requests': 0, u'naks': 11304, u'requests': 274388},) coastats = api(cmd='/radius/incoming/monitor', once=True) coa_values_to_monitor = [ 'acks', # Acknowledged 'bad-requests', # Bad Requests 'naks', # Rejects 'requests' # Requests ] for coaitem in coastats: for val in coa_values_to_monitor: print "{host} \"{key}\"{unixtime}{value}".format( host='-', key='mikrotik.radius-in.coa[{val}]'.format(val=val), unixtime=unixtime, value=zabbix_escape(coaitem.get(val, 0))) # We need to figure out which Radius settings do we have radservers = api(cmd='/radius/print') # pp = pprint.PrettyPrinter(indent=4) # pp.pprint(radservers) radius_values_to_monitor = [ 'accepts', # Accepts 'bad-replies', # Bad Replies 'pending', # Pending 'rejects', # Rejects 'requests', # Requests 'resends', # Resends 'timeouts', # Timeouts # 'comment' ] for server in radservers: # Lets fetch the stats for the every server params = {'.id': server.get('.id')} stats = api(cmd='/radius/monitor', once=True, **params) # pp.pprint(stats) for item in stats: for val in radius_values_to_monitor: print "{host} \"{key}\"{unixtime}{value}".format( host='-', key='mikrotik.radius-out.node[' + strip(server.get('.id'), '*') + ',' + val + ']', unixtime=unixtime, value=zabbix_escape(item.get(val)))