-
Notifications
You must be signed in to change notification settings - Fork 1
/
send-host.py
52 lines (36 loc) · 1.31 KB
/
send-host.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python3
import sys
import urllib.parse
from discord_webhook import DiscordEmbed, DiscordWebhook
HOOK = "https://discordapp.com/api/webhooks/id/token" # UPDATE WITH YOUR WEBHOOK
KEYS = ["type", "hostname", "hoststate", "hostaddr", "output", "time"]
DOMAIN = "your.website.com" # UPDATE WITH YOUR URL/DOMAIN
def codecolor(alerttype):
clr_red = 13632027
clr_yel = 16098851
clr_grn = 8311585
if alerttype == "PROBLEM":
return clr_red
elif alerttype == "RECOVERY":
return clr_grn
else:
return clr_yel
def main(nag_in):
_cmd = nag_in.pop(0)
data = {KEYS[i]: nag_in[i] for i in range(len(KEYS))}
host = urllib.parse.quote(data["host"])
link = f"https://{DOMAIN}/nagios/cgi-bin/extinfo.cgi?type=2&host={host}"
line1 = f"**<{data['type']}>** {data['hostname']} ({data['hostaddr']}) is {data['hoststate']}"
webhook = DiscordWebhook(url=HOOK)
# create embed object for webhook
embed = DiscordEmbed(
title=line1, description=data["output"], color=codecolor(data["type"])
)
embed.set_author(name="Open Nagios service detail", url=link)
# set timestamp
embed.set_timestamp(int(data["time"]))
# add embed object to webhook
webhook.add_embed(embed)
webhook.execute()
if __name__ == "__main__":
main(sys.argv)