From 912a2862782acbc17a248119cbf44887a8019b1c Mon Sep 17 00:00:00 2001 From: Ciaby Date: Fri, 29 May 2015 14:59:00 -0500 Subject: [PATCH] Customize Icinga2 configuration Add 30 seconds timeout to the apt check --- .../files/etc/icinga2/conf.d/apt.conf | 7 ++ .../files/etc/icinga2/conf.d/commands.conf | 42 +++++++ .../etc/icinga2/conf.d/custom_checks.conf | 11 ++ .../files/etc/icinga2/conf.d/downtimes.conf | 20 +++ .../files/etc/icinga2/conf.d/groups.conf | 37 ++++++ .../files/etc/icinga2/conf.d/hosts.conf | 52 ++++++++ .../etc/icinga2/conf.d/notifications.conf | 25 ++++ .../files/etc/icinga2/conf.d/satellite.conf | 33 +++++ .../files/etc/icinga2/conf.d/services.conf | 118 ++++++++++++++++++ .../files/etc/icinga2/conf.d/templates.conf | 72 +++++++++++ .../files/etc/icinga2/conf.d/timeperiods.conf | 43 +++++++ .../files/etc/icinga2/conf.d/users.conf | 17 +++ modules/rhizo_base/manifests/icinga.pp | 9 +- 13 files changed, 485 insertions(+), 1 deletion(-) create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/apt.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/commands.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/custom_checks.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/downtimes.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/groups.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/hosts.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/notifications.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/satellite.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/services.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/templates.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/timeperiods.conf create mode 100644 modules/rhizo_base/files/etc/icinga2/conf.d/users.conf diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/apt.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/apt.conf new file mode 100644 index 0000000..ca31f43 --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/apt.conf @@ -0,0 +1,7 @@ +apply Service "apt" { + import "generic-service" + + check_command = "apt_custom" + + assign where host.name == NodeName +} diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/commands.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/commands.conf new file mode 100644 index 0000000..f39cfcd --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/commands.conf @@ -0,0 +1,42 @@ +/* Command objects */ + +object NotificationCommand "mail-host-notification" { + import "plugin-notification-command" + + command = [ SysconfDir + "/icinga2/scripts/mail-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$" + USEREMAIL = "$user.email$" + } +} + +object NotificationCommand "mail-service-notification" { + import "plugin-notification-command" + + command = [ SysconfDir + "/icinga2/scripts/mail-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$" + USEREMAIL = "$user.email$" + } +} + diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/custom_checks.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/custom_checks.conf new file mode 100644 index 0000000..818cc5f --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/custom_checks.conf @@ -0,0 +1,11 @@ +object CheckCommand "apt_custom" { + import "plugin-check-command" + + command = [ PluginDir + "/check_apt" ] + + arguments = { + "-t" = "$apt_timeout$" + } + + vars.apt_timeout = "30" +} diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/downtimes.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/downtimes.conf new file mode 100644 index 0000000..0bed647 --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/downtimes.conf @@ -0,0 +1,20 @@ +/** + * The example downtime apply rule. + */ + +apply ScheduledDowntime "backup-downtime" to Service { + author = "icingaadmin" + comment = "Scheduled downtime for backup" + + ranges = { + monday = service.vars.backup_downtime + tuesday = service.vars.backup_downtime + wednesday = service.vars.backup_downtime + thursday = service.vars.backup_downtime + friday = service.vars.backup_downtime + saturday = service.vars.backup_downtime + sunday = service.vars.backup_downtime + } + + assign where service.vars.backup_downtime != "" +} diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/groups.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/groups.conf new file mode 100644 index 0000000..e6004a3 --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/groups.conf @@ -0,0 +1,37 @@ +/** + * Host group examples. + */ + +object HostGroup "linux-servers" { + display_name = "Linux Servers" + + assign where host.vars.os == "Linux" +} + +object HostGroup "windows-servers" { + display_name = "Windows Servers" + + assign where host.vars.os == "Windows" +} + +/** + * Service group examples. + */ + +object ServiceGroup "ping" { + display_name = "Ping Checks" + + assign where match("ping*", service.name) +} + +object ServiceGroup "http" { + display_name = "HTTP Checks" + + assign where match("http*", service.check_command) +} + +object ServiceGroup "disk" { + display_name = "Disk Checks" + + assign where match("disk*", service.check_command) +} diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/hosts.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/hosts.conf new file mode 100644 index 0000000..5ff1f9b --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/hosts.conf @@ -0,0 +1,52 @@ +/* + * Host definitions with object attributes + * used for apply rules for Service, Notification, + * Dependency and ScheduledDowntime objects. + * + * Tip: Use `icinga2 object list --type Host` to + * list all host objects after running + * configuration validation (`icinga2 daemon -C`). + */ + +/* + * This is an example host based on your + * local host's FQDN. Specify the NodeName + * constant in `constants.conf` or use your + * own description, e.g. "db-host-1". + */ + +object Host NodeName { + /* Import the default host template defined in `templates.conf`. */ + import "generic-host" + + /* Specify the address attributes for checks e.g. `ssh` or `http`. */ + address = "127.0.0.1" + address6 = "::1" + + /* Set custom attribute `os` for hostgroup assignment in `groups.conf`. */ + vars.os = "Linux" + + /* Define http vhost attributes for service apply rules in `services.conf`. */ + vars.http_vhosts["http"] = { + http_uri = "/" + } + /* Uncomment if you've sucessfully installed Icinga Web 2. */ + //vars.http_vhosts["Icinga Web 2"] = { + // http_uri = "/icingaweb2" + //} + + /* Define disks and attributes for service apply rules in `services.conf`. */ + vars.disks["disk"] = { + /* No parameters. */ + } + vars.disks["disk /"] = { + disk_partitions = "/" + } + + /* Define notification mail attributes for notification apply rules in `notifications.conf`. */ + vars.notification["mail"] = { + /* The UserGroup `icingaadmins` is defined in `users.conf`. */ + groups = [ "icingaadmins" ] + } +} + diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/notifications.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/notifications.conf new file mode 100644 index 0000000..fd3af73 --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/notifications.conf @@ -0,0 +1,25 @@ +/** + * The example notification apply rules. + * + * Only applied if host/service objects have + * the custom attribute `notification` defined + * and containing `mail` as key. + * + * Check `hosts.conf` for an example. + */ + +apply Notification "mail-icingaadmin" to Host { + import "mail-host-notification" + + user_groups = host.vars.notification.mail.groups + + assign where host.vars.notification.mail +} + +apply Notification "mail-icingaadmin" to Service { + import "mail-service-notification" + + user_groups = host.vars.notification.mail.groups + + assign where host.vars.notification.mail +} diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/satellite.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/satellite.conf new file mode 100644 index 0000000..4a6b97a --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/satellite.conf @@ -0,0 +1,33 @@ +/* + * Host and Service templates for the Agent Setup. + */ + + +/** + * Provides settings for satellite hosts managed by 'icinga2 repository'. + * Define your global attributes here, for example custom + * attributes used for notifications, etc. + */ +template Host "satellite-host" { + vars.notification["mail"] = { + groups = [ "icingaadmins" ] + } +} + +/** + * Provides settings for satellite services managed by 'icinga2 repository'. + * Define your global satellite attributes here, for example custom + * attributes used for notifications, etc. + */ +template Service "satellite-service" { + vars.notification["mail"] = { + groups = [ "icingaadmins" ] + } +} + + +apply Dependency "satellite-host" to Host { + parent_host_name = host.zone + + assign where host.zone != "" && "satellite-host" in host.templates +} diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/services.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/services.conf new file mode 100644 index 0000000..4decbcf --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/services.conf @@ -0,0 +1,118 @@ +/* + * Service apply rules. + * + * The CheckCommand objects `ping4`, `ping6`, etc + * are provided by the plugin check command templates. + * Check the documentation for details. + * + * Tip: Use `icinga2 object list --type Service` to + * list all service objects after running + * configuration validation (`icinga2 daemon -C`). + */ + +/* + * This is an example host based on your + * local host's FQDN. Specify the NodeName + * constant in `constants.conf` or use your + * own description, e.g. "db-host-1". + */ + +/* + * These are generic `ping4` and `ping6` + * checks applied to all hosts having the + * `address` resp. `address6` attribute + * defined. + */ +apply Service "ping4" { + import "generic-service" + + check_command = "ping4" + + assign where host.address +} + +apply Service "ping6" { + import "generic-service" + + check_command = "ping6" + + assign where host.address6 +} + +/* + * Apply the `ssh` service to all hosts + * with the `address` attribute defined and + * the custom attribute `os` set to `Linux`. + */ +apply Service "ssh" { + import "generic-service" + + check_command = "ssh" + + assign where (host.address || host.address6) && host.vars.os == "Linux" + ignore where host.name == "localhost" /* for upgrade safety */ +} + + + +apply Service for (http_vhost => config in host.vars.http_vhosts) { + import "generic-service" + + check_command = "http" + + vars += config +} + +apply Service for (disk => config in host.vars.disks) { + import "generic-service" + + check_command = "disk" + + vars += config +} + +apply Service "icinga" { + import "generic-service" + + check_command = "icinga" + + assign where host.name == NodeName +} + +apply Service "load" { + import "generic-service" + + check_command = "load" + + /* Used by the ScheduledDowntime apply rule in `downtimes.conf`. */ + vars.backup_downtime = "02:00-03:00" + + assign where host.name == NodeName +} + +apply Service "procs" { + import "generic-service" + + check_command = "procs" + + assign where host.name == NodeName +} + +apply Service "swap" { + import "generic-service" + + check_command = "swap" + + assign where host.name == NodeName +} + +apply Service "users" { + import "generic-service" + + check_command = "users" + + assign where host.name == NodeName +} + + + diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/templates.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/templates.conf new file mode 100644 index 0000000..3588f7f --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/templates.conf @@ -0,0 +1,72 @@ +/* + * Generic template examples. + */ + + +/** + * Provides default settings for hosts. By convention + * all hosts should import this template. + * + * The CheckCommand object `hostalive` is provided by + * the plugin check command templates. + * Check the documentation for details. + */ +template Host "generic-host" { + max_check_attempts = 3 + check_interval = 1m + retry_interval = 30s + + check_command = "hostalive" +} + +/** + * Provides default settings for services. By convention + * all services should import this template. + */ +template Service "generic-service" { + max_check_attempts = 5 + check_interval = 1m + retry_interval = 30s +} + +/** + * Provides default settings for users. By convention + * all users should inherit from this template. + */ + +template User "generic-user" { + +} + +/** + * Provides default settings for host notifications. + * By convention all host notifications should import + * this template. + */ +template Notification "mail-host-notification" { + command = "mail-host-notification" + + states = [ Up, Down ] + types = [ Problem, Acknowledgement, Recovery, Custom, + FlappingStart, FlappingEnd, + DowntimeStart, DowntimeEnd, DowntimeRemoved ] + + period = "24x7" +} + +/** + * Provides default settings for service notifications. + * By convention all service notifications should import + * this template. + */ +template Notification "mail-service-notification" { + command = "mail-service-notification" + + states = [ OK, Warning, Critical, Unknown ] + types = [ Problem, Acknowledgement, Recovery, Custom, + FlappingStart, FlappingEnd, + DowntimeStart, DowntimeEnd, DowntimeRemoved ] + + period = "24x7" +} + diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/timeperiods.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/timeperiods.conf new file mode 100644 index 0000000..21fac52 --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/timeperiods.conf @@ -0,0 +1,43 @@ +/** + * Sample timeperiods for Icinga 2 requiring + * 'legacy-timeperiod' template from the Icinga + * Template Library (ITL). + * Check the documentation for details. + */ + +object TimePeriod "24x7" { + import "legacy-timeperiod" + + 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 "9to5" { + import "legacy-timeperiod" + + display_name = "Icinga 2 9to5 TimePeriod" + ranges = { + "monday" = "09:00-17:00" + "tuesday" = "09:00-17:00" + "wednesday" = "09:00-17:00" + "thursday" = "09:00-17:00" + "friday" = "09:00-17:00" + } +} + +object TimePeriod "never" { + import "legacy-timeperiod" + + display_name = "Icinga 2 never TimePeriod" + ranges = { + } +} + diff --git a/modules/rhizo_base/files/etc/icinga2/conf.d/users.conf b/modules/rhizo_base/files/etc/icinga2/conf.d/users.conf new file mode 100644 index 0000000..515ef21 --- /dev/null +++ b/modules/rhizo_base/files/etc/icinga2/conf.d/users.conf @@ -0,0 +1,17 @@ +/** + * The example user 'icingaadmin' and the example + * group 'icingaadmins'. + */ + +object User "icingaadmin" { + import "generic-user" + + display_name = "Icinga 2 Admin" + groups = [ "icingaadmins" ] + + email = "icinga@localhost" +} + +object UserGroup "icingaadmins" { + display_name = "Icinga 2 Admin Group" +} diff --git a/modules/rhizo_base/manifests/icinga.pp b/modules/rhizo_base/manifests/icinga.pp index 061c55d..db45f6f 100644 --- a/modules/rhizo_base/manifests/icinga.pp +++ b/modules/rhizo_base/manifests/icinga.pp @@ -12,9 +12,16 @@ # class rhizo_base::icinga { - package { 'icinga2': + package { ['icinga2', 'icinga2-bin', 'icinga2-common', 'icinga2-doc']: ensure => '2.3.4~precise', require => Class['rhizo_base::apt'], } + file { '/etc/icinga2/conf.d': + ensure => directory, + source => 'puppet:///modules/rhizo_base/etc/icinga2/conf.d', + recurse => remote, + require => Package['icinga2'], + } + } \ No newline at end of file