# Scripts

# monitoring

import subprocess  
import requests

def run\_ssh\_command():  
 # SSH command  
 ssh\_command = "ssh -p 54231 monitoring@netvm1.shiny.space"  
   
 # Run the SSH command and capture the output  
 try:  
 result = subprocess.check\_output(ssh\_command, shell=True, text=True, stderr=subprocess.STDOUT)  
 # Filter out unwanted parts of the output  
 filtered\_output = \[line.strip() for line in result.split('\\n') if line.strip() and "PTY allocation request failed" not in line and "Connection to" not in line and "Pseudo-terminal will not be allocated" not in line\]  
 return filtered\_output

 except subprocess.CalledProcessError as e:  
 return \[f"Error: {e.output.strip()}"\]

def send\_result\_to\_ntfy(result):  
 # Ntfy.sh endpoint  
 ntfy\_url = "https://ntfy.sh/shinyspace"  
   
 # Check if the first line is "OK"  
 if result and result\[0\].strip() == "OK":  
 print("SSH command succeeded. Sending nothing to ntfy.sh.")  
 else:  
 print("SSH command failed or the first line is not 'OK'. Sending error to ntfy.sh.")  
 payload = {"error": result}  
 # POST request with the result or error  
 response = requests.post(ntfy\_url, data=payload)  
   
 # Check the response status  
 if response.status\_code == 200:  
 print("Result sent successfully to ntfy.sh")  
 else:  
 print(f"Failed to send result. Status code: {response.status\_code}")

if \_\_name\_\_ == "\_\_main\_\_":  
 # Run SSH command  
 ssh\_result = run\_ssh\_command()  
   
 # Send result or error to ntfy.sh  
 send\_result\_to\_ntfy(ssh\_result)