From f6d42944f7ce296aac53e5d669800329c024ac06 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 14 May 2014 17:45:40 +0200 Subject: [PATCH] Update Vagrant Icinga 2 test config refs #6127 --- .../files/etc/icinga2/conf.d/test-config.conf | 131 +++++------------- 1 file changed, 35 insertions(+), 96 deletions(-) diff --git a/.vagrant-puppet/files/etc/icinga2/conf.d/test-config.conf b/.vagrant-puppet/files/etc/icinga2/conf.d/test-config.conf index ee13a0ebb..412307328 100644 --- a/.vagrant-puppet/files/etc/icinga2/conf.d/test-config.conf +++ b/.vagrant-puppet/files/etc/icinga2/conf.d/test-config.conf @@ -1,5 +1,4 @@ - -template CheckCommand "dummy-host-generic" { +object CheckCommand "dummy-host" { import "plugin-check-command" command = [ PluginDir + "/libexec/test_hostcheck.pl" ] arguments = { @@ -17,7 +16,7 @@ template CheckCommand "dummy-host-generic" { vars.check_hostname = "$name$" } -template CheckCommand "dummy-service-generic" { +object CheckCommand "dummy-service" { import "plugin-check-command" command = [ PluginDir + "/libexec/test_servicecheck.pl" ] arguments = { @@ -40,119 +39,59 @@ template CheckCommand "dummy-service-generic" { vars.check_servicedesc = "$service.name$" } -// Concrete check commands -object CheckCommand "dummy-host" { - import "dummy-host-generic" -} - -object CheckCommand "dummy-service" { - import "dummy-service-generic" -} - // Hostgroups object HostGroup "all-hosts" { display_name = "All hosts on the system" assign where true } -object HostGroup "all-ok" { - display_name = "All ok hosts" - assign where regex("^test-ok", host.name) +host_types = ["ok", "random", "down", "up", "unreachable", "pending"] + +__for (host_type in host_types) { + object HostGroup "all-" + host_type { + display_name = "All " + host_type + " hosts" + assign where regex("^test-" + host_type, host.name) + } } -object HostGroup "all-chaos" { - display_name = "All chaos hosts" - assign where regex("^test-random", host.name) -} - -object HostGroup "all-down" { - display_name = "All down hosts" - assign where regex("^test-down", host.name) -} - -object HostGroup "all-up" { - display_name = "All ok hosts" - assign where regex("^test-ok", host.name) -} - -object HostGroup "all-unreachable" { - display_name = "All ok hosts" - assign where regex("^test-unreachable", host.name) -} - -object HostGroup "all-pending" { - display_name = "All ok hosts" - assign where regex("^test-pending", host.name) -} +service_types = ["ok", "warning", "critical", "unknown", "flapping", "pending"] // Servicegroups -object ServiceGroup "service-ok" { - display_name = "All ok services" - assign where regex("^service-ok", service.name) -} - -object ServiceGroup "service-warning" { - display_name = "All warning services" - assign where regex("^service-warning", service.name) -} - -object ServiceGroup "service-critical" { - display_name = "All critical services" - assign where regex("^service-critical", service.name) -} - -object ServiceGroup "service-unknown" { - display_name = "All unknown services" - assign where regex("^service-unknown", service.name) -} - -object ServiceGroup "service-flapping" { - display_name = "All flapping services" - assign where regex("^service-flapping", service.name) -} - - -object ServiceGroup "service-pending" { - display_name = "All pending services" - assign where regex("^service-pending", service.name) -} - -// Config helper -function loop(count, func) { - count == 1 || loop(count - 1, func) - func(count) +__for (service_type in service_types) { + object ServiceGroup "service-" + service_type { + display_name = "All " + service_type + " services" + assign where regex("^service-" + service_type, service.name) + } } // --------------------------------------------------------------------------------------------------------------------- // Services // --------------------------------------------------------------------------------------------------------------------- -function createService(filter, num, checkEnabled) { - apply Service "service-" + filter + "-" + string(num) { +__function createService(service_type, num) { + apply Service "service-" + service_type + "-" + string(num + 1) { import "generic-service" - check_command = "dummy-service" - enable_active_checks = checkEnabled - vars.check_type = filter - assign where match("*" + filter + "*", host.vars.check_config) + + check_command = "dummy-service" + enable_active_checks = (service_type != "pending") + vars.check_type = service_type + + assign where match("*" + service_type + "*", host.vars.check_config) } } -loop(4, lambda num: { - createService("ok", num, true) - createService("warning", num, true) - createService("critical", num, true) - createService("flap", num, true) - createService("random", num, true) - createService("unknown", num, true) - createService("pending", num, false) -}) +__for (num in range(4)) { + __for (service_type in service_types) { + createService(service_type, num) + } +} // --------------------------------------------------------------------------------------------------------------------- // Hosts // --------------------------------------------------------------------------------------------------------------------- -function createHost(checkType, checkConfig, num, checkEnabled) { - object Host "test-" + checkType + "-" + string(num) { +__function createHost(checkType, checkConfig, num, checkEnabled) { + object Host "test-" + checkType + "-" + string(num + 1) { import "generic-host" address = "127.0.0.1" check_command = "dummy-host" @@ -162,13 +101,13 @@ function createHost(checkType, checkConfig, num, checkEnabled) { } } -loop(10, lambda num: { +__for (num in range(10)) { createHost("ok", "ok", num, true) - createHost("random", "random,flap", num, true) + createHost("random", "random,flapping", num, true) createHost("down", "warning,critical", num, true) createHost("unreachable", "unknown", num, true) createHost("pending", "pending", num, false) - createHost("flap", "flap", num, true) - }) + createHost("flap", "flapping", num, true) +} -// EOF \ No newline at end of file +// EOF