Telegram notifications

Hello everyone!

I’m trying to configure Icinga to get notifications with a telegram bot. I have followed the following links:

Tutorial:
https://www.srcbox.net/posts/monitoring-notifications-via-telegram/

Topic:

But I think I’m having some concept problems, I have a main server called “Monitor” and a few satellite servers that I monitor with the main one.

I have configured what is shown in the tutorial on both the main one and one of the satellites to test since I did not know which of the two it should be on.

The files on the main one (Monitor) are:

/etc/icinga2/constants.conf

const TelegramBotToken = "${00000000000}$"

/etc/icinga2/conf.d/notifications.conf

apply Notification "telegram-notification" to Host {
  import "telegram-host-notification"

  user_groups = host.vars.notification.telegram.groups
  users = host.vars.notification.telegram.users

  assign where host.vars.notification.telegram
}

apply Notification "telegram-notification" to Service {
  import "telegram-service-notification"

  user_groups = host.vars.notification.telegram.groups
  users = host.vars.notification.telegram.users

  assign where host.vars.notification.telegram
}

/etc/icinga2/conf.d/hosts.conf

object Host NodeName {
  /* Import the default host template defined in `templates.conf`. */
  import "generic-host"

 {Other things.....}

  vars.notification["telegram"] = {
     groups = [ "icingaadmins" ]
  }

/etc/icinga2/conf.d/commands.conf

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

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

  env = {
    NOTIFICATIONTYPE = "$notification.type$"
    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$"
  }
}

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

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

  env = {
    NOTIFICATIONTYPE = "$notification.type$"
    SERVICEDESC = "$service.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$"
  }
}

/etc/icinga2/conf.d/templates.conf

template Notification "telegram-host-notification" {
  command = "telegram-host-notification"
  states = [ Up, Down ]
  types = [ Problem, Acknowledgement, Recovery, Custom,
            FlappingStart, FlappingEnd,
            DowntimeStart, DowntimeEnd, DowntimeRemoved ]
  period = "24x7"
}


template Notification "telegram-service-notification" {
  command = "telegram-service-notification"
  states = [ Up, Down ]
  types = [ Problem, Acknowledgement, Recovery, Custom,
            FlappingStart, FlappingEnd,
            DowntimeStart, DowntimeEnd, DowntimeRemoved ]
  period = "24x7"
}

/etc/icinga2/conf.d/users.conf

object User "icingaadmin" {
  import "generic-user"

  display_name = "Icinga 2 Admin"
  groups = [ "icingaadmins" ]

  email = "root@localhost"
  vars.telegram_chat_id = "-0000000000"

}

object UserGroup "icingaadmins" {
  display_name = "Icinga 2 Admin Group"
}

The scripts telegram-host-notification.sh and telegram-service-notification.sh are the same as in the tutorial and they have the right permissions or I think so :slightly_frowning_face:

-rwxr-xr-x 1 root root 4359 Jul 17  2018 mail-host-notification.sh
-rwxr-xr-x 1 root root 4759 Dec 29 15:34 mail-service-notification.sh
-rwxr-xr-x 1 root root  556 Dec 29 15:37 telegram-host-notification.sh
-rwxr-xr-x 1 root root  619 Dec 29 15:40 telegram-service-notification.sh

I have enabled the debug “log icinga2 feature enable debug log”, but I don’t see anything about telegram on it.

The bot has permissions and the tokens are fine since with curl or executing the scripts on purpose I get notifications.

Finally,I don’t know if I’m posing it incorrectly and for example I should also edit the satellite server that I’m using for testing from /etc/icinga2/zones.d/master/hosts or if I’m debugging wrong

Thank you so much!

Hello, could someone lend me a hand? :frowning:

did u figure it out? or u still need help?

Hello,

Yes but I don’t remember how :sweat_smile:

I remember that a large part of the problem was solved by running icinga in the foreground because the error was not reflected in any other way.

Thank you anyway!