Add VPN widget for tmux-collector
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
6b9a58aa25
commit
e7b3d54d0d
1 changed files with 31 additions and 0 deletions
31
bin/tmux-vpn
Executable file
31
bin/tmux-vpn
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/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', '-W1', ip],
|
||||
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 = []
|
||||
|
||||
for check in config['checks']:
|
||||
if check_ping_reachable(check['ip']):
|
||||
results.append(check['icon'])
|
||||
|
||||
print(' '.join(results))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
Loading…
Add table
Reference in a new issue