我希望 nagios 通过 twilio 向多个 [人] 发送短信。
我该怎么做?
我使用了此代码,但它仅将短信发送到一个电话号码:
define command {
command_name notify-by-page
command_line curl --data-urlencode "From=YOURTWILIONUMBER" --data-urlencode "To=YOURCELL" --data-urlencode "Body=[Nagios] $NOTIFICATIONTYPE$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" https://SID:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d29323638333d1c0d1453090a14111412531e1210" rel="noreferrer noopener nofollow">[email protected]</a>/2010-04-01/Accounts/SID/SMS/Messages >> /tmp/sms
}
define command {
command_name host-notify-by-page
command_line curl --data-urlencode "From=YOURTWILIONUMBER" --data-urlencode "To=YOURCELL" --data-urlencode "Body=[Nagios] $HOSTSTATE$ alert for $HOSTNAME$" https://SID:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f7b60646a616f4e5f46015b5846434640014c4042" rel="noreferrer noopener nofollow">[email protected]</a>/2010-04-01/Accounts/SID/SMS/Messages >> /tmp/sms
}
最佳答案
您必须为要向其发送 SMS 的每个电话号码向 Twilio API 发出单独的 POST 请求。在本例中,我将编写一个 Bash 脚本来发送所有消息,然后让 nagios 调用该 Bash 脚本。
这是一个示例脚本:
#!/bin/bash
curl --data-urlencode "From=YOURTWILIONUMBER" --data-urlencode "To=YOURCELL" --data-urlencode "Body=${1}" https://SID:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="74203b3f313a3415041d5a00031d181d1b5a171b19" rel="noreferrer noopener nofollow">[email protected]</a>/2010-04-01/Accounts/SID/SMS/Messages >> /tmp/sms
curl --data-urlencode "From=YOURTWILIONUMBER" --data-urlencode "To=ANOTHERCELL" --data-urlencode "Body=${1}" https://SID:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e5b1aaaea0aba584958ccb91928c898c8acb868a88" rel="noreferrer noopener nofollow">[email protected]</a>/2010-04-01/Accounts/SID/SMS/Messages >> /tmp/sms
您会注意到我接受正文作为消息作为脚本的第一个参数。那么你的 nagios 配置将如下所示:
define command {
command_name notify-by-page
command_line /path/to/script.sh "[Nagios] $NOTIFICATIONTYPE$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"
}
define command {
command_name host-notify-by-page
command_line /path/to/script.sh "[Nagios] $HOSTSTATE$ alert for $HOSTNAME$"
}
免责声明:我为 Twilio 工作。
关于sms - nagios 通过 twilio 发送短信通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33393093/