Made the openvpn module more flexible by allowing custom status commands, making it compatible with networkmanager based VPNs. Also changed the spelling of colour_down and colour_up to color so the module is the same as all of the others

This commit is contained in:
Holden Salomon 2016-02-11 12:00:49 -05:00
parent 8e3857ccd0
commit 8254eaf43e

View File

@ -23,7 +23,7 @@ class OpenVPN(IntervalModule):
status_up = ''
status_down = ''
format = "{vpn_name} {status}"
status_command = "bash -c \"systemctl show openvpn@%(vpn_name)s | grep -oP 'ActiveState=\K(\w+)'\""
status_command = "bash -c \"systemctl show openvpn@%(vpn_name)s | grep 'ActiveState=active'"
label = ''
vpn_name = ''
@ -35,6 +35,7 @@ class OpenVPN(IntervalModule):
("status_down", "Symbol to display when down"),
("status_up", "Symbol to display when up"),
("vpn_name", "Name of VPN"),
("status_command", "command to find out if the VPN is active"),
)
def init(self):
@ -45,7 +46,7 @@ class OpenVPN(IntervalModule):
command_result = run_through_shell(self.status_command % {'vpn_name': self.vpn_name}, enable_shell=True)
output = command_result.out.strip()
if output == 'active':
if output:
color = self.color_up
status = self.status_up
else: