Skip to content
Snippets Groups Projects

Mattermost alerting for monit

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Erick Hitter

    Called via monit's exec function:

    if not exists then exec "/etc/monit/mattermost.sh danger" else if succeeded then exec "/etc/monit/mattermost.sh good"

    Either named colors, or hex codes, are accepted as the first argument.

    Edited
    mattermost.sh 582 B
    #!/bin/sh
    
    COLOR=${1:-default}
    
    /usr/bin/curl \
        -X POST \
        -s \
        --data-urlencode "payload={ \
            \"channel\": \"#alerts\", \
            \"username\": \"Monit\", \
            \"attachments\": [ { \
                \"fallback\": \"$MONIT_HOST: $MONIT_SERVICE - $MONIT_DESCRIPTION\", \
                \"pretext\": \"**$MONIT_HOST** @ $MONIT_DATE\", \
                \"text\": \"**$MONIT_SERVICE** - $MONIT_DESCRIPTION\", \
                \"color\": \"$COLOR\" \
            } ],\
            \"icon_url\": \"https://mattermost/static/emoji/1f47b.png\" \
        }" \
        https://mattermost/hooks/boo
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment