summaryrefslogtreecommitdiffstats
path: root/collectors/python.d.plugin/ovpn_status_log/ovpn_status_log.chart.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--collectors/python.d.plugin/ovpn_status_log/ovpn_status_log.chart.py (renamed from python.d/ovpn_status_log.chart.py)27
1 files changed, 19 insertions, 8 deletions
diff --git a/python.d/ovpn_status_log.chart.py b/collectors/python.d.plugin/ovpn_status_log/ovpn_status_log.chart.py
index 519c77fa3..64d7062d9 100644
--- a/python.d/ovpn_status_log.chart.py
+++ b/collectors/python.d.plugin/ovpn_status_log/ovpn_status_log.chart.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Description: openvpn status log netdata python.d module
# Author: l2isbad
+# SPDX-License-Identifier: GPL-3.0-or-later
from re import compile as r_compile
@@ -16,15 +17,19 @@ CHARTS = {
'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]
- ]},
-
+ ]
+ }
}
+TLS_REGEX = r_compile(r'(?:[0-9a-f:]+|(?:\d{1,3}(?:\.\d{1,3}){3}(?::\d+)?)) (?P<bytes_in>\d+) (?P<bytes_out>\d+)')
+STATIC_KEY_REGEX = r_compile(r'TCP/[A-Z]+ (?P<direction>(?:read|write)) bytes,(?P<bytes>\d+)')
+
class Service(SimpleService):
def __init__(self, configuration=None, name=None):
@@ -32,8 +37,10 @@ class Service(SimpleService):
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+)'))
+ self.regex = {
+ 'tls': TLS_REGEX,
+ 'static_key': STATIC_KEY_REGEX
+ }
def check(self):
if not (self.log_path and isinstance(self.log_path, str)):
@@ -57,7 +64,7 @@ class Service(SimpleService):
break
if found:
return True
- self.error("Failed to parse ovpenvpn log file")
+ self.error('Failed to parse ovpenvpn log file')
return False
def _get_raw_data(self):
@@ -107,8 +114,12 @@ class Service(SimpleService):
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)
+ columns = row.split(',') if ',' in row else row.split()
+ if 'UNDEF' in columns:
+ # see https://openvpn.net/archive/openvpn-users/2004-08/msg00116.html
+ continue
+
+ match = self.regex['tls'].search(' '.join(columns))
if match:
match = match.groupdict()
data['users'] += 1