@cryptotaxi247 / netdata-1 / commits / 823797426

"freeradius" fixes and module conf update

lgz committed Oct 13, 2017 at 23:04 UTC 823797426c2aad897fd01597b0ae013747316497
2 files changed +63 -48
conf.d/python.d/freeradius.conf
+7 -7
@@ -59,9 +59,9 @@
59 # host: 'host' # Default: 'localhost'. Server ip address or hostname.
60 # port: 'port' # Default: '18121'. Port on which freeradius server listen (type = status).
61 # secret: 'secret' # Default: 'adminsecret'.
62 -# acct: True/False # Defalt: False. Freeradius accounting statistics.
63 -# proxy_auth: True/False # Default: False. Freeradius proxy authentication statistics.
64 -# proxy_acct: True/False # Default: False. Freeradius proxy accounting statistics.
62 +# acct: yes/no # Default: no. Freeradius accounting statistics.
63 +# proxy_auth: yes/no # Default: no. Freeradius proxy authentication statistics.
64 +# proxy_acct: yes/no # Default: no. Freeradius proxy accounting statistics.
65 #
66 # ------------------------------------------------------------------------------------------------------------------
67 # Freeradius server configuration:
@@ -80,7 +80,7 @@
80 local:
81 host: 'localhost'
82 port: '18121'
83 - secret: 'adminsecret'
84 -#acct: False
85 -#proxy_auth: False
86 -#proxy_acct: False
83 +#secret: 'adminsecret'
84 +#acct: no
85 +#proxy_auth: no
86 +#proxy_acct: no
python.d/freeradius.chart.py
+56 -41
@@ -2,15 +2,18 @@
2 # Description: freeradius netdata python.d module
3 # Author: l2isbad
4
5 -from base import SimpleService
5 from re import findall
6 from subprocess import Popen, PIPE
7
8 +from bases.FrameworkServices.SimpleService import SimpleService
9 +
10 # default module values (can be overridden per job in `config`)
11 priority = 60000
12 retries = 60
13 update_every = 15
14
15 +RADIUS_MSG = 'Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept'
16 +
17 # charts order (can be overridden if you want less charts, or different order)
18 ORDER = ['authentication', 'accounting', 'proxy-auth', 'proxy-acct']
19
@@ -18,34 +21,46 @@ CHARTS = {
21 'authentication': {
22 'options': [None, "Authentication", "packets/s", 'Authentication', 'freerad.auth', 'line'],
23 'lines': [
21 - ['access-accepts', None, 'incremental'], ['access-rejects', None, 'incremental'],
22 - ['auth-dropped-requests', None, 'incremental'], ['auth-duplicate-requests', None, 'incremental'],
23 - ['auth-invalid-requests', None, 'incremental'], ['auth-malformed-requests', None, 'incremental'],
24 - ['auth-unknown-types', None, 'incremental']
25 - ]},
26 - 'accounting': {
24 + ['access-accepts', None, 'incremental'],
25 + ['access-rejects', None, 'incremental'],
26 + ['auth-dropped-requests', 'dropped-requests', 'incremental'],
27 + ['auth-duplicate-requests', 'duplicate-requests', 'incremental'],
28 + ['auth-invalid-requests', 'invalid-requests', 'incremental'],
29 + ['auth-malformed-requests', 'malformed-requests', 'incremental'],
30 + ['auth-unknown-types', 'unknown-types', 'incremental']
31 + ]},
32 + 'accounting': {
33 'options': [None, "Accounting", "packets/s", 'Accounting', 'freerad.acct', 'line'],
34 'lines': [
29 - ['accounting-requests', None, 'incremental'], ['accounting-responses', None, 'incremental'],
30 - ['acct-dropped-requests', None, 'incremental'], ['acct-duplicate-requests', None, 'incremental'],
31 - ['acct-invalid-requests', None, 'incremental'], ['acct-malformed-requests', None, 'incremental'],
32 - ['acct-unknown-types', None, 'incremental']
35 + ['accounting-requests', 'requests', 'incremental'],
36 + ['accounting-responses', 'responses', 'incremental'],
37 + ['acct-dropped-requests', 'dropped-requests', 'incremental'],
38 + ['acct-duplicate-requests', 'duplicate-requests', 'incremental'],
39 + ['acct-invalid-requests', 'invalid-requests', 'incremental'],
40 + ['acct-malformed-requests', 'malformed-requests', 'incremental'],
41 + ['acct-unknown-types', 'unknown-types', 'incremental']
42 ]},
43 'proxy-auth': {
44 'options': [None, "Proxy Authentication", "packets/s", 'Authentication', 'freerad.proxy.auth', 'line'],
45 'lines': [
37 - ['proxy-access-accepts', None, 'incremental'], ['proxy-access-rejects', None, 'incremental'],
38 - ['proxy-auth-dropped-requests', None, 'incremental'], ['proxy-auth-duplicate-requests', None, 'incremental'],
39 - ['proxy-auth-invalid-requests', None, 'incremental'], ['proxy-auth-malformed-requests', None, 'incremental'],
40 - ['proxy-auth-unknown-types', None, 'incremental']
46 + ['proxy-access-accepts', 'access-accepts', 'incremental'],
47 + ['proxy-access-rejects', 'access-rejects', 'incremental'],
48 + ['proxy-auth-dropped-requests', 'dropped-requests', 'incremental'],
49 + ['proxy-auth-duplicate-requests', 'duplicate-requests', 'incremental'],
50 + ['proxy-auth-invalid-requests', 'invalid-requests', 'incremental'],
51 + ['proxy-auth-malformed-requests', 'malformed-requests', 'incremental'],
52 + ['proxy-auth-unknown-types', 'unknown-types', 'incremental']
53 ]},
42 - 'proxy-acct': {
54 + 'proxy-acct': {
55 'options': [None, "Proxy Accounting", "packets/s", 'Accounting', 'freerad.proxy.acct', 'line'],
56 'lines': [
45 - ['proxy-accounting-requests', None, 'incremental'], ['proxy-accounting-responses', None, 'incremental'],
46 - ['proxy-acct-dropped-requests', None, 'incremental'], ['proxy-acct-duplicate-requests', None, 'incremental'],
47 - ['proxy-acct-invalid-requests', None, 'incremental'], ['proxy-acct-malformed-requests', None, 'incremental'],
48 - ['proxy-acct-unknown-types', None, 'incremental']
57 + ['proxy-accounting-requests', 'requests', 'incremental'],
58 + ['proxy-accounting-responses', 'responses', 'incremental'],
59 + ['proxy-acct-dropped-requests', 'dropped-requests', 'incremental'],
60 + ['proxy-acct-duplicate-requests', 'duplicate-requests', 'incremental'],
61 + ['proxy-acct-invalid-requests', 'invalid-requests', 'incremental'],
62 + ['proxy-acct-malformed-requests', 'malformed-requests', 'incremental'],
63 + ['proxy-acct-unknown-types', 'unknown-types', 'incremental']
64 ]}
65
66 }
@@ -54,31 +69,32 @@ CHARTS = {
69 class Service(SimpleService):
70 def __init__(self, configuration=None, name=None):
71 SimpleService.__init__(self, configuration=configuration, name=name)
72 + self.definitions = CHARTS
73 self.host = self.configuration.get('host', 'localhost')
74 self.port = self.configuration.get('port', '18121')
59 - self.secret = self.configuration.get('secret', 'adminsecret')
75 + self.secret = self.configuration.get('secret')
76 self.acct = self.configuration.get('acct', False)
77 self.proxy_auth = self.configuration.get('proxy_auth', False)
78 self.proxy_acct = self.configuration.get('proxy_acct', False)
63 - self.echo = self.find_binary('echo')
64 - self.radclient = self.find_binary('radclient')
65 - self.sub_echo = [self.echo, 'Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept']
66 - self.sub_radclient = [self.radclient, '-r', '1', '-t', '1', ':'.join([self.host, self.port]), 'status', self.secret]
79 + chart_choice = [True, bool(self.acct), bool(self.proxy_auth), bool(self.proxy_acct)]
80 + self.order = [chart for chart, choice in zip(ORDER, chart_choice) if choice]
81 + self.echo = self.functions.find_binary('echo')
82 + self.radclient = self.functions.find_binary('radclient')
83 + self.sub_echo = [self.echo, RADIUS_MSG]
84 + self.sub_radclient = [self.radclient, '-r', '1', '-t', '1',
85 + ':'.join([self.host, self.port]), 'status', self.secret]
86
87 def check(self):
88 if not all([self.echo, self.radclient]):
70 - self.error('Can\'t locate \'radclient\' binary or binary is not executable by netdata')
89 + self.error('Can\'t locate "radclient" binary or binary is not executable by netdata')
90 return False
91 + if not self.secret:
92 + self.error('"secret" not set')
93 +
94 if self._get_raw_data():
73 - chart_choice = [True, bool(self.acct), bool(self.proxy_auth), bool(self.proxy_acct)]
74 - self.order = [chart for chart, choice in zip(ORDER, chart_choice) if choice]
75 - self.definitions = dict([chart for chart in CHARTS.items() if chart[0] in self.order])
76 - self.info('Plugin was started succesfully')
95 return True
78 - else:
79 - self.error('Request returned no data. Is server alive? Used options: host {0}, port {1}, secret {2}'.format(self.host, self.port, self.secret))
80 - return False
81 -
96 + self.error('Request returned no data. Is server alive?')
97 + return False
98
99 def _get_data(self):
100 """
@@ -91,7 +107,8 @@ class Service(SimpleService):
107 def _get_raw_data(self):
108 """
109 The following code is equivalent to
94 - 'echo "Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept" | radclient -t 1 -r 1 host:port status secret'
110 + 'echo "Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept"
111 + | radclient -t 1 -r 1 host:port status secret'
112 :return: str
113 """
114 try:
@@ -99,10 +116,8 @@ class Service(SimpleService):
116 process_rad = Popen(self.sub_radclient, stdin=process_echo.stdout, stdout=PIPE, stderr=PIPE, shell=False)
117 process_echo.stdout.close()
118 raw_result = process_rad.communicate()[0]
102 - except Exception:
119 + except OSError:
120 return None
104 - else:
105 - if process_rad.returncode is 0:
106 - return raw_result.decode()
107 - else:
108 - return None
121 + if process_rad.returncode is 0:
122 + return raw_result.decode()
123 + return None