Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Mattermost incoming web-hook URL and user name
  4. url='https://xxx'
  5. username='Zabbix'
  6. icon='http://www.myiconfinder.com/uploads/iconsets/256-256-25dba2a6b2692c018ed4879d9cc0a5e4-wrench.png'
  7.  
  8. ## Values received by this script:
  9. # To = $1 (Mattermost channel or user to send the message to, specified in the Zabbix web interface; "@username" or "#channel")
  10. # Subject = $2 (usually either PROBLEM or RECOVERY)
  11. # Message = $3 (whatever message the Zabbix action sends, preferably something like "Zabbix server is unreachable for 5 minutes - Zabbix server (127.0.0.1)")
  12.  
  13. # Get the Mattermost channel or user ($1) and Zabbix subject ($2 - hopefully either PROBLEM or RECOVERY)
  14. to="$1"
  15. subject="$2"
  16.  
  17. # Change color emoji depending on the subject - Green (RECOVERY), Red (PROBLEM)
  18. if [ "$subject" == 'Recovery' ]; then
  19. color="#00ff33"
  20. elif [ "$subject" == 'Problem' ]; then
  21. color="#ff2a00"
  22. fi
  23.  
  24. # The message that we want to send to Mattermost is the "subject" value ($2 / $subject - that we got earlier)
  25. # followed by the message that Zabbix actually sent us ($3)
  26. message="${subject}: $3"
  27. #message=`echo "$message" | sed 's/\\r\\n/X/g'`
  28.  
  29. # Build our JSON payload and send it as a POST request to the Mattermost incoming web-hook URL
  30. payload="payload={\"icon_url\": \"$icon\", \"attachments\": [ {\"color\": \"${color}\", \"text\": \"${message}\"} ], \"channel\": \"${to}\", \"username\": \"${username}\", \"icon_emoji\": \"${emoji}\"}"
  31. curl -m 5 --data-urlencode "${payload}" $url
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement