-
-
Notifications
You must be signed in to change notification settings - Fork 784
/
alert_slack.sh
80 lines (74 loc) · 2.31 KB
/
alert_slack.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# LinuxGSM alert_slack.sh function
# Author: Kenneth Lindeof
# Website: https://linuxgsm.com
# Description: Sends Slack alert.
local modulename="ALERT"
local commandaction="Alert"
local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
if ! command -v jq > /dev/null; then
fn_print_fail_nl "Sending Slack alert: jq is missing."
fn_script_log_fatal "Sending Slack alert: jq is missing."
fi
json=$(cat <<EOF
{
"attachments": [
{
"color": "#36a64f",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*LinuxGSM Alert*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*${alertemoji} ${alertsubject}* \n ${alertbody}"
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Game:* \n ${gamename}"
},
{
"type": "mrkdwn",
"text": "*Server IP:* \n ${alertip}:${port}"
},
{
"type": "mrkdwn",
"text": "*Server Name:* \n ${servername}"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hostname: ${HOSTNAME} / More info: ${alerturl}"
}
}
]
}
]
}
EOF
)
fn_print_dots "Sending Slack alert"
slacksend=$(curl -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${slackwebhook}")
if [ "${slacksend}" == "ok" ]; then
fn_print_ok_nl "Sending Slack alert"
fn_script_log_pass "Sending Slack alert"
else
fn_print_fail_nl "Sending Slack alert: ${slacksend}"
fn_script_log_fatal "Sending Slack alert: ${slacksend}"
fi