= Icinga2 Notification to Slack through Director = === Prerequisite === * SLACK API WEbHook URL created. If you haven't created these, please consult [wiki:NSM2021/Agenda/SlackGuide here] * Notification Users are created in Icinga Director == Create new command on Icinga2 == We have created custom bash codes to translate Icinga notifications to Slack. Download them into the scripts directory. {{{ #!sh cd /etc/icinga2/scripts wget https://raw.githubusercontent.com/LEARN-LK/Tutorials/master/Scripts/ICINGA2/icinga2-slack-host.sh wget https://raw.githubusercontent.com/LEARN-LK/Tutorials/master/Scripts/ICINGA2/icinga2-slack-service.sh chmod +x icinga2-slack-host.sh chmod +x icinga2-slack-service.sh }}} Then log into Icinga Director and create two commands as follows. * Host Alarm to Slack [[Image(HostAlarm-Slack.png, 600px, nolink)]] Add following Arguments as well. [[Image(HAS-Args.png, 500px, nolink)]] * Service Alarm to Slack [[Image(ServiceAlarm-Slack.png, 600px, nolink)]] Add following Arguments as well. [[Image(SAS-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.