#!/usr/bin/python3
import subprocess
import requests
import sys
import os
service = sys.argv[1]
proc = subprocess.Popen("hostname", stdout=subprocess.PIPE, shell=True)
hostname = proc.communicate()[0].decode("utf-8").strip()
status = f"Service {service} failed on {hostname}"
print(status)
try:
import redis
r = redis.Redis()
r.publish("boterrorlocal", status)
except Exception as e:
print(e)
proc = subprocess.Popen(
f"systemctl --user -M pi@ status {service}", stdout=subprocess.PIPE, shell=True
)
output = proc.communicate()[0].decode("utf-8").strip()
logo = "https://cdn.discordapp.com/attachments/1170631155905744896/1175721829906788472/systemd-logomark.png"
user = "systemd"
hook = "https://discord.com/api/webhooks/1175604004059877426/[REDACTED]"
color = 0xFF0000
o = dict(
embeds=[dict(color=color, title=status, description=f"```rb\n{output}\n```")],
username=user,
avatar_url=logo,
)
d = requests.post(hook, params=dict(wait="true"), json=o)
print(d.text)