How are you handling notification rules (DSL only)?

➜  icinga2 git:(master) cat example.conf
object CheckCommand "cc" {
 command = [ "true" ]
}

object Host "h" {
 check_command = "cc"
}

apply Service "s" {
 check_command = "cc"
 vars.users = [ "u" ]
 assign where true
}

object User "u" {
 vars.mail = [ Warning, Critical, Unknown ]
 vars.sms = [ Critical ]
}

object NotificationCommand "mail" {
 command = [ "true" ]
}

apply Notification "mail-" for (user in service.vars.users) to Service {
 command = "mail"
 users = [ user ]
 states = get_object(User, user).vars.mail
}

object NotificationCommand "sms" {
 command = [ "true" ]
}

apply Notification "sms-" for (user in service.vars.users) to Service {
 command = "sms"
 users = [ user ]
 states = get_object(User, user).vars.sms
}
➜  icinga2 git:(master) prefix/sbin/icinga2 daemon -c example.conf -C
[2020-08-12 16:03:12 +0200] information/cli: Icinga application loader (version: v2.12.0)
[2020-08-12 16:03:12 +0200] information/cli: Loading configuration file(s).
[2020-08-12 16:03:12 +0200] information/ConfigItem: Committing config item(s).
[2020-08-12 16:03:12 +0200] information/ConfigItem: Instantiated 1 Host.
[2020-08-12 16:03:12 +0200] information/ConfigItem: Instantiated 1 IcingaApplication.
[2020-08-12 16:03:12 +0200] information/ConfigItem: Instantiated 2 Notifications.
[2020-08-12 16:03:12 +0200] information/ConfigItem: Instantiated 2 NotificationCommands.
[2020-08-12 16:03:12 +0200] information/ConfigItem: Instantiated 1 Service.
[2020-08-12 16:03:12 +0200] information/ConfigItem: Instantiated 1 User.
[2020-08-12 16:03:12 +0200] information/ConfigItem: Instantiated 1 CheckCommand.
[2020-08-12 16:03:12 +0200] information/ScriptGlobal: Dumping variables to file '/Users/aklimov/NET/WS/icinga2/prefix/var/cache/icinga2/icinga2.vars'
[2020-08-12 16:03:12 +0200] information/cli: Finished validating the configuration file(s).
➜  icinga2 git:(master) prefix/sbin/icinga2 object list
Object 'app' of type 'IcingaApplication':
  % declared in '', lines 0:0-0:0
  * __name = "app"
  * enable_event_handlers = true
  * enable_flapping = true
  * enable_host_checks = true
  * enable_notifications = true
  * enable_perfdata = true
  * enable_service_checks = true
  * environment = ""
  * name = "app"
  * package = ""
  * source_location
    * first_column = 0
    * first_line = 0
    * last_column = 0
    * last_line = 0
    * path = ""
  * templates = [ "app" ]
    % = modified in '', lines 0:0-0:0
  * type = "IcingaApplication"
  * vars = null
  * zone = ""

Object 'mail' of type 'NotificationCommand':
  % declared in 'example.conf', lines 20:1-20:33
  * __name = "mail"
  * arguments = null
  * command = [ "true" ]
    % = modified in 'example.conf', lines 21:2-21:21
  * env = null
  * execute
    % = modified in 'methods-itl.conf', lines 23:3-23:30
    * arguments = [ "notification", "user", "cr", "itype", "author", "comment", "resolvedMacros", "useResolvedMacros" ]
    * deprecated = false
    * name = "Internal#PluginNotification"
    * side_effect_free = false
    * type = "Function"
  * name = "mail"
  * package = "_etc"
  * source_location
    * first_column = 1
    * first_line = 20
    * last_column = 33
    * last_line = 20
    * path = "example.conf"
  * templates = [ "mail", "plugin-notification-command" ]
    % = modified in 'example.conf', lines 20:1-20:33
    % = modified in 'methods-itl.conf', lines 22:2-22:122
  * timeout = 60
  * type = "NotificationCommand"
  * vars = null
  * zone = ""

