forked from drwestt/Nagios2GoogleChat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgchat_notify.sh
32 lines (26 loc) · 890 Bytes
/
gchat_notify.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
#!/usr/bin/env bash
# edit webhook url and thread id
url='https://chat.googleapis.com/v1/spaces/xxxxxxxxx/messages?key=xxxxxxxx&token=xxxxxxxx'
id=spaces/xxxxxxxxx/threads/xxxxxxxx
# gchat notification commands
#
# define command {
# command_name gchat-service
# command_line /usr/lib64/nagios/plugins/gchat_notify.sh "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTADDRESS$" "$SERVICEDESC$" "$SERVICEOUTPUT$" "$LONGDATETIME$"
# }
# define command {
# command_name gchat-host
# command_line /usr/lib64/nagios/plugins/gchat_notify.sh "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTADDRESS$" "$HOSTSTATE$" "$HOSTOUTPUT$" "$LONGDATETIME$"
# }
IFS='%'
# sending notification to gchat
curl -4 -X POST \
"$url" \
-H 'Content-Type: text/json; charset=utf-8' \
-d '{
"text": "*`'$2'`:`'$4'`*\n```Notification: '$5'\n'$6'```",
"thread": {
"name": "'$id'"
}
}'
unset IFS