14. 02. 2017 Juergen Vigna NetEye

How to send monitoring notifications to Telegram or Microsoft Teams

The conventional thing in a monitoring environment is to notify problems to your staff over E-Mail. Other than E-Mails also SMS are a very common notification type. But is this all we can offer to notify people about problems in our IT?

Obviously, there is more than that. Two very handy examples are:

  • Notifications over the Telegram App (CLI)
  • Notifications over the Office 365 Web API (Microsoft Teams)

Telegram

As you are most probably aware, the WhatsApp-similar application “Telegram”, allows you to send messages to your contacts, groups and also channels. Other then WhatsApp, Telegram has an installable command line interface (CLI) through which you may script the sending of messages from a computer. You have to download and install the Telegram binaries on your monitoring server. After that, you define the notification command in the monitoring in this way:

Host Notification: telegram-cli -W -e "msg $CONTACTEMAIL$ Host '$HOSTNAME$' is $HOSTSTATE$ - Info: $HOSTOUTPUT$ - Time: $SHORTDATETIME$"

Service Notification: telegram-cli -W -e "msg $CONTACTEMAI$ NetEye - $NOTIFICATIONTYPE$ - $SERVICEDESC$ - $HOSTNAME$ - $HOSTADDRESS$ - $SERVICESTATE$ - $SHORTDATETIME$ - $SERVICEOUTPUT$"

Obviously before being able to do this, you have to register your monitoring host as a Telegram sender (the same as you would do it on your smartphone). For this you can use the same phone number you use for sending the SMS’s.

NetEye Telegram Notifications

Office 365

Here you have the possibility to register groups. For the notification you need exactly this GUID after that use this commands to send your notifications:

Host Notification: curl -H "Content-Type: application/json" -d "{\"title\": \"** $NOTIFICATIONTYPE$ alert - $HOSTNAME$ is $HOSTSTATE$ **\", \"text\": \"***** NetEye *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n\", \"themeColor\": \"EA4300\"}" https://outlook.office365.com/webhook/YOURGUIDHERE

Service Notification: curl -H "Content-Type: application/json" -d "{\"title\": \" ** $NOTIFICATIONTYPE$ alert - $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **\", \"text\": \"***** NetEye *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\n[HealthPortalURL]($SERVICENOTESURL$)\nHost: $HOSTNAME$ ($HOSTALIAS$)\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\", \"themeColor\": \"EA4300\"}" https://outlook.office365.com/webhook/YOURGUIDHERE

Office365

Hope this 2 ideas will help you to extend you monitoring notifications even further.

Juergen Vigna

Juergen Vigna

NetEye Solution Architect at Würth Phoenix
I have over 20 years of experience in the IT branch. After first experiences in the field of software development for public transport companies, I finally decided to join the young and growing team of Würth Phoenix. Initially, I was responsible for the internal Linux/Unix infrastructure and the management of CVS software. Afterwards, my main challenge was to establish the meanwhile well-known IT System Management Solution WÜRTHPHOENIX NetEye. As a Product Manager I started building NetEye from scratch, analyzing existing open source models, extending and finally joining them into one single powerful solution. After that, my job turned into a passion: Constant developments, customer installations and support became a matter of personal. Today I use my knowledge as a NetEye Senior Consultant as well as NetEye Solution Architect at Würth Phoenix.

Author

Juergen Vigna

I have over 20 years of experience in the IT branch. After first experiences in the field of software development for public transport companies, I finally decided to join the young and growing team of Würth Phoenix. Initially, I was responsible for the internal Linux/Unix infrastructure and the management of CVS software. Afterwards, my main challenge was to establish the meanwhile well-known IT System Management Solution WÜRTHPHOENIX NetEye. As a Product Manager I started building NetEye from scratch, analyzing existing open source models, extending and finally joining them into one single powerful solution. After that, my job turned into a passion: Constant developments, customer installations and support became a matter of personal. Today I use my knowledge as a NetEye Senior Consultant as well as NetEye Solution Architect at Würth Phoenix.

5 Replies to “How to send monitoring notifications to Telegram or Microsoft Teams”

  1. Ricardo says:

    Hi.
    Thanks for sharing.
    For Office 365, can share with me the nagios (command.cfg and NRPE.cfg)?
    Thanks

    1. Juergen Vigna says:

      Hi Ricardo,

      I do not understand what you exactly need, there is no NRPE.cfg as this is just a Notification Command the command you have to use is described in the blog anyway use this:

      For Host Notification: curl -H “Content-Type: application/json” -d “{\”title\”: \”** $NOTIFICATIONTYPE$ alert – $HOSTNAME$ is $HOSTSTATE$ **\”, \”text\”: \”***** NetEye *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n\”, \”themeColor\”: \”EA4300\”}” https://outlook.office365.com/webhook/YOURGUIDHERE

      For Service Notification:

      curl -H “Content-Type: application/json” -d “{\”title\”: \” ** $NOTIFICATIONTYPE$ alert – $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **\”, \”text\”: \”***** NetEye *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\n[HealthPortalURL]($SERVICENOTESURL$)\nHost: $HOSTNAME$ ($HOSTALIAS$)\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\”, \”themeColor\”: \”EA4300\”}” https://outlook.office365.com/webhook/YOURGUIDHERE

      Hope this helps.

      1. Ricardo says:

        Hi.
        It’s an Nagios command, right?
        I was talking about invoking the command on NRPE config.

        1. Juergen Vigna says:

          Hello Ricardo,

          yes this is a Nagios Command, why would you make a Notification over NRPE?

          Anyway if you use it over NRPE just pass the same arguments to it, something like:

          check_nrpe -H -c notify_o365 -a ”-H “Content-Type: application/json” -d “{\”title\”: \” ** $NOTIFICATIONTYPE$ alert – $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **\”, \”text\”: \”***** NetEye *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\n[HealthPortalURL]($SERVICENOTESURL$)\nHost: $HOSTNAME$ ($HOSTALIAS$)\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\”, \”themeColor\”: \”EA4300\”}” YOURGUID

          And a command in nrpe.cfg like:

          [notify_o365] = curl $ARG1$

          Cheers,

          Jürgen

          1. Ricardo says:

            Hi Juergen.
            Not for the NRPE but for the NCPA.
            Set the command as indicated (with webhook URL) and in ncpa.cfg:

            define service {
            use generic-service
            host_name SERVERNAME
            service_description TEAMS NOT Teste
            check_command check_ncpa!-t ‘token-ncpa’ -P 5693 -M ‘disk/logical/C:|’ -w 90 -c 95 -u G
            event_handler ms-teams-notifications

            works well.
            Thanks for help.
            Ricardo

Leave a Reply

Your email address will not be published. Required fields are marked *

Archive