Is it possible to monitor the Interface-Usage of only one interface & Interface-Status of all interfaces of a cisco ASR using "check_nwc"

Tried with the below in services.conf. We need to monitor the Interface-Usage of GigabitEthernet0/0/0 only & Interface-Status of all interfaces of a cisco ASR using “check_nwc”

apply Service “Interface-Usage” for (if_name => config in host.vars.interfaces){
import “service_check”
check_command = “check_nwc”
vars.nwc_mode = "interface-usage
vars.nwc_name = if_name
vars.nwc_warning = 80
vars.nwc_critical = 90
assign where “ASR” in host.groups && host.vars.interfaces == “GigabitEthernet0/0/0”
}

Hi @prajithvs

host.vars.interfaces is a dictionary. If you change the assign rule to

assign where "ASR" in host.groups && host.vars.interfaces["GigabitEthernet0/0/0"]

it should work.

Kind regards

Hi @ritzgu

There are 8 interfaces in this device. I need to monitor all the interface-status. But need to monitor only the interface-usage of GigabitEthernet0/0/0. Tried the below. But I am getting the usage of all the 8 interfaces.

apply Service “Interface-Usage” for (if_name => config in host.vars.interfaces){
import “service_check”
check_command = “check_nwc”
vars.nwc_mode = “interface-usage”
vars.nwc_name = if_name
vars.nwc_warning = 80
vars.nwc_critical = 90
assign where “ASR” in host.groups && host.vars.interfaces[“GigabitEthernet0/0/0”]
}

My bad. What if you create a new dictionary for this?
Maybe another possbile way: you could write a function to “filter” the interfaces beforehand:

object Host "test" {
        check_command = "dummy"
        vars.interfaces["test-1"] = {
                usage = true
        }
        vars.interfaces["test-2"] = {
                usage = false
        }
}

apply Service "interfaces-usage" for (int => config in get_interfaces_with_usage(host.vars.interfaces)) {
        check_command = "dummy"
        vars += config
}

globals.get_interfaces_with_usage = function(interfaces) {
  var res = {}
  for (ifname => ifvalues in interfaces) {
    if (ifvalues.usage) {
        res[ifname] = ifvalues
    }
  }
  return res
}

(inspired by this post)

Just tested it and it seems to be working.

Kind regards

We got a simpler method. Which is working fine for us

apply Service “Interface-Usage of Ethernet0/0/0” {
import “service_check”
check_command = “check_nwc”
vars.nwc_mode = “interface-usage”
vars.nwc_name = “Ethernet0/0/0”
vars.nwc_warning = 80
vars.nwc_critical = 90
assign where “Cisco” in host.groups
}

1 Like