From 50485bedfd9818165aa1d039d0abe95a559134b7 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 8 Feb 2019 08:31:03 +0100 Subject: Merging upstream version 1.12.0. Signed-off-by: Daniel Baumann --- collectors/python.d.plugin/freeradius/README.md | 2 + .../python.d.plugin/freeradius/freeradius.chart.py | 108 +++++++++++++++------ .../python.d.plugin/freeradius/freeradius.conf | 10 +- 3 files changed, 84 insertions(+), 36 deletions(-) (limited to 'collectors/python.d.plugin/freeradius') diff --git a/collectors/python.d.plugin/freeradius/README.md b/collectors/python.d.plugin/freeradius/README.md index e5fe88ec3..00eb50dff 100644 --- a/collectors/python.d.plugin/freeradius/README.md +++ b/collectors/python.d.plugin/freeradius/README.md @@ -68,3 +68,5 @@ To do this, create a link from the sites-enabled directory to the status file in and restart/reload your FREERADIUS server. --- + +[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fcollectors%2Fpython.d.plugin%2Ffreeradius%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]() diff --git a/collectors/python.d.plugin/freeradius/freeradius.chart.py b/collectors/python.d.plugin/freeradius/freeradius.chart.py index 3126831b7..8563660cc 100644 --- a/collectors/python.d.plugin/freeradius/freeradius.chart.py +++ b/collectors/python.d.plugin/freeradius/freeradius.chart.py @@ -3,25 +3,37 @@ # Author: l2isbad # SPDX-License-Identifier: GPL-3.0-or-later -from re import findall +import re 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 +PARSER = re.compile(r'((?<=-)[AP][a-zA-Z-]+) = (\d+)') + 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'] +RADCLIENT_RETRIES = 1 +RADCLIENT_TIMEOUT = 1 + +DEFAULT_HOST = 'localhost' +DEFAULT_PORT = 18121 +DEFAULT_DO_ACCT = False +DEFAULT_DO_PROXY_AUTH = False +DEFAULT_DO_PROXY_ACCT = False + +ORDER = [ + 'authentication', + 'accounting', + 'proxy-auth', + 'proxy-acct', +] CHARTS = { 'authentication': { - 'options': [None, 'Authentication', 'packets/s', 'Authentication', 'freerad.auth', 'line'], + 'options': [None, 'Authentication', 'packets/s', 'authentication', 'freerad.auth', 'line'], 'lines': [ ['access-accepts', None, 'incremental'], ['access-rejects', None, 'incremental'], @@ -33,7 +45,7 @@ CHARTS = { ] }, 'accounting': { - 'options': [None, 'Accounting', 'packets/s', 'Accounting', 'freerad.acct', 'line'], + 'options': [None, 'Accounting', 'packets/s', 'accounting', 'freerad.acct', 'line'], 'lines': [ ['accounting-requests', 'requests', 'incremental'], ['accounting-responses', 'responses', 'incremental'], @@ -45,7 +57,7 @@ CHARTS = { ] }, 'proxy-auth': { - 'options': [None, 'Proxy Authentication', 'packets/s', 'Authentication', 'freerad.proxy.auth', 'line'], + 'options': [None, 'Proxy Authentication', 'packets/s', 'authentication', 'freerad.proxy.auth', 'line'], 'lines': [ ['proxy-access-accepts', 'access-accepts', 'incremental'], ['proxy-access-rejects', 'access-rejects', 'incremental'], @@ -57,7 +69,7 @@ CHARTS = { ] }, 'proxy-acct': { - 'options': [None, 'Proxy Accounting', 'packets/s', 'Accounting', 'freerad.proxy.acct', 'line'], + 'options': [None, 'Proxy Accounting', 'packets/s', 'accounting', 'freerad.proxy.acct', 'line'], 'lines': [ ['proxy-accounting-requests', 'requests', 'incremental'], ['proxy-accounting-responses', 'responses', 'incremental'], @@ -71,46 +83,80 @@ CHARTS = { } +def radclient_status(radclient, retries, timeout, host, port, secret): + # radclient -r 1 -t 1 -x 127.0.0.1:18121 status secret + + return '{radclient} -r {num_retries} -t {timeout} -x {host}:{port} status {secret}'.format( + radclient=radclient, + num_retries=retries, + timeout=timeout, + host=host, + port=port, + secret=secret, + ).split() + + class Service(SimpleService): def __init__(self, configuration=None, name=None): SimpleService.__init__(self, configuration=configuration, name=name) + self.order = ORDER self.definitions = CHARTS - self.host = self.configuration.get('host', 'localhost') - self.port = self.configuration.get('port', '18121') + self.host = self.configuration.get('host', DEFAULT_HOST) + self.port = self.configuration.get('port', DEFAULT_PORT) 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) - 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.do_acct = self.configuration.get('acct', DEFAULT_DO_ACCT) + self.do_proxy_auth = self.configuration.get('proxy_auth', DEFAULT_DO_PROXY_AUTH) + self.do_proxy_acct = self.configuration.get('proxy_acct', DEFAULT_DO_PROXY_ACCT) 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] + self.sub_radclient = radclient_status( + self.radclient, RADCLIENT_RETRIES, RADCLIENT_TIMEOUT, self.host, self.port, 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') + if not self.radclient: + self.error("Can't locate 'radclient' binary or binary is not executable by netdata user") return False + + if not self.echo: + self.error("Can't locate 'echo' binary or binary is not executable by netdata user") + return None + if not self.secret: - self.error('"secret" not set') + self.error("'secret' isn't set") return None - if self._get_raw_data(): - return True - self.error('Request returned no data. Is server alive?') - return False + if not self.get_raw_data(): + self.error('Request returned no data. Is server alive?') + return False - def _get_data(self): + if not self.do_acct: + self.order.remove('accounting') + + if not self.do_proxy_auth: + self.order.remove('proxy-auth') + + if not self.do_proxy_acct: + self.order.remove('proxy-acct') + + return True + + def get_data(self): """ Format data received from shell command :return: dict """ - result = self._get_raw_data() - return dict([(elem[0].lower(), int(elem[1])) for elem in findall(r'((?<=-)[AP][a-zA-Z-]+) = (\d+)', result)]) + result = self.get_raw_data() - def _get_raw_data(self): + if not result: + return None + + return dict( + (key.lower(), value) for key, value in PARSER.findall(result) + ) + + def get_raw_data(self): """ The following code is equivalent to 'echo "Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept" @@ -124,6 +170,8 @@ class Service(SimpleService): raw_result = process_rad.communicate()[0] except OSError: return None + if process_rad.returncode is 0: return raw_result.decode() + return None diff --git a/collectors/python.d.plugin/freeradius/freeradius.conf b/collectors/python.d.plugin/freeradius/freeradius.conf index 3336d4c49..74b273776 100644 --- a/collectors/python.d.plugin/freeradius/freeradius.conf +++ b/collectors/python.d.plugin/freeradius/freeradius.conf @@ -27,11 +27,9 @@ # If unset, the default for python.d.plugin is used. # priority: 60000 -# retries sets the number of retries to be made in case of failures. -# If unset, the default for python.d.plugin is used. -# Attempts to restore the service are made once every update_every -# and only if the module has collected values in the past. -# retries: 60 +# penalty indicates whether to apply penalty to update_every in case of failures. +# Penalty will increase every 5 failed updates in a row. Maximum penalty is 10 minutes. +# penalty: yes # autodetection_retry sets the job re-check interval in seconds. # The job is not deleted if check fails. @@ -58,7 +56,7 @@ # # JOBs sharing a name are mutually exclusive # update_every: 1 # the JOB's data collection frequency # priority: 60000 # the JOB's order on the dashboard -# retries: 60 # the JOB's number of restoration attempts +# penalty: yes # the JOB's penalty # autodetection_retry: 0 # the JOB's re-check interval in seconds # # Additionally to the above, freeradius also supports the following: -- cgit v1.2.3