mirror of
https://github.com/roles-ansible/ansible_role_sway.git
synced 2024-08-16 13:49:49 +02:00
Create custom ping module to detect internet
This commit is contained in:
parent
a4a8a53ba5
commit
926c74b6e2
5 changed files with 68 additions and 0 deletions
|
@ -27,6 +27,7 @@ sway__waybar_modules_right:
|
||||||
- "custom/weather"
|
- "custom/weather"
|
||||||
- "pulseaudio"
|
- "pulseaudio"
|
||||||
- "network"
|
- "network"
|
||||||
|
- "custom/ping"
|
||||||
- "cpu"
|
- "cpu"
|
||||||
- "memory"
|
- "memory"
|
||||||
- "disk"
|
- "disk"
|
||||||
|
|
|
@ -27,6 +27,16 @@
|
||||||
group: "{{ swayusr.user }}"
|
group: "{{ swayusr.user }}"
|
||||||
backup: true
|
backup: true
|
||||||
|
|
||||||
|
- name: Deploy ping script
|
||||||
|
become: true
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: 'templates/ping.py.j2'
|
||||||
|
dest: "{{ swayusr.home }}/.config/waybar/ping.py"
|
||||||
|
mode: '0750'
|
||||||
|
owner: "{{ swayusr.user }}"
|
||||||
|
group: "{{ swayusr.user }}"
|
||||||
|
backup: true
|
||||||
|
|
||||||
- name: Deploy waybar stylesheet
|
- name: Deploy waybar stylesheet
|
||||||
become: true
|
become: true
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
|
|
43
templates/ping.py.j2
Normal file
43
templates/ping.py.j2
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
ping waybar widget
|
||||||
|
{{ ansible_managed }}
|
||||||
|
"""
|
||||||
|
import subprocess
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def check_internet():
|
||||||
|
"""
|
||||||
|
Try to ping a host in the internet,
|
||||||
|
then return true or false
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
subprocess.check_call(['ping', '-c', '2', 'c3woc.de'],
|
||||||
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
return True
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""
|
||||||
|
parsing internet status and create output
|
||||||
|
"""
|
||||||
|
internet_status = check_internet()
|
||||||
|
if internet_status:
|
||||||
|
status = {
|
||||||
|
"text": "Online",
|
||||||
|
"tooltip": "Internet connection is active",
|
||||||
|
"class": "online"
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
status = {
|
||||||
|
"text": "Offline",
|
||||||
|
"tooltip": "No internet connection",
|
||||||
|
"class": "offline"
|
||||||
|
}
|
||||||
|
print(json.dumps(status))
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -280,3 +280,11 @@ label:focus {
|
||||||
#scratchpad.empty {
|
#scratchpad.empty {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#custom-ping.connected {
|
||||||
|
color: #00FF00; /* Grün für verbunden */
|
||||||
|
}
|
||||||
|
|
||||||
|
#custom-ping.disconnected {
|
||||||
|
color: #FF0000; /* Rot für nicht verbunden */
|
||||||
|
}
|
||||||
|
|
|
@ -166,6 +166,12 @@
|
||||||
"format": "",
|
"format": "",
|
||||||
"on-click": "wlogout",
|
"on-click": "wlogout",
|
||||||
"tooltip": false
|
"tooltip": false
|
||||||
|
},
|
||||||
|
"custom/ping": {
|
||||||
|
"format": "{}",
|
||||||
|
"exec": "{{ swayusr.home }}/.config/waybar/ping.py",
|
||||||
|
"interval": 60,
|
||||||
|
"return-type": "json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue