= Icinga2 Notification to Telegram through Director = === Prerequisite === * Telegram BOT Token code and Chat ID created. If you haven't created these, please consult [wiki:NSM2021/Agenda/AlertsLibrenms#CreateTelegramBOT here] * Notification Users are created in Icinga Director == Create new command on Icinga2 == We have created custom bash codes to translate Icinga notifications to Telegram. Download them into the scripts directory. {{{ #!sh cd /etc/icinga2/scripts wget https://raw.githubusercontent.com/LEARN-LK/Tutorials/master/Scripts/ICINGA2/icinga2-telegram-host.sh wget https://raw.githubusercontent.com/LEARN-LK/Tutorials/master/Scripts/ICINGA2/icinga2-telegram-service.sh chmod +x icinga2-telegram-host.sh chmod +x icinga2-telegram-service.sh }}} Then log into Icinga Director and create two commands as follows. * Host Alarm to Telegram [[Image(HostAlarm-Telegram.png, 600px, nolink)]] Add following Arguments as well. [[Image(HAT-Args.png, 500px, nolink)]] * Service Alarm to Telegram [[Image(ServiceAlarm-Telegram.png, 600px, nolink)]] Add following Arguments as well. [[Image(SAT-Args.png, 500px, nolink)]] == Create Custom Variables == Above scripts uses two custom variables called tokencode and chat_id, these are Telegram User specific data and we have to define them on Iciga Director before applying it on Notifications. Go to Icinga Director --> `Data Field Categories` [[Image(DataCat1.png, 500px, nolink)]] Add a Data Category as below. [[Image(DataCat2.png, 500px, nolink)]] Then go to Icinga Director --> `Define Data Fields` Create two new Data Fields as follows: * Token Code [[Image(TokenCode.png, 500px, nolink)]] * Chat ID [[Image(ChatId.png, 500px, nolink)]] == Telegram Notification Templates == Create following templates with the given data. * Telegram Host Notification Template [[Image(THT.png, 500px, nolink)]] * Include custom fields we created earlier. Goto the Fields tab of the template and enter chat_id and tockencode as mandatory fields [[Image(Field_chatId.png, 500px, nolink)]] [[Image(Field_tokencode.png, 500px, nolink)]] * Telegram Service Notification Template [[Image(TST.png, 500px, nolink)]] * Goto the Fields tab of the template and enter `chat_id` and `tockencode` as mandatory fields based on previous guidelines. == Create Notifications to Telegram == In this setup, we shall create two notifications setups for Hosts and Services respectively. When assigning notifications we should select a user rather than a user group to avoid multiple duplicates of notifications. * Telegram-Host-Notification [[Image(THS.png, 600px, nolink)]] * Telegram-Service-Notification [[Image(TSN.png, 600px, nolink)]] * Finally, Deploy the changes you did.