Add VPN status to status bar
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
c7f0bda701
commit
94be1742d3
2 changed files with 49 additions and 1 deletions
|
@ -56,8 +56,11 @@ interval=30
|
|||
[load]
|
||||
interval=30
|
||||
|
||||
[vpn]
|
||||
interval=5
|
||||
|
||||
[wifi]
|
||||
interval=30
|
||||
interval=5
|
||||
|
||||
[battery]
|
||||
interval=10
|
||||
|
|
45
.config/i3blocks/vpn
Executable file
45
.config/i3blocks/vpn
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
|
||||
def check_ping_reachable(ip):
|
||||
try:
|
||||
subprocess.check_call(['ping', '-c2', ip],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL)
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
||||
|
||||
def check_service_active(service):
|
||||
try:
|
||||
subprocess.check_call(['systemctl', 'status', service],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL)
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
config = yaml.load(open(Path('~/.config/i3-vpn.json').expanduser()))
|
||||
results = [config['prefix']]
|
||||
|
||||
for check in config['checks']:
|
||||
if check_service_active(check['service']) and check_ping_reachable(check['ip']):
|
||||
check['color'] = config['colors']['success']
|
||||
else:
|
||||
check['color'] = config['colors']['failure']
|
||||
|
||||
results.append(config['template'].format(**check))
|
||||
|
||||
print(' '.join(results))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
Loading…
Reference in a new issue