Different timeperiod for notifications by cellphone for different users

  • Version used (icinga2 --version)
icinga2 - The Icinga 2 network monitoring daemon (version: r2.13.1-1)

Copyright (c) 2012-2021 Icinga GmbH (https://icinga.com/)
License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl2.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

System information:
  Platform: Debian GNU/Linux
  Platform version: 10 (buster)
  Kernel: Linux
  Kernel version: 4.19.0-16-amd64
  Architecture: x86_64

Build information:
  Compiler: GNU 8.3.0
  Build host: runner-hh8q3bz2-project-508-concurrent-0
  OpenSSL version: OpenSSL 1.1.1d  10 Sep 2019

Application information:

General paths:
  Config directory: /etc/icinga2
  Data directory: /var/lib/icinga2
  Log directory: /var/log/icinga2
  Cache directory: /var/cache/icinga2
  Spool directory: /var/spool/icinga2
  Run directory: /run/icinga2

Old paths (deprecated):
  Installation root: /usr
  Sysconf directory: /etc
  Run directory (base): /run
  Local state directory: /var

Internal paths:
  Package data directory: /usr/share/icinga2
  State path: /var/lib/icinga2/icinga2.state
  Modified attributes path: /var/lib/icinga2/modified-attributes.conf
  Objects path: /var/cache/icinga2/icinga2.debug
  Vars path: /var/cache/icinga2/icinga2.vars
  PID path: /run/icinga2/icinga2.pid
  • Enabled features (icinga2 feature list)
Disabled features: compatlog debuglog elasticsearch gelf graphite icingadb influxdb influxdb2 livestatus opentsdb perfdata statusdata syslog
Enabled features: api checker command ido-mysql mainlog notification
  • Config validation (icinga2 daemon -C)
[2021-11-22 18:26:53 +0300] information/cli: Icinga application loader (version: r2.13.1-1)
[2021-11-22 18:26:53 +0300] information/cli: Loading configuration file(s).
[2021-11-22 18:26:53 +0300] information/ConfigItem: Committing config item(s).
[2021-11-22 18:26:53 +0300] information/ApiListener: My API identity: <hostname>
[2021-11-22 18:27:00 +0300] warning/ApplyRule: Apply rule 'host-downtime' (in /etc/icinga2/zones.d/master/downtimes.conf: 5:1-5:47) for type 'ScheduledDowntime' does not match anywhere!
[2021-11-22 18:27:00 +0300] warning/ApplyRule: Apply rule 'hardware_raid_adaptec' (in /etc/icinga2/zones.d/master/services.d/services.linux.conf: 25:1-25:37) for type 'Service' does not match anywhere!
[2021-11-22 18:27:00 +0300] warning/ApplyRule: Apply rule 'service_exchange_mail_queue' (in /etc/icinga2/zones.d/master/services.d/services.linux.conf: 106:1-106:43) for type 'Service' does not match anywhere!
[2021-11-22 18:27:00 +0300] warning/ApplyRule: Apply rule 'check_ups_hrsnk_alarms_present' (in /etc/icinga2/zones.d/master/services.d/services.ups.conf: 528:1-528:46) for type 'Service' does not match anywhere!
[2021-11-22 18:27:00 +0300] warning/ApplyRule: Apply rule 'check_ups_output_source' (in /etc/icinga2/zones.d/master/services.d/services.ups.conf: 537:1-537:39) for type 'Service' does not match anywhere!
[2021-11-22 18:27:00 +0300] warning/ApplyRule: Apply rule 'check_ups_battary_status' (in /etc/icinga2/zones.d/master/services.d/services.ups.conf: 547:1-547:40) for type 'Service' does not match anywhere!
[2021-11-22 18:27:00 +0300] warning/ApplyRule: Apply rule 'check_ups_battery_capacity' (in /etc/icinga2/zones.d/master/services.d/services.ups.conf: 557:1-557:42) for type 'Service' does not match anywhere!
[2021-11-22 18:27:00 +0300] warning/ApplyRule: Apply rule 'check_ups_ambient_temp' (in /etc/icinga2/zones.d/master/services.d/services.ups.conf: 567:1-567:38) for type 'Service' does not match anywhere!
[2021-11-22 18:27:00 +0300] warning/ApplyRule: Apply rule 'check_root_dc_params' (in /etc/icinga2/zones.d/master/services.d/services.windows.conf: 512:1-512:36) for type 'Service' does not match anywhere!
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 43836 Notifications.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 18022 Dependencies.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 1 IcingaApplication.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 8 NotificationCommands.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 82 HostGroups.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 975 Hosts.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 265 Downtimes.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 1 Comment.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 1 FileLogger.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 1 CheckerComponent.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 1 ApiListener.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 1 IdoMysqlConnection.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 2 Zones.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 1 ExternalCommandListener.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 2 Endpoints.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 1 ApiUser.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 282 CheckCommands.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 1 NotificationComponent.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 29 UserGroups.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 35 Users.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 6 TimePeriods.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 124 ServiceGroups.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 1 ScheduledDowntime.
[2021-11-22 18:27:00 +0300] information/ConfigItem: Instantiated 9984 Services.
[2021-11-22 18:27:01 +0300] information/ScriptGlobal: Dumping variables to file '/var/cache/icinga2/icinga2.vars'
[2021-11-22 18:27:01 +0300] information/cli: Finished validating the configuration file(s).


Hi
Maybe somebody cah help. I have notifications to each alert by telegram, mail and cell phone. And I need to silent(maybe sticky ack.) only cell phone notifications from 7AM till 9PM for specific users or usergroup. And I donā€™t understand how to do itā€¦ I know this is very strange feature

I tried a lot of methods but no one helped me. Read a lot of community blocks.
If I correctly understand I need to use some builtin macros which can see some variable with notification cell phone command and hostname.

Maybe something like this

  ...
  if ( notification.name == "phone-service-sender") {
    period = "7to9"
  } else {
    period = "24x7"
  }
  ...

but I understand that I canā€™t call notification.name from users space, and also i need to get current hostname

Thank you!

Current config:
notifications.sender.conf

apply Notification "phone-host-sender" to Host {
  import "phone-host-notification"
  user_groups = host.vars.notification.pager.groups
  users = host.vars.notification.pager.users
  interval = 0
  assign where host.vars.notification.pager
}

apply Notification "phone-service-sender" to Service {
  import "phone-service-notification"
  user_groups = host.vars.notification.pager.groups
  users = host.vars.notification.pager.users
  interval = 0
  assign where host.vars.notification.pager
}

users.conf

object User "username" {
  enable_notifications = true
  display_name = "username"
  groups = [ "all device [contact group]" ]
  email = "EMAIL"
  pager = "CELL PHONE"
  vars.telegram = "TELEGRAM"
  period = "24x7"
}

timeperiods.conf

object TimePeriod "24x7" {
  display_name = "Icinga 2 24x7 TimePeriod"
  ranges = {
    "monday"    = "00:00-24:00"
    "tuesday"   = "00:00-24:00"
    "wednesday" = "00:00-24:00"
    "thursday"  = "00:00-24:00"
    "friday"    = "00:00-24:00"
    "saturday"  = "00:00-24:00"
    "sunday"    = "00:00-24:00"
  }
}

object TimePeriod "7to9" {
  display_name = "Icinga 2 work hours TimePeriod"
  ranges = {
    "monday"    = "00:00-09:00,21:00-24:00"
    "tuesday"   = "00:00-09:00,21:00-24:00"
    "wednesday" = "00:00-09:00,21:00-24:00"
    "thursday"  = "00:00-09:00,21:00-24:00"
    "friday"    = "00:00-09:00,21:00-24:00"
    "saturday"  = "00:00-24:00"
    "sunday"    = "00:00-24:00"
  }
}

Easiest way is to have 2 notification rules, have one rule use email/telegram and the other use the cellphone. Both rules can use different (or same) time periods as needed.

There is this section of the documentation that might help you achieve what you need without creating multiple rules.

Thank you, for your answer.
thatā€™s right. Iā€™ve got it. Iā€™ve got 3 rules(templates) for host alerting by email, telegram, phone, and 3 rules for service alerting by email, telegram and phone which apply on each host.
Iā€™m trying it right now, like you said.
But sorry, maybe do you know some another way to do it? Problem is that I need to refactor all scheme of notification from nice to ugly view.
yeah, I understand that I want some strange, but maybe you know some another way.
If you donā€™t, then anyway thanks a lot!

@steaksauce
eventually, I had taken you advice and transformed him a little bit then I got solution for my problem.

I made not a 2 notification rules then 2 user object. First one with email\telegram and second only with cellphone. Or maybe you were just mean this exactly, but I didā€™t understand that )
Example:
user.conf

object User "USERNAME" {
  enable_notifications = true
  display_name = "USER NAME"
  groups = [ "all devices [contact group]" ]
  email = "USERNAME@MAIL"
  vars.telegram = "TELEGRAM"
  period = "24x7"
}

user.phone.conf

object User "USERNAME_PHONE" {
  enable_notifications = true
  display_name = "USER NAME(PHONE)"
  groups = [ "all devices [contact group]" ]
  pager = "CELLPHONE"
  period = "7to9"
}

p.s.: then to kept this straight, and donā€™t lose groups I added variable with cellphone to user.conf(vars.phone = ā€˜blablablaā€™) and incron service to watch on ā€œuser.confā€ and generate ā€œuser.phone.confā€.

Thank you!

1 Like