added tailscale subnet availability check
This commit is contained in:
parent
93c4c0d49e
commit
7d157e5136
1 changed files with 26 additions and 9 deletions
|
|
@ -3,9 +3,11 @@
|
||||||
#usage: python3 lainmonitor.py | or run it as a service
|
#usage: python3 lainmonitor.py | or run it as a service
|
||||||
#author: hornetmaidan
|
#author: hornetmaidan
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import threading
|
||||||
import telebot
|
import telebot
|
||||||
#define the variables
|
#define the variables
|
||||||
status, hostname, uptime, zerotier, prosody, postgres, tailscale, disk, ping = 'unknown', 'unknown', 'unknown', 'unknown', 'unknown', 'unknown', 'unknown', 'unknown', 'unknown'
|
status, hostname, uptime, zerotier, prosody, postgres, tailscale, disk, ping = 'unknown', 'unknown', 'unknown', 'unknown', 'unknown', 'unknown', 'unknown', 'unknown', 'unknown'
|
||||||
|
nodes, hostnames, reach, threads = [], [], [], []
|
||||||
#telegram bot token
|
#telegram bot token
|
||||||
TOKEN = 'PLACE_YOUR_TOKEN_HERE'
|
TOKEN = 'PLACE_YOUR_TOKEN_HERE'
|
||||||
|
|
||||||
|
|
@ -29,15 +31,30 @@ def getinfo():
|
||||||
status = 'online'
|
status = 'online'
|
||||||
return hostname, uptime, zerotier, prosody, postgres, tailscale, disk
|
return hostname, uptime, zerotier, prosody, postgres, tailscale, disk
|
||||||
|
|
||||||
#ping tailscale (change the IP address to the one you want or add more)
|
#function to ping tailscale nodes
|
||||||
def check_tailscale():
|
def ping_node(node, hostname):
|
||||||
global ping
|
ping = subprocess.Popen(f"ping {node} -c 1 | grep '1 packets'", shell=True, stdout=subprocess.PIPE).stdout.read().decode().strip()
|
||||||
ping = subprocess.Popen("ping TAILSCALE_IP -c 1 | grep '1 packets'", shell=True, stdout=subprocess.PIPE).stdout.read().decode().strip()
|
|
||||||
if '1 received' in ping:
|
if '1 received' in ping:
|
||||||
ping = 'connected'
|
reach.append(f'{node}/{hostname} is reachable')
|
||||||
else:
|
else:
|
||||||
ping = 'unreachable'
|
reach.append(f'{node}/{hostname} is unreachable')
|
||||||
return ping
|
|
||||||
|
#ping tailscale nodes
|
||||||
|
def check_tailscale():
|
||||||
|
global nodes, hostnames, reach, threads, ping
|
||||||
|
nodes_output = subprocess.Popen("tailscale status | grep '100'", shell=True, stdout=subprocess.PIPE).stdout.read().decode().strip()
|
||||||
|
nodes = [line.split()[0] for line in nodes_output.split('\n') if line]
|
||||||
|
hostnames = [line.split()[1] for line in nodes_output.split('\n') if line]
|
||||||
|
|
||||||
|
for node, hostname in zip(nodes, hostnames):
|
||||||
|
thread = threading.Thread(target=ping_node, args=(node, hostname))
|
||||||
|
threads.append(thread)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
for thread in threads:
|
||||||
|
thread.join()
|
||||||
|
|
||||||
|
return reach
|
||||||
|
|
||||||
#debug handler
|
#debug handler
|
||||||
def check():
|
def check():
|
||||||
|
|
@ -69,7 +86,7 @@ def handle(message):
|
||||||
bot.reply_to(message, 'work in progress...')
|
bot.reply_to(message, 'work in progress...')
|
||||||
elif message.text == '/ping':
|
elif message.text == '/ping':
|
||||||
check_tailscale()
|
check_tailscale()
|
||||||
bot.reply_to(message, f'ping status: {ping}')
|
bot.reply_to(message, f'ping status: \n\n{reach}')
|
||||||
|
|
||||||
#polling
|
#polling
|
||||||
bot.polling()
|
bot.polling()
|
||||||
Loading…
Add table
Reference in a new issue