object Host "" { check_command = "dummy" vars.int["Port 0/1"] = { int = "gigabitethernet1/0/1" port_type = "uplink" } vars.int["Port 0/2"] = { int = "gigabitethernet1/0/2" port_type = "workstation" } } globals.get_host_interfaces = function(interfaces, port_type_filter, exclude_enabled) { var res = {} if (typeof(interfaces) != Dictionary) { log(LogWarning, "get_host_interfaces", "interfaces parameter is not a Dictionary, but " + typeof(interfaces).to_string() + " (value: '" + Json.encode(interfaces) + "')") return res // empty } //debugger for (ifname => ifvalues in interfaces) { log(LogInformation, "get_host_interfaces", "Evaluating interface " + ifname + " with values: '" + Json.encode(ifvalues) + "'") if (typeof(ifvalues) != Dictionary) { log(LogInformation, "get_host_interfaces", "Wrong type for ifvalues for ifname + " + ifname) return {} } log(LogInformation, "get_host_interfaces", "Port_type_filter: " + port_type_filter + " ifvalues.port_type: " + ifvalues.port_type) if (exclude_enabled) { log(LogInformation, "get_host_interfaces", "exclude enabled") } else { log(LogInformation, "get_host_interfaces", "exclude disabled") } if (exclude_enabled == true && !match(port_type_filter, ifvalues.port_type)) { log(LogInformation, "get_host_interfaces", "Matched port_type: " + ifvalues.port_type) res[ifname] = ifvalues log(LogInformation, "get_host_interfaces", "Adding to result: " + Json.encode(res)) } else if (exclude_enabled == false && match(port_type_filter, ifvalues.port_type)) { log(LogInformation, "get_host_interfaces", "Matched port_type: " + ifvalues.port_type) res[ifname] = ifvalues log(LogInformation, "get_host_interfaces", "Adding to result: " + Json.encode(res)) } else { log(LogInformation, "get_host_interfaces", "Nothing matched") } } log(LogInformation, "get_host_interfaces", "Result: " + Json.encode(res)) return res } /* use this service definition for any port type other than a workstation */ apply Service for (int => config in get_host_interfaces(host.vars.int, "*workstation*", true)) { check_command = "dummy" vars += config } /* use this service definition for workstations */ apply Service "Workstation: " for (int => config in get_host_interfaces(host.vars.int, "*workstation*", false)) { check_command = "dummy" vars += config }