42 lines
861 B
Python
42 lines
861 B
Python
|
class openvpnstatus(object):
|
||
|
"""read the openvpn-status.log file"""
|
||
|
|
||
|
def __init__(self):
|
||
|
self.update()
|
||
|
|
||
|
def update(self):
|
||
|
"""read file"""
|
||
|
|
||
|
import os
|
||
|
|
||
|
self.connections = []
|
||
|
self.routes = []
|
||
|
|
||
|
f = open("openvpn-status.log", "r")
|
||
|
|
||
|
state = 0
|
||
|
for line in f:
|
||
|
|
||
|
if "Updated" in line:
|
||
|
state = 1
|
||
|
continue
|
||
|
elif "ROUTING" in line:
|
||
|
state = 2
|
||
|
continue
|
||
|
elif "GLOBAL" in line:
|
||
|
state = 0
|
||
|
break
|
||
|
|
||
|
if state == 1:
|
||
|
fields = line.split(",")
|
||
|
self.connections.append(fields)
|
||
|
elif state == 2:
|
||
|
fields = line.split(",")
|
||
|
self.routes.append(fields)
|
||
|
|
||
|
f.close()
|
||
|
|
||
|
|
||
|
|
||
|
#end of file
|