object CheckCommand "dummy-host" {
    import "plugin-check-command"
    command = [ PluginDir + "/test_hostcheck.pl" ]
    arguments = {
            "--type"            = "$check_type$"
            "--failchance"      = "$check_failchance$"
            "--previous-state"  = "$check_previous_state$"
            "--state-duration"  = "$check_state_duration$"
            "--hostname"        = "$check_hostname$"
    }

    vars.check_type             = "UP"
    vars.check_failchance       = "2%"
    vars.check_previous_state   = "$state$"
    vars.check_state_duration   = "$duration_sec$"
    vars.check_hostname         = "$name$"
}

object CheckCommand "dummy-service" {
    import "plugin-check-command"
    command = [ PluginDir + "/test_servicecheck.pl" ]
    arguments = {
            "--total-critical-on-host"  = "$check_critical_on_host$"
            "--total-warning-on-host"   = "$check_warning_on_host$"
            "--type"                    = "$check_type$"
            "--failchance"              = "$check_failchance$"
            "--previous-state"          = "$check_previous_state$"
            "--state-duration"          = "$check_state_duration$"
            "--hostname"                = "$check_hostname$"
            "--servicedesc"             = "$check_servicedesc$"
    }
    vars.check_critical_on_host     = "$host.total_services_critical$"
    vars.check_warning_on_host      = "$host.total_services_warning$"
    vars.check_type                 = "random"
    vars.check_failchange           = "5%"
    vars.check_previous_state       = "$service.state$"
    vars.check_duration             = "$service.duration_sec$"
    vars.check_hostname             = "$host.name$"
    vars.check_servicedesc          = "$service.name$"
}

// Hostgroups
object HostGroup "all-hosts" {
    display_name = "All hosts on the system"
    assign where true
}

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)
    }
}

service_types = ["ok", "warning", "critical", "unknown", "flapping", "pending"]

// Servicegroups
__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(service_type, num) {
    apply Service "service-" + service_type + "-" + string(num + 1) {
        import "generic-service"

        check_command = "dummy-service"
        enable_active_checks = (service_type != "pending")
        vars.check_type = service_type

        assign where match("*" + service_type + "*", host.vars.check_config)
    }
}

__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 + 1) {
        import "generic-host"
        address = "127.0.0.1"
        check_command = "dummy-host"
        enable_active_checks = checkEnabled
        vars.check_type = checkType
        vars.check_config = checkConfig
    }
}

__for (num in range(10)) {
     createHost("ok", "ok", 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", "flapping", num, true)
}

// EOF
