Certain notifications

Hello everybody,

currently we are using the E-Mail notifications, which is working fine, but we would like to install an additionally option. We would like to implement notifications by Telegram. I found this solution:

https://github.com/lazyfrosch/icinga2-telegram

I followed the instructions step by step and it works. Now we are receiving notifications from every host and service, but we only want to receive messages from certain hosts and services.

Example:

/*
 * User
 */
object User "icingatwotelegramm" {
  import "generic-user"

  display_name = "IcingaTwoTelegramm"

  // The telegram chat ID
  vars.telegram_chat_id = "01010101010101010"
}

/*
 * Notifications
 */
apply Notification "telegram-icingaadmin" to Host {
  import "mail-host-notification"
  command = "telegram-host-notification"

  users = [ "icingatwotelegramm" ]

  assign where host.name
}

apply Notification "telegram-icingaadmin" to Service {
  import "mail-service-notification"
  command = "telegram-service-notification"

  users = [ "icingatwotelegramm" ]

  assign where host.name
}

/*
 * Notification Commands
 */
object NotificationCommand "telegram-host-notification" {
  import "plugin-notification-command"

  command = [ SysconfDir + "/icinga2/scripts/telegram-host-notification.sh" ]

  env = {
    NOTIFICATIONTYPE = "$notification.type$"
    HOSTNAME = "$host.name$"
    HOSTALIAS = "$host.display_name$"
    HOSTADDRESS = "$address$"
    HOSTSTATE = "$host.state$"
    LONGDATETIME = "$icinga.long_date_time$"
    HOSTOUTPUT = "$host.output$"
    NOTIFICATIONAUTHORNAME = "$notification.author$"
    NOTIFICATIONCOMMENT = "$notification.comment$"
    HOSTDISPLAYNAME = "$host.display_name$"
    //TELEGRAM_BOT_TOKEN = TelegramBotToken
    //TELEGRAM_CHAT_ID = "$user.vars.telegram_chat_id$"

    // optional
    ICINGAWEB2_URL = "https://icinga.example.com/icingaweb2"
  }
}

object NotificationCommand "telegram-service-notification" {
  import "plugin-notification-command"

  command = [ SysconfDir + "/icinga2/scripts/telegram-service-notification.sh" ]

  env = {
    NOTIFICATIONTYPE = "$notification.type$"
    SERVICEDESC = "$service.name$"
    HOSTNAME = "$host.name$"
    HOSTALIAS = "$host.display_name$"
    HOSTADDRESS = "$address$"
    SERVICESTATE = "$service.state$"
    LONGDATETIME = "$icinga.long_date_time$"
    SERVICEOUTPUT = "$service.output$"
    NOTIFICATIONAUTHORNAME = "$notification.author$"
    NOTIFICATIONCOMMENT = "$notification.comment$"
    HOSTDISPLAYNAME = "$host.display_name$"
    SERVICEDISPLAYNAME = "$service.display_name$"
    //TELEGRAM_BOT_TOKEN = TelegramBotToken
    //TELEGRAM_CHAT_ID = "$user.vars.telegram_chat_id$"

    // optional
    ICINGAWEB2_URL = "https://icinga.example.com/icingaweb2"
  }
}

Any Ideas?

Thank you for the help.
Best Regards

Maybe you want to add a Telegram host and or service groups and use them in the assign where statements.

Thank you for the Answer.
I dont know what you mean. Could.could you give me an example?
Sorry, I have a mental block.

Something like this. Then you can add the Telegram group to the host and only the hosts in the Telegram group will notify this way.

Dear Dominik,

you are awesome. This solution works fine.

Thank you