Object 'sms' of type 'NotificationCommand':
  % declared in 'example.conf', lines 30:1-30:32
  * __name = "sms"
  * arguments = null
  * command = [ "true" ]
    % = modified in 'example.conf', lines 31:2-31:21
  * env = null
  * execute
    % = modified in 'methods-itl.conf', lines 23:3-23:30
    * arguments = [ "notification", "user", "cr", "itype", "author", "comment", "resolvedMacros", "useResolvedMacros" ]
    * deprecated = false
    * name = "Internal#PluginNotification"
    * side_effect_free = false
    * type = "Function"
  * name = "sms"
  * package = "_etc"
  * source_location
    * first_column = 1
    * first_line = 30
    * last_column = 32
    * last_line = 30
    * path = "example.conf"
  * templates = [ "sms", "plugin-notification-command" ]
    % = modified in 'example.conf', lines 30:1-30:32
    % = modified in 'methods-itl.conf', lines 22:2-22:122
  * timeout = 60
  * type = "NotificationCommand"
  * vars = null
  * zone = ""

Object 'u' of type 'User':
  % declared in 'example.conf', lines 15:1-15:15
  * __name = "u"
  * display_name = "u"
  * email = ""
  * enable_notifications = true
  * groups = [ ]
  * name = "u"
  * package = "_etc"
  * pager = ""
  * period = ""
  * source_location
    * first_column = 1
    * first_line = 15
    * last_column = 15
    * last_line = 15
    * path = "example.conf"
  * states = null
  * templates = [ "u" ]
    % = modified in 'example.conf', lines 15:1-15:15
  * type = "User"
  * types = null
  * vars
    * mail = [ "Warning", "Critical", "Unknown" ]
      % = modified in 'example.conf', lines 16:2-16:43
    * sms = [ "Critical" ]
      % = modified in 'example.conf', lines 17:2-17:24
  * zone = ""

Object 'cc' of type 'CheckCommand':
  % declared in 'example.conf', lines 1:0-1:23
  * __name = "cc"
  * arguments = null
  * command = [ "true" ]
    % = modified in 'example.conf', lines 2:2-2:21
  * env = null
  * execute
    % = modified in 'methods-itl.conf', lines 19:3-19:23
    * arguments = [ "checkable", "cr", "resolvedMacros", "useResolvedMacros" ]
    * deprecated = false
    * name = "Internal#PluginCheck"
    * side_effect_free = false
    * type = "Function"
  * name = "cc"
  * package = "_etc"
  * source_location
    * first_column = 0
    * first_line = 1
    * last_column = 23
    * last_line = 1
    * path = "example.conf"
  * templates = [ "cc", "plugin-check-command" ]
    % = modified in 'example.conf', lines 1:0-1:23
    % = modified in 'methods-itl.conf', lines 18:2-18:94
  * timeout = 60
  * type = "CheckCommand"
  * vars = null
  * zone = ""

Object 'h' of type 'Host':
  % declared in 'example.conf', lines 5:1-5:15
  * __name = "h"
  * action_url = ""
  * address = ""
  * address6 = ""
  * check_command = "cc"
    % = modified in 'example.conf', lines 6:2-6:21
  * check_interval = 300
  * check_period = ""
  * check_timeout = null
  * command_endpoint = ""
  * display_name = "h"
  * enable_active_checks = true
  * enable_event_handler = true
  * enable_flapping = false
  * enable_notifications = true
  * enable_passive_checks = true
  * enable_perfdata = true
  * event_command = ""
  * flapping_threshold = 0
  * flapping_threshold_high = 30
  * flapping_threshold_low = 25
  * groups = [ ]
  * icon_image = ""
  * icon_image_alt = ""
  * max_check_attempts = 3
  * name = "h"
  * notes = ""
  * notes_url = ""
  * package = "_etc"
  * retry_interval = 60
  * source_location
    * first_column = 1
    * first_line = 5
    * last_column = 15
    * last_line = 5
    * path = "example.conf"
  * templates = [ "h" ]
    % = modified in 'example.conf', lines 5:1-5:15
  * type = "Host"
  * vars = null
  * volatile = false
  * zone = ""

