
Enabling Telegram notifications in Centreon
In this document we will see something very interesting, let's see how to implement a Centreon notification system with Telegram, so we will receive the alerts of our monitoring with Telegram messages directly to our mobile phones. I hope you are interested!
The necessary steps are, first create a bot in Telegram and then create a Telegram Group and add to said bot and whoever we want to receive notifications. Later we will register in Centreon the necessary configurations for our Hosts or Services to alert us with Telegram messages, A joy!
Setting up Telegram,
We assume that you have Telegram installed on a mobile phone and perfectly activated, The first step then, is to register our bot, we added @botfather to our Telegram and started the conversation with '/start', To create the bot we press '/newbot', and it will tell us to give it a name, in the example I use 'Centreon Notifications', then it tells us that we must create a user (Finished in _bot), in the example I'm using 'NotificacionesCentreon_bot'. It will create the bot and give us the TOKEN that we will need to validate ourselves and use its API when sending messages. I leave you the name I am using, don't troll me please 🙂 in any case a greeting is welcome 😉
The following is what has been said, We will create a group, we add the newly created bot and our user or people from the IT team. The Group's default privacy mode will not allow our bot to read messages, So we must either make the group public (Like no), or make the bot admin of the group and confirm that it has visibility over the messages. After making it an administrator, you may need to remove it from the group and add it back.
If we open a browser and access: https://api.telegram.org/botTOKEN/getUpdates
We will be able to know what the ID of the group to which the bot belongs is, We'll need it next:
GOOD, to send a test message, from the Centreon shell we tried to send us a message:
[SourceCode]curl -s -X POST https://api.telegram.org/botTOKEN/sendMessage -d text=”Test Text Message” -d chat_id=-ID_GRUPO_CHAT[/SourceCode]
Setting up alerts in Centreon,
At Centreon we must create 2 Notification Commands, we will associate one with the notifications generated by the Hosts, and the other to notifications from the Services.
So in “Configuration” > “Commands” > “Notifications” > “Add” we create the Command that will execute when a Host generates an alert, we name it and in Command Line something like:
[SourceCode]curl -s -X POST https://api.telegram.org/botTOKEN/sendMessage -d text=”The host $HOSTNAME$ ($HOSTADDRESS$) is in $HOSTSTATE$ status, More info: $HOSTOUTPUT$ – $LONGDATETIME$” -d chat_id=-ID_GRUPO_CHAT[/SourceCode]
And we created another Notification Command for the Services, and the following command can help us:
[SourceCode]curl -s -X POST https://api.telegram.org/botTOKEN/sendMessage -d text=”At $HOSTNAME$ the $SERVICEDESC$ Service is in $SERVICESTATE$ status, More info: $SERVICEOUTPUT$ – $LONGDATETIME$” -d chat_id=-ID_GRUPO_CHAT[/SourceCode]
Now in the user or group we are interested in, in the 'Notification' section’ we must enable the type of alerts we want to receive from both the Hosts and the Services, indicate the time range for the warnings and the command they will execute, indicating the 2 that we have just created! As usual, after tapping settings, we record and export the config in Centreon and if everything has gone well… Wait for the messages!
And that's it! We will see that messages will start arriving as soon as our machines go down or their services affected! that easy, It's that simple!! If you don't have your environment monitored, it's because you don't want to, And if you want to stay in the know… what better than enabling this type of notifications with Telegram!