Hello!
I'm trying to implement Rocket.Chat notifications (aside from standard e-mail ones) via custom alertscript in bash. I use the same action to send notifications for e-mail and the messenger.
Here's my action:
And here is the script:
E-mail notifications work just fine but messenger ones never arrive. I changed DebugLevel=5 in server config to catch the problem and that's what i found:
Apparentely curl can't process the output from ALERT.MESSAGE because it's multiline. When i made additional messenger-specific action with default message consisted of only one line it worked fine. My Linux knowledge is very limited, i tried to fix it several ways including by using herein and variables but didn't succeed probably due to my general dumbassness. I could live with oneliners in messenger but this just bugs me so much so i thought i'd try to ask on forum and here i am
I'm trying to implement Rocket.Chat notifications (aside from standard e-mail ones) via custom alertscript in bash. I use the same action to send notifications for e-mail and the messenger.
Here's my action:
Default subject: {HOST.NAME} - [{TRIGGER.STATUS}], {TRIGGER.NAME}
Default message:
Problem started at {EVENT.TIME} on {EVENT.DATE}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Trigger description:
{TRIGGER.DESCRIPTION}
Original problem ID: {EVENT.ID}
Default message:
Problem started at {EVENT.TIME} on {EVENT.DATE}
Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}
Trigger description:
{TRIGGER.DESCRIPTION}
Original problem ID: {EVENT.ID}
And here is the script:
Code:
#!/bin/bash
SUBJECT="$2"
MESSAGE="$3"
# Sending message
curl -s -H "Content-Type: application/json" -d "{\"username\":\"zabbix\",\"text\":\"$( echo "$SUBJECT\n$MESSAGE" | sed 's/"/\\\"/g' )\"}" https://rchat.trololo.com/hooks/zSUM_HooK_HERE
26811:20181127:152739.307 /usr/lib/zabbix/alertscripts/rocketsend.sh '#zabb' 'alt8test.trololo.com - [PROBLEM], "AUTH module" check failed' 'Problem started at 15:27:37 on 2018.11.27
Host: alt8test.trololo.com
Severity: High
Trigger description:
"AUTH module" check failed at the step 1:
response code "502" did not match any of the required status codes "200"
Step 1 - Login
Step 2 - AUTH test
Step 3 - Logout
Original problem ID: 126342' output:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Bad Request</pre>
</body>
</html>
26811:20181127:152739.307 In zbx_ipc_socket_write()
26811:20181127:152739.307 End of zbx_ipc_socket_write():SUCCEED
Host: alt8test.trololo.com
Severity: High
Trigger description:
"AUTH module" check failed at the step 1:
response code "502" did not match any of the required status codes "200"
Step 1 - Login
Step 2 - AUTH test
Step 3 - Logout
Original problem ID: 126342' output:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Bad Request</pre>
</body>
</html>
26811:20181127:152739.307 In zbx_ipc_socket_write()
26811:20181127:152739.307 End of zbx_ipc_socket_write():SUCCEED