-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathradius.py
79 lines (67 loc) · 2.28 KB
/
radius.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: UTF-8 -*-
"""
This module pokes Mikrotik for Radius Counters
"""
import time
# import pprint
from libs.strings import zabbix_escape
from logging import getLogger
def run(api, ts=False, log=getLogger(__name__), ver=''):
"""
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[' + server.get('.id').strip('*') + ',' + val + ']',
unixtime=unixtime,
value=zabbix_escape(item.get(val))
))