SpecialistOff.NET / Вопросы / Статьи / Фрагменты кода / Резюме / Метки / Помощь / Файлы
Список вопросов ПечатьМетки: zabbix мониторинг slack
| RemiZOffAlex Создано: 2018-03-24 20:26:49.737199 Обновлено: 2018-03-24 20:26:49.737199 |
|---|
|
В Zabbix меню: Администрирование -> Способы оповещения Нажать кнопу Создать способ оповещения Заполняем поле Имя, указываем тип Скрипт и имя скрипта slack.sh Параметры скрипта:
Файл slack.sh
#!/bin/bash
# Slack incoming web-hook URL and user name
url='' # example: https://hooks.slack.com/services/QW3R7Y/D34DC0D3/BCADFGabcDEF123
username='Zabbix'
## Values received by this script:
# To = $1 (Slack channel or user to send the message to, specified in the Zabbix web interface; "@username" or "#channel")
# Subject = $2 (usually either PROBLEM or RECOVERY/OK)
# Message = $3 (whatever message the Zabbix action sends, preferably something like "Zabbix server is unreachable for 5 minutes - Zabbix server (127.0.0.1)")
# Get the Slack channel or user ($1) and Zabbix subject ($2 - hopefully either PROBLEM or RECOVERY/OK)
to="$1"
subject="$2"
# Change message emoji depending on the subject - smile (RECOVERY/OK), frowning (PROBLEM), or ghost (for everything else)
emoji=':exclamation:'
if [[ "$subject" == "Recover:"* ]]; then
emoji=':white_check_mark:'
elif [[ "$subject" == "Resolved:"* ]]; then
emoji=':white_check_mark:'
fi
# The message that we want to send to Slack is the "subject" value ($2 / $subject - that we got earlier)
# followed by the message that Zabbix actually sent us ($3)
message="${emoji} ${subject}"
# Build our JSON payload and send it as a POST request to the Slack incoming web-hook URL
payload="payload={\"channel\": \"${to//\"/\\\"}\", \"username\": \"${username//\"/\\\"}\", \"text\": \"${message//\"/\\\"}\"}"
curl -m 5 --data-urlencode "${payload}" $url -A 'zabbix-slack-alertscript'
|