-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdiscord_bot.sh
49 lines (42 loc) · 1.26 KB
/
discord_bot.sh
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
#!/bin/bash
# Discord Webhook URL. It'll be set by the install.sh script
WEBHOOK_URL="ENTER_DISCORD_WEBHOOK_URL_HERE"
CURL=/usr/bin/curl
MINA=/usr/local/bin/mina
# get useful status info from mina client
status=$($MINA client status | grep -E "Block height:|Local uptime:|Peers:|Sync status:|Block producers running:|Next block will be produced in:|Consensus time now:")
# get disk usage
disk=$(df -H | awk '{ if ($6=="/") printf "Filesystem: %s\\nMounted on: /\\nTotal: %s\\nAvail: %s\\nUsed: %s\\nUse%%: %s\\n", $1, $2, $4, $3, $5}')
# get memory usage
mem=$(free -h --si | awk -v ORS='\\n' 'NR>1{print $1" "$4" / "$2" Free, "$3" / "$2" Used"}')
# prepare Discord notification payload
payload=$(cat <<-END
{
"embeds": [
{
"color": "14177041",
"fields": [
{
"name": "Hostname",
"value": "$(hostname)"
},
{
"name": "Mina Client Status",
"value": "$(echo ${status//$'\n'/'\n'})"
},
{
"name": "Disk Usage",
"value": "$disk"
},
{
"name": "Memory Usage",
"value": "$mem"
}
]
}
]
}
END
)
# send the notification to Discord channel
$CURL -sL -X POST $WEBHOOK_URL -H 'Content-Type: application/json' -d "$payload"