summaryrefslogtreecommitdiffstats
path: root/python.d/freeradius.chart.py
diff options
context:
space:
mode:
Diffstat (limited to 'python.d/freeradius.chart.py')
-rw-r--r--python.d/freeradius.chart.py101
1 files changed, 59 insertions, 42 deletions
diff --git a/python.d/freeradius.chart.py b/python.d/freeradius.chart.py
index f3de15735..3acc58d1a 100644
--- a/python.d/freeradius.chart.py
+++ b/python.d/freeradius.chart.py
@@ -2,15 +2,19 @@
# Description: freeradius netdata python.d module
# Author: l2isbad
-from base import SimpleService
from re import findall
from subprocess import Popen, PIPE
+from bases.collection import find_binary
+from bases.FrameworkServices.SimpleService import SimpleService
+
# default module values (can be overridden per job in `config`)
priority = 60000
retries = 60
update_every = 15
+RADIUS_MSG = 'Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept'
+
# charts order (can be overridden if you want less charts, or different order)
ORDER = ['authentication', 'accounting', 'proxy-auth', 'proxy-acct']
@@ -18,34 +22,46 @@ CHARTS = {
'authentication': {
'options': [None, "Authentication", "packets/s", 'Authentication', 'freerad.auth', 'line'],
'lines': [
- ['access-accepts', None, 'incremental'], ['access-rejects', None, 'incremental'],
- ['auth-dropped-requests', None, 'incremental'], ['auth-duplicate-requests', None, 'incremental'],
- ['auth-invalid-requests', None, 'incremental'], ['auth-malformed-requests', None, 'incremental'],
- ['auth-unknown-types', None, 'incremental']
- ]},
- 'accounting': {
+ ['access-accepts', None, 'incremental'],
+ ['access-rejects', None, 'incremental'],
+ ['auth-dropped-requests', 'dropped-requests', 'incremental'],
+ ['auth-duplicate-requests', 'duplicate-requests', 'incremental'],
+ ['auth-invalid-requests', 'invalid-requests', 'incremental'],
+ ['auth-malformed-requests', 'malformed-requests', 'incremental'],
+ ['auth-unknown-types', 'unknown-types', 'incremental']
+ ]},
+ 'accounting': {
'options': [None, "Accounting", "packets/s", 'Accounting', 'freerad.acct', 'line'],
'lines': [
- ['accounting-requests', None, 'incremental'], ['accounting-responses', None, 'incremental'],
- ['acct-dropped-requests', None, 'incremental'], ['acct-duplicate-requests', None, 'incremental'],
- ['acct-invalid-requests', None, 'incremental'], ['acct-malformed-requests', None, 'incremental'],
- ['acct-unknown-types', None, 'incremental']
+ ['accounting-requests', 'requests', 'incremental'],
+ ['accounting-responses', 'responses', 'incremental'],
+ ['acct-dropped-requests', 'dropped-requests', 'incremental'],
+ ['acct-duplicate-requests', 'duplicate-requests', 'incremental'],
+ ['acct-invalid-requests', 'invalid-requests', 'incremental'],
+ ['acct-malformed-requests', 'malformed-requests', 'incremental'],
+ ['acct-unknown-types', 'unknown-types', 'incremental']
]},
'proxy-auth': {
'options': [None, "Proxy Authentication", "packets/s", 'Authentication', 'freerad.proxy.auth', 'line'],
'lines': [
- ['proxy-access-accepts', None, 'incremental'], ['proxy-access-rejects', None, 'incremental'],
- ['proxy-auth-dropped-requests', None, 'incremental'], ['proxy-auth-duplicate-requests', None, 'incremental'],
- ['proxy-auth-invalid-requests', None, 'incremental'], ['proxy-auth-malformed-requests', None, 'incremental'],
- ['proxy-auth-unknown-types', None, 'incremental']
+ ['proxy-access-accepts', 'access-accepts', 'incremental'],
+ ['proxy-access-rejects', 'access-rejects', 'incremental'],
+ ['proxy-auth-dropped-requests', 'dropped-requests', 'incremental'],
+ ['proxy-auth-duplicate-requests', 'duplicate-requests', 'incremental'],
+ ['proxy-auth-invalid-requests', 'invalid-requests', 'incremental'],
+ ['proxy-auth-malformed-requests', 'malformed-requests', 'incremental'],
+ ['proxy-auth-unknown-types', 'unknown-types', 'incremental']
]},
- 'proxy-acct': {
+ 'proxy-acct': {
'options': [None, "Proxy Accounting", "packets/s", 'Accounting', 'freerad.proxy.acct', 'line'],
'lines': [
- ['proxy-accounting-requests', None, 'incremental'], ['proxy-accounting-responses', None, 'incremental'],
- ['proxy-acct-dropped-requests', None, 'incremental'], ['proxy-acct-duplicate-requests', None, 'incremental'],
- ['proxy-acct-invalid-requests', None, 'incremental'], ['proxy-acct-malformed-requests', None, 'incremental'],
- ['proxy-acct-unknown-types', None, 'incremental']
+ ['proxy-accounting-requests', 'requests', 'incremental'],
+ ['proxy-accounting-responses', 'responses', 'incremental'],
+ ['proxy-acct-dropped-requests', 'dropped-requests', 'incremental'],
+ ['proxy-acct-duplicate-requests', 'duplicate-requests', 'incremental'],
+ ['proxy-acct-invalid-requests', 'invalid-requests', 'incremental'],
+ ['proxy-acct-malformed-requests', 'malformed-requests', 'incremental'],
+ ['proxy-acct-unknown-types', 'unknown-types', 'incremental']
]}
}
@@ -54,31 +70,33 @@ CHARTS = {
class Service(SimpleService):
def __init__(self, configuration=None, name=None):
SimpleService.__init__(self, configuration=configuration, name=name)
+ self.definitions = CHARTS
self.host = self.configuration.get('host', 'localhost')
self.port = self.configuration.get('port', '18121')
- self.secret = self.configuration.get('secret', 'adminsecret')
+ self.secret = self.configuration.get('secret')
self.acct = self.configuration.get('acct', False)
self.proxy_auth = self.configuration.get('proxy_auth', False)
self.proxy_acct = self.configuration.get('proxy_acct', False)
- self.echo = self.find_binary('echo')
- self.radclient = self.find_binary('radclient')
- self.sub_echo = [self.echo, 'Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept']
- self.sub_radclient = [self.radclient, '-r', '1', '-t', '1', ':'.join([self.host, self.port]), 'status', self.secret]
-
+ chart_choice = [True, bool(self.acct), bool(self.proxy_auth), bool(self.proxy_acct)]
+ self.order = [chart for chart, choice in zip(ORDER, chart_choice) if choice]
+ self.echo = find_binary('echo')
+ self.radclient = find_binary('radclient')
+ self.sub_echo = [self.echo, RADIUS_MSG]
+ self.sub_radclient = [self.radclient, '-r', '1', '-t', '1', '-x',
+ ':'.join([self.host, self.port]), 'status', self.secret]
+
def check(self):
if not all([self.echo, self.radclient]):
- self.error('Can\'t locate \'radclient\' binary or binary is not executable by netdata')
+ self.error('Can\'t locate "radclient" binary or binary is not executable by netdata')
return False
+ if not self.secret:
+ self.error('"secret" not set')
+ return None
+
if self._get_raw_data():
- chart_choice = [True, bool(self.acct), bool(self.proxy_auth), bool(self.proxy_acct)]
- self.order = [chart for chart, choice in zip(ORDER, chart_choice) if choice]
- self.definitions = dict([chart for chart in CHARTS.items() if chart[0] in self.order])
- self.info('Plugin was started succesfully')
return True
- else:
- self.error('Request returned no data. Is server alive? Used options: host {0}, port {1}, secret {2}'.format(self.host, self.port, self.secret))
- return False
-
+ self.error('Request returned no data. Is server alive?')
+ return False
def _get_data(self):
"""
@@ -91,7 +109,8 @@ class Service(SimpleService):
def _get_raw_data(self):
"""
The following code is equivalent to
- 'echo "Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept" | radclient -t 1 -r 1 host:port status secret'
+ 'echo "Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept"
+ | radclient -t 1 -r 1 host:port status secret'
:return: str
"""
try:
@@ -99,10 +118,8 @@ class Service(SimpleService):
process_rad = Popen(self.sub_radclient, stdin=process_echo.stdout, stdout=PIPE, stderr=PIPE, shell=False)
process_echo.stdout.close()
raw_result = process_rad.communicate()[0]
- except Exception:
+ except OSError:
return None
- else:
- if process_rad.returncode is 0:
- return raw_result.decode()
- else:
- return None
+ if process_rad.returncode is 0:
+ return raw_result.decode()
+ return None