]> granicus.if.org Git - icinga2/commitdiff
Revamp sample configuration: add NodeName host, move services into apply rules schema
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 7 Nov 2014 00:10:56 +0000 (01:10 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 7 Nov 2014 03:13:45 +0000 (04:13 +0100)
fixes #7594

18 files changed:
debian/config/apt.conf
debian/config/kernel.conf
debian/icinga2-common.install
etc/CMakeLists.txt
etc/icinga2/conf.d/groups.conf
etc/icinga2/conf.d/hosts.conf [new file with mode: 0644]
etc/icinga2/conf.d/hosts/localhost.conf [deleted file]
etc/icinga2/conf.d/hosts/localhost/disk.conf [deleted file]
etc/icinga2/conf.d/hosts/localhost/http.conf [deleted file]
etc/icinga2/conf.d/hosts/localhost/icinga.conf [deleted file]
etc/icinga2/conf.d/hosts/localhost/load.conf [deleted file]
etc/icinga2/conf.d/hosts/localhost/procs.conf [deleted file]
etc/icinga2/conf.d/hosts/localhost/ssh.conf [deleted file]
etc/icinga2/conf.d/hosts/localhost/swap.conf [deleted file]
etc/icinga2/conf.d/hosts/localhost/users.conf [deleted file]
etc/icinga2/conf.d/notifications.conf
etc/icinga2/conf.d/services.conf
icinga2.spec

index 0222f2ba5a965827eecb2395dc76e7ded3f171c8..b2c77a0c1f29514d985fcaa449d680dd030d4895 100644 (file)
@@ -1,6 +1,7 @@
-object Service "apt" {
+apply Service "apt" {
   import "generic-service"
 
-  host_name = "localhost"
   check_command = "apt"
+
+  assign where host.name == NodeName
 }
index d8b061fa6c2023d0d807cb7afa52d90e49356a24..8817b2efa760fdddcfceadd9cb62ae05c3760736 100644 (file)
@@ -1,6 +1,7 @@
-object Service "kernel" {
+apply Service "kernel" {
   import "generic-service"
 
-  host_name = "localhost"
   check_command = "running_kernel"
+
+  assign where host.name == NodeName
 }
index 3badcf22190edd892cb1a66449dc937c27fb1bf9..219a0d5f6f9eab81ad97046500726343506c40fd 100644 (file)
@@ -1,4 +1,4 @@
-debian/config/apt.conf        etc/icinga2/conf.d/hosts/localhost
+debian/config/apt.conf        etc/icinga2/conf.d
 debian/tmp/etc/icinga2
 debian/tmp/etc/logrotate.d
 debian/tmp/etc/bash_completion.d
index 0ddaae47840e9c52bc8851d049c78698c79226fa..204e1e85ec4cfddcd582622e30855611a07a5ac1 100644 (file)
@@ -29,21 +29,13 @@ install_if_not_exists(icinga2/zones.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2)
 install_if_not_exists(icinga2/conf.d/commands.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d)
 install_if_not_exists(icinga2/conf.d/downtimes.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d)
 install_if_not_exists(icinga2/conf.d/groups.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d)
+install_if_not_exists(icinga2/conf.d/hosts.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d)
 install_if_not_exists(icinga2/conf.d/notifications.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d)
 install_if_not_exists(icinga2/conf.d/satellite.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d)
 install_if_not_exists(icinga2/conf.d/services.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d)
 install_if_not_exists(icinga2/conf.d/templates.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d)
 install_if_not_exists(icinga2/conf.d/timeperiods.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d)
 install_if_not_exists(icinga2/conf.d/users.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d)
-install_if_not_exists(icinga2/conf.d/hosts/localhost.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts)
-install_if_not_exists(icinga2/conf.d/hosts/localhost/disk.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
-install_if_not_exists(icinga2/conf.d/hosts/localhost/http.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
-install_if_not_exists(icinga2/conf.d/hosts/localhost/icinga.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
-install_if_not_exists(icinga2/conf.d/hosts/localhost/load.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
-install_if_not_exists(icinga2/conf.d/hosts/localhost/procs.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
-install_if_not_exists(icinga2/conf.d/hosts/localhost/ssh.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
-install_if_not_exists(icinga2/conf.d/hosts/localhost/swap.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
-install_if_not_exists(icinga2/conf.d/hosts/localhost/users.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
 install_if_not_exists(icinga2/features-available/api.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available)
 install_if_not_exists(icinga2/features-available/checker.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available)
 install_if_not_exists(icinga2/features-available/command.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available)
index 7b5bceb73add5f249e3eaf56dbcb533ae20990eb..e6004a324001d1752c959253271e3764a4414b9c 100644 (file)
@@ -33,5 +33,5 @@ object ServiceGroup "http" {
 object ServiceGroup "disk" {
   display_name = "Disk Checks"
 
-  assign where service.check_command == "disk"
+  assign where match("disk*", service.check_command)
 }
diff --git a/etc/icinga2/conf.d/hosts.conf b/etc/icinga2/conf.d/hosts.conf
new file mode 100644 (file)
index 0000000..ff9aef2
--- /dev/null
@@ -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 = "/icingaweb"
+  //}
+
+  /* Define disks and attributes for service apply rules in `services.conf`. */
+  vars.disks["disk"] = {
+    /* No parameters. */
+  }
+  vars.disks["disk /"] = {
+    disk_partition = "/"
+  }
+
+  /* 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/etc/icinga2/conf.d/hosts/localhost.conf b/etc/icinga2/conf.d/hosts/localhost.conf
deleted file mode 100644 (file)
index bbf2a8c..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * A host definition. You can create your own configuration files
- * in the conf.d directory (e.g. one per host). By default all *.conf
- * files in this directory are included.
- */
-object Host "localhost" {
-  import "generic-host"
-
-  address = "127.0.0.1"
-  address6 = "::1"
-
-  vars.os = "Linux"
-  vars.sla = "24x7"
-}
diff --git a/etc/icinga2/conf.d/hosts/localhost/disk.conf b/etc/icinga2/conf.d/hosts/localhost/disk.conf
deleted file mode 100644 (file)
index 55da9c4..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * The CheckCommand object `disk` is provided by
- * the plugin check command templates.
- * Check the documentation for details.
- */
-object Service "disk" {
-  import "generic-service"
-
-  host_name = "localhost"
-  check_command = "disk"
-  vars.sla = "24x7"
-}
diff --git a/etc/icinga2/conf.d/hosts/localhost/http.conf b/etc/icinga2/conf.d/hosts/localhost/http.conf
deleted file mode 100644 (file)
index cedded9..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * The CheckCommand object `http` is provided by
- * the plugin check command templates.
- * Check the documentation for details.
- */
-object Service "http" {
-  import "generic-service"
-
-  host_name = "localhost"
-  check_command = "http"
-  vars.sla = "24x7"
-}
diff --git a/etc/icinga2/conf.d/hosts/localhost/icinga.conf b/etc/icinga2/conf.d/hosts/localhost/icinga.conf
deleted file mode 100644 (file)
index 9583aa7..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * The CheckCommand object `icinga` is provided by
- * the icinga template library.
- * Check the documentation for details.
- */
-object Service "icinga" {
-  import "generic-service"
-
-  host_name = "localhost"
-  check_command = "icinga"
-  vars.sla = "24x7"
-}
diff --git a/etc/icinga2/conf.d/hosts/localhost/load.conf b/etc/icinga2/conf.d/hosts/localhost/load.conf
deleted file mode 100644 (file)
index 0919678..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * The CheckCommand object `load` is provided by
- * the plugin check command templates.
- * Check the documentation for details.
- */
-object Service "load" {
-  import "generic-service"
-
-  host_name = "localhost"
-  check_command = "load"
-  vars.sla = "24x7"
-
-  vars.backup_downtime = "02:00-03:00"
-}
diff --git a/etc/icinga2/conf.d/hosts/localhost/procs.conf b/etc/icinga2/conf.d/hosts/localhost/procs.conf
deleted file mode 100644 (file)
index c91c6de..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * The CheckCommand object `procs` is provided by
- * the plugin check command templates.
- * Check the documentation for details.
- */
-object Service "procs" {
-  import "generic-service"
-
-  host_name = "localhost"
-  check_command = "procs"
-  vars.sla = "24x7"
-}
diff --git a/etc/icinga2/conf.d/hosts/localhost/ssh.conf b/etc/icinga2/conf.d/hosts/localhost/ssh.conf
deleted file mode 100644 (file)
index b07d2a3..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * The CheckCommand object `ssh` is provided by
- * the plugin check command templates.
- * Check the documentation for details.
- */
-object Service "ssh" {
-  import "generic-service"
-
-  host_name = "localhost"
-  check_command = "ssh"
-  vars.sla = "24x7"
-}
diff --git a/etc/icinga2/conf.d/hosts/localhost/swap.conf b/etc/icinga2/conf.d/hosts/localhost/swap.conf
deleted file mode 100644 (file)
index 539cade..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * The CheckCommand object `swap` is provided by
- * the plugin check command templates.
- * Check the documentation for details.
- */
-object Service "swap" {
-  import "generic-service"
-
-  host_name = "localhost"
-  check_command = "swap"
-  vars.sla = "24x7"
-}
diff --git a/etc/icinga2/conf.d/hosts/localhost/users.conf b/etc/icinga2/conf.d/hosts/localhost/users.conf
deleted file mode 100644 (file)
index 4b6f45b..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * The CheckCommand object `users` is provided by
- * the plugin check command templates.
- * Check the documentation for details.
- */
-object Service "users" {
-  import "generic-service"
-
-  host_name = "localhost"
-  check_command = "users"
-  vars.sla = "24x7"
-}
index 88ee292d6a015a9c5a0a94ba0716f6eeed34ddf2..fd3af731863914454271117394c3c1edd6dc2b01 100644 (file)
@@ -2,21 +2,24 @@
  * The example notification apply rules.
  *
  * Only applied if host/service objects have
- * the custom attribute `sla` set to `24x7`.
+ * 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 = [ "icingaadmins" ]
+  user_groups = host.vars.notification.mail.groups
 
-  assign where host.vars.sla == "24x7"
+  assign where host.vars.notification.mail
 }
 
 apply Notification "mail-icingaadmin" to Service {
   import "mail-service-notification"
 
-  user_groups = [ "icingaadmins" ]
+  user_groups = host.vars.notification.mail.groups
 
-  assign where service.vars.sla == "24x7"
+  assign where host.vars.notification.mail
 }
index d973376a71f0a46803ed0abc3b406b0d59226ded..58665f8b4f86f5f03788f6f02378c5219ae4cf6c 100644 (file)
 /*
  * Service apply rules.
  *
- * Only applied if host objects are members of
- * the groups `linux-server` or `windows-server`
- * and having the `address` resp. `address6`
- * attribute set.
- *
- * The CheckCommand objects `ping4` and `ping6`
+ * 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"
-  vars.sla = "24x7"
 
-  assign where "linux-servers" in host.groups
-  assign where "windows-servers" in host.groups
-  ignore where host.address == ""
+  assign where host.address
 }
 
 apply Service "ping6" {
   import "generic-service"
 
   check_command = "ping6"
-  vars.sla = "24x7"
 
-  assign where "linux-servers" in host.groups
-  assign where "windows-servers" in host.groups
-  ignore where host.address6 == ""
+  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.vars.os == "Linux"
+}
+
+
+
+apply Service for (http_vhost => config in host.vars.http_vhosts) {
+  import "generic-service"
+
+  check_command = "http"
+
+  vars += config
+
+  assign where host.vars.http_vhosts
+}
+
+apply Service for (disk => config in host.vars.disks) {
+  import "generic-service"
+
+  check_command = "disk"
+
+  vars += config
+
+  assign where host.vars.disks
 }
 
+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
+}
+
+
+
index 6ea0d96fc6d5ff99b333dde884b528cd361948e6..3f80c2da549592367a8accbd4ee82f24416c5ec9 100644 (file)
@@ -467,8 +467,6 @@ exit 0
 %endif
 %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}
 %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/conf.d
-%attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/conf.d/hosts
-%attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/conf.d/hosts/localhost
 %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/features-available
 %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/features-enabled
 %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/repository.d
@@ -480,8 +478,6 @@ exit 0
 %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/constants.conf
 %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/zones.conf
 %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/conf.d/*.conf
-%config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/conf.d/hosts/*.conf
-%config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/conf.d/hosts/localhost/*.conf
 %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/features-available/*.conf
 %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/repository.d/*
 %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/zones.d/*