2015-10-29 76 views
1

我有一个自定义通知脚本,我想在发生严重事件时使用来自munin的数据。不幸的是,我无法使其正常工作,同时遵循官方文档。它自己的通知脚本经过测试,并且在使用假数据从shell调用时工作正常。它的权限在755上,所以执行也不应该成为问题。因此,联系挂钩可能未被调用。 我所做的是:Munin警报/通知未被执行

# /etc/munin/munin-conf.d/custom.cnf 
    [...] 
    contact.slack.command MUNIN_SERVICESTATE="${var:worst}" MUNIN_HOST="${var:host}" MUNIN_SERVICE="${var:graph_title}" MUNIN_GROUP=${var:group} /usr/local/bin/notify_slack_munin 
    contact.slack.always_send warning critical 
    contact.slack.text ${if:cfields \u000A* CRITICALs:${loop<,>:cfields ${var:label} is ${var:value} (outside range [${var:crange}])${if:extinfo : ${var:extinfo}}}.}${if:wfields \u000A* WARNINGs:${loop<,>:wfields ${var:label} is ${var:value} (outside range [${var:wrange}])${if:extinfo : ${var:extinfo}}}.}${if:ufields \u000A* UNKNOWNs:${loop<,>:ufields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}${if:fofields \u000A* OKs:${loop<,>:fofields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.} 

上面的节点和目录的定义这些线路工作正常。但通知不会出去。你有什么想法可能是什么?

+0

我假设你已经看到了这一点:https://开头gist.github.com/anarchivist/58a905515b2eb2b42fe6,但我发布它以防万一。 – nha

+0

是的,谢谢你:) – user2693017

回答

1

我只是打了相同的脚本最初发现于gist得到它固定2次琐碎失误后工作:

  • 确保你把联系人在配置宿主树前。我把它放在配置文件的末尾,直到我将它移到放置示例联系人的地方为止
  • 请确保Munin配置中的命令使用完整的文件名,因此如果您将在/usr/local/bin/notify_slack_munin脚本,然后检查是否有对文件

正如写在Munin Guide没有文件扩展名,看穆宁,limits.log看到发生了什么。

最后注意,如果您有contact.slack.always_send warning critical它将重复推送通知,而不仅仅是严重性更改。

以供参考(如果要点链接刹车),调用松弛网络挂接脚本如下(略有修改澄清):

#!/bin/bash 

# Slack notification script for Munin 
# Mark Matienzo (@anarchivist) 
# https://gist.github.com/anarchivist/58a905515b2eb2b42fe6 
# 
# To use: 
# 1) Create a new incoming webhook for Slack 
# 2) Edit the configuration variables that start with "SLACK_" below 
# 3) Add the following to your munin configuration before the host tree 
# in the part where sample contacts are listed: 
# 
# # -- Slack contact configuration 
# # notify_slack_munin.sh is the full file name 
# contact.slack.command MUNIN_SERVICESTATE="${var:worst}" MUNIN_HOST="${var:host}" MUNIN_SERVICE="${var:graph_title}" MUNIN_GROUP=${var:group} /usr/local/bin/notify_slack_munin.sh 
# # This line will spam Slack with notifications even if no state change happens 
# contact.slack.always_send warning critical 
# # note: This has to be on one line for munin to parse properly 
# contact.slack.text ${if:cfields \u000A* CRITICALs:${loop<,>:cfields ${var:label} is ${var:value} (outside range [${var:crange}])${if:extinfo : ${var:extinfo}}}.}${if:wfields \u000A* WARNINGs:${loop<,>:wfields ${var:label} is ${var:value} (outside range [${var:wrange}])${if:extinfo : ${var:extinfo}}}.}${if:ufields \u000A* UNKNOWNs:${loop<,>:ufields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}${if:fofields \u000A* OKs:${loop<,>:fofields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.} 


SLACK_CHANNEL="#insert-your-channel" 
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/insert/your/hookURL" 
SLACK_USERNAME="munin" 
SLACK_ICON_EMOJI=":munin:" 

# If you want to test the script, you may have to comment this out to avoid hanging console 
input=`cat` 

#Set the message icon based on service state 
if [ "$MUNIN_SERVICESTATE" = "CRITICAL" ] 
then 
    ICON=":exclamation:" 
    COLOR="danger" 
elif [ "$MUNIN_SERVICESTATE" = "WARNING" ] 
then 
    ICON=":warning:" 
    COLOR="warning" 
elif [ "$MUNIN_SERVICESTATE" = "ok" ] 
then 
    ICON=":white_check_mark:" 
    COLOR="good" 
elif [ "$MUNIN_SERVICESTATE" = "OK" ] 
then 
    ICON=":white_check_mark:" 
    COLOR="good" 
elif [ "$MUNIN_SERVICESTATE" = "UNKNOWN" ] 
then 
    ICON=":question:" 
    COLOR="#00CCCC" 
else 
    ICON=":white_medium_square:" 
    COLOR="#CCCCCC" 
fi 

# Generate the JSON payload 
PAYLOAD="{\"channel\": \"${SLACK_CHANNEL}\", \"username\": \"${SLACK_USERNAME}\", \"icon_emoji\": \"${SLACK_ICON_EMOJI}\", \"attachments\": [{\"color\": \"${COLOR}\", \"fallback\": \"Munin alert - ${MUNIN_SERVICESTATE}: ${MUNIN_SERVICE} on ${MUNIN_HOST}\", \"pretext\": \"${ICON} Munin alert - ${MUNIN_SERVICESTATE}: ${MUNIN_SERVICE} on ${MUNIN_HOST} in ${MUNIN_GROUP} - <http://central/munin/|View Munin>\", \"fields\": [{\"title\": \"Severity\", \"value\": \"${MUNIN_SERVICESTATE}\", \"short\": \"true\"}, {\"title\": \"Service\", \"value\": \"${MUNIN_SERVICE}\", \"short\": \"true\"}, {\"title\": \"Host\", \"value\": \"${MUNIN_HOST}\", \"short\": \"true\"}, {\"title\": \"Current Values\", \"value\": \"${input}\", \"short\": \"false\"}]}]}" 

#Send message to Slack 
curl -sX POST -o /dev/null --data "payload=${PAYLOAD}" $SLACK_WEBHOOK_URL 2>&1 
+0

嗨亚伯,也许它可能会有所帮助,如果你还可以在你的答案中包括脚本(或至少相关部分)。要点可能并不总是可用的。这会让你的答案更完整。 – dubes

+0

这是配置顺序,ty .. – user2693017