diff --git a/manifests/icinga2/objects.pp b/manifests/icinga2/objects.pp index 8eabeef..ab4ef45 100644 --- a/manifests/icinga2/objects.pp +++ b/manifests/icinga2/objects.pp @@ -1,6 +1,7 @@ # Icinga2 object definitions class profile::icinga2::objects { include profile::icinga2::objects::templates + include profile::icinga2::objects::commands include profile::icinga2::objects::common_checks include profile::icinga2::objects::static_checks } diff --git a/manifests/icinga2/objects/commands.pp b/manifests/icinga2/objects/commands.pp new file mode 100644 index 0000000..b1d5e82 --- /dev/null +++ b/manifests/icinga2/objects/commands.pp @@ -0,0 +1,45 @@ +# Icinga2 object command definitions +class profile::icinga2::objects::commands { + + $command_file = '/etc/icinga2/conf.d/commands.conf' + + $hostenv = { + 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$', + USEREMAIL => '$user.email$', + } + + $serviceenv = $hostenv - 'HOSTOUTPUT' + { + SERVICEDESC => '$service.name$', + SERVICESTATE => '$service.state$', + SERVICEOUTPUT => '$service.output$', + SERVICEDISPLAYNAME => '$service.display_name$', + } + + ::icinga2::object::notificationcommand {'mail-host-notification': + command => ['/etc/icinga2/scripts/mail-host-notification.sh'], + env => $hostenv, + } + + ::icinga2::object::notificationcommand {'irc-host-notification': + command => ['/etc/icinga2/scripts/irc-host-notification.sh'], + env => $hostenv, + } + + ::icinga2::object::notificationcommand {'mail-service-notification': + command => ['/etc/icinga2/scripts/irc-service-notification.sh'], + env => $serviceenv, + } + + ::icinga2::object::notificationcommand {'irc-service-notification': + command => ['/etc/icinga2/scripts/irc-service-notification.sh'], + env => $serviceenv, + } +} diff --git a/manifests/icinga2/objects/templates.pp b/manifests/icinga2/objects/templates.pp index 3fc29b6..659708d 100644 --- a/manifests/icinga2/objects/templates.pp +++ b/manifests/icinga2/objects/templates.pp @@ -1,51 +1,65 @@ # Icinga2 object template definitions class profile::icinga2::objects::templates { $template_file = '/etc/icinga2/conf.d/templates.conf' ::icinga2::object::host {'generic-host': template => true, max_check_attempts => 3, check_interval => '1m', retry_interval => '30s', check_command => 'hostalive', target => $template_file, } ::icinga2::object::service {'generic-service': template => true, max_check_attempts => 5, check_interval => '1m', retry_interval => '30s', target => $template_file, } ::icinga2::object::user {'generic-user': template => true, target => $template_file, } - ::icinga2::object::notification {'mail-host-notification': + ::icinga2::object::notification {'host-notification': template => true, - command => 'mail-host-notification', states => ['Up', 'Down'], types => [ 'Problem', 'Acknowledgement', 'Recovery', 'Custom', 'FlappingStart', 'FlappingEnd', 'DowntimeStart', 'DowntimeEnd', 'DowntimeRemoved', ], period => '24x7', target => $template_file, } - ::icinga2::object::notification {'mail-service-notification': + ::icinga2::object::notification {'mail-host-notification': + template => true, + target => $template_file, + } + + ::icinga2::object::notification {'service-notification': template => true, - command => 'mail-service-notification', states => ['OK', 'Warning', 'Critical', 'Unknown' ], types => [ 'Problem', 'Acknowledgement', 'Recovery', 'Custom', 'FlappingStart', 'FlappingEnd', 'DowntimeStart', 'DowntimeEnd', 'DowntimeRemoved', ], period => '24x7', target => $template_file, } + + each(['host', 'service']) |$type| { + each(['irc', 'mail']) |$means| { + ::icinga2::object::notification {"${means}-${type}-notification": + template => true, + import => ["${type}-notification"], + command => "${means}-${type}-notification", + target => $template_file, + } + } + } }