summaryrefslogtreecommitdiffstats
path: root/python.d/ovpn_status_log.chart.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2018-11-07 12:22:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2018-11-07 12:22:44 +0000
commit1e6c93250172946eeb38e94a92a1fd12c9d3011e (patch)
tree8ca5e16dfc7ad6b3bf2738ca0a48408a950f8f7e /python.d/ovpn_status_log.chart.py
parentUpdate watch file (diff)
downloadnetdata-1e6c93250172946eeb38e94a92a1fd12c9d3011e.tar.xz
netdata-1e6c93250172946eeb38e94a92a1fd12c9d3011e.zip
Merging upstream version 1.11.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'python.d/ovpn_status_log.chart.py')
-rw-r--r--python.d/ovpn_status_log.chart.py118
1 files changed, 0 insertions, 118 deletions
diff --git a/python.d/ovpn_status_log.chart.py b/python.d/ovpn_status_log.chart.py
deleted file mode 100644
index 519c77fa3..000000000
--- a/python.d/ovpn_status_log.chart.py
+++ /dev/null
@@ -1,118 +0,0 @@
-# -*- coding: utf-8 -*-
-# Description: openvpn status log netdata python.d module
-# Author: l2isbad
-
-from re import compile as r_compile
-
-from bases.FrameworkServices.SimpleService import SimpleService
-
-priority = 60000
-retries = 60
-update_every = 10
-
-ORDER = ['users', 'traffic']
-CHARTS = {
- 'users': {
- 'options': [None, 'OpenVPN Active Users', 'active users', 'users', 'openvpn_status.users', 'line'],
- 'lines': [
- ['users', None, 'absolute'],
- ]},
- 'traffic': {
- 'options': [None, 'OpenVPN Traffic', 'KB/s', 'traffic', 'openvpn_status.traffic', 'area'],
- 'lines': [
- ['bytes_in', 'in', 'incremental', 1, 1 << 10], ['bytes_out', 'out', 'incremental', 1, -1 << 10]
- ]},
-
-}
-
-
-class Service(SimpleService):
- def __init__(self, configuration=None, name=None):
- SimpleService.__init__(self, configuration=configuration, name=name)
- self.order = ORDER
- self.definitions = CHARTS
- self.log_path = self.configuration.get('log_path')
- self.regex = dict(tls=r_compile(r'\d{1,3}(?:\.\d{1,3}){3}(?::\d+)? (?P<bytes_in>\d+) (?P<bytes_out>\d+)'),
- static_key=r_compile(r'TCP/[A-Z]+ (?P<direction>(?:read|write)) bytes,(?P<bytes>\d+)'))
-
- def check(self):
- if not (self.log_path and isinstance(self.log_path, str)):
- self.error("'log_path' is not defined")
- return False
-
- data = self._get_raw_data()
- if not data:
- self.error('Make sure that the openvpn status log file exists and netdata has permission to read it')
- return None
-
- found = None
- for row in data:
- if 'ROUTING' in row:
- self.get_data = self.get_data_tls
- found = True
- break
- elif 'STATISTICS' in row:
- self.get_data = self.get_data_static_key
- found = True
- break
- if found:
- return True
- self.error("Failed to parse ovpenvpn log file")
- return False
-
- def _get_raw_data(self):
- """
- Open log file
- :return: str
- """
-
- try:
- with open(self.log_path) as log:
- raw_data = log.readlines() or None
- except OSError:
- return None
- else:
- return raw_data
-
- def get_data_static_key(self):
- """
- Parse openvpn-status log file.
- """
-
- raw_data = self._get_raw_data()
- if not raw_data:
- return None
-
- data = dict(bytes_in=0, bytes_out=0)
-
- for row in raw_data:
- match = self.regex['static_key'].search(row)
- if match:
- match = match.groupdict()
- if match['direction'] == 'read':
- data['bytes_in'] += int(match['bytes'])
- else:
- data['bytes_out'] += int(match['bytes'])
-
- return data or None
-
- def get_data_tls(self):
- """
- Parse openvpn-status log file.
- """
-
- raw_data = self._get_raw_data()
- if not raw_data:
- return None
-
- data = dict(users=0, bytes_in=0, bytes_out=0)
- for row in raw_data:
- row = ' '.join(row.split(',')) if ',' in row else ' '.join(row.split())
- match = self.regex['tls'].search(row)
- if match:
- match = match.groupdict()
- data['users'] += 1
- data['bytes_in'] += int(match['bytes_in'])
- data['bytes_out'] += int(match['bytes_out'])
-
- return data or None