Object 'h!s' of type 'Service':
  % declared in 'example.conf', lines 9:1-9:17
  * __name = "h!s"
  * action_url = ""
  * check_command = "cc"
    % = modified in 'example.conf', lines 10:2-10:21
  * check_interval = 300
  * check_period = ""
  * check_timeout = null
  * command_endpoint = ""
  * display_name = "s"
  * enable_active_checks = true
  * enable_event_handler = true
  * enable_flapping = false
  * enable_notifications = true
  * enable_passive_checks = true
  * enable_perfdata = true
  * event_command = ""
  * flapping_threshold = 0
  * flapping_threshold_high = 30
  * flapping_threshold_low = 25
  * groups = [ ]
  * host_name = "h"
    % = modified in 'example.conf', lines 9:1-9:17
  * icon_image = ""
  * icon_image_alt = ""
  * max_check_attempts = 3
  * name = "s"
    % = modified in 'example.conf', lines 9:1-9:17
  * notes = ""
  * notes_url = ""
  * package = "_etc"
    % = modified in 'example.conf', lines 9:1-9:17
  * retry_interval = 60
  * source_location
    * first_column = 1
    * first_line = 9
    * last_column = 17
    * last_line = 9
    * path = "example.conf"
  * templates = [ "s" ]
    % = modified in 'example.conf', lines 9:1-9:17
  * type = "Service"
  * vars
    * users = [ "u" ]
      % = modified in 'example.conf', lines 11:2-11:21
  * volatile = false
  * zone = ""

Object 'h!s!sms-u' of type 'Notification':
  % declared in 'example.conf', lines 34:1-34:69
  * __name = "h!s!sms-u"
  * command = "sms"
    % = modified in 'example.conf', lines 35:2-35:16
  * command_endpoint = ""
  * host_name = "h"
    % = modified in 'example.conf', lines 34:1-34:69
  * interval = 1800
  * name = "sms-u"
  * package = "_etc"
    % = modified in 'example.conf', lines 34:1-34:69
  * period = ""
  * service_name = "s"
    % = modified in 'example.conf', lines 34:1-34:69
  * source_location
    * first_column = 1
    * first_line = 34
    * last_column = 69
    * last_line = 34
    * path = "example.conf"
  * states = [ "Critical" ]
    % = modified in 'example.conf', lines 37:2-37:41
  * templates = [ "sms-u" ]
    % = modified in 'example.conf', lines 34:1-34:69
  * times = null
  * type = "Notification"
  * types = null
  * user_groups = null
  * users = [ "u" ]
    % = modified in 'example.conf', lines 36:2-36:17
  * vars = null
  * zone = ""

Object 'h!s!mail-u' of type 'Notification':
  % declared in 'example.conf', lines 24:1-24:70
  * __name = "h!s!mail-u"
  * command = "mail"
    % = modified in 'example.conf', lines 25:2-25:17
  * command_endpoint = ""
  * host_name = "h"
    % = modified in 'example.conf', lines 24:1-24:70
  * interval = 1800
  * name = "mail-u"
  * package = "_etc"
    % = modified in 'example.conf', lines 24:1-24:70
  * period = ""
  * service_name = "s"
    % = modified in 'example.conf', lines 24:1-24:70
  * source_location
    * first_column = 1
    * first_line = 24
    * last_column = 70
    * last_line = 24
    * path = "example.conf"
  * states = [ "Warning", "Critical", "Unknown" ]
    % = modified in 'example.conf', lines 27:2-27:42
  * templates = [ "mail-u" ]
    % = modified in 'example.conf', lines 24:1-24:70
  * times = null
  * type = "Notification"
  * types = null
  * user_groups = null
  * users = [ "u" ]
    % = modified in 'example.conf', lines 26:2-26:17
  * vars = null
  * zone = ""
➜  icinga2 git:(master)
2 Likes