Switch port monitoring error: unknown interface

My Icinga gives the following error on all switch ports that I have configured.

prueba

This is the host file:

object Host “SwitchPASDpto” {
import “generic-host”
import “int-ports-template”
address = “SwitchIP”
vars.snmp_v3 = true
vars.snmp_nocrypt = false
vars.snmp_address = “SwicthIP”
vars.snmp_port = 161
vars.snmp_login = “MyUser”
vars.snmp_password = “MyPass”
vars.snmp_v3_use_authprotocol = true
vars.snmp_authprotocol = “md5,des”
vars.snmp_v3_use_privpass = true
vars.snmp_privpass = “MyPass”
}

This is the template that gives the error:

template Host “int-ports-template” {

vars.snmp_interfaces[“snmp-int-port1”] = {
vars.snmp_interface = “Slot0/1”
vars.snmp_interface_label = “port1”
}

vars.snmp_interfaces[“snmp-int-port2”] = {
vars.snmp_interface = “Slot0/2”
vars.snmp_interface_label = “port2”
}

vars.snmp_interfaces[“snmp-int-port3”] = {
vars.snmp_interface = “Slot0/3”
vars.snmp_interface_label = “port 03”
}
vars.snmp_interfaces[“snmp-int-port4”] = {
vars.snmp_interface = “Slot0/4”
vars.snmp_interface_label = “port 04”
}
}

This is the service that gives the “ERROR : Unknown interface eth0”:

apply Service for (interface => config in host.vars.snmp_interfaces) {
import “generic-service”
display_name = "Network traffic on " + config.snmp_interface_label
check_command = “snmp-interface”

vars.snmp_interface_ifname = “true”
vars.snmp_interface_bits_bytes = “true”
vars.snmp_interface_megabytes = “true”
vars.snmp_interface_noregexp = “true”
vars.snmp_warncrit_percent = “true”
vars.snmp_warn = “100,100”
vars.snmp_crit = “100,100”
vars += config

assign where host.vars.snmp_address
}

This are the port names according to snmpwalk on that switch:

No matter what changes I make on the template I just get the same “ERROR : Unknown interface eth0”

Can you inspect the command that was run under action?
Alternatively, enable the debug log and restart icinga, make sure the check run, disable the debug log, restart icinga and search the command in the log.

I checked the logs and found that it’s checking for a eth0 interface, if I execute that command I do obtain something searching for one of the ports.

Now my question would be how do I change that -n value, I guess it should be with the other config in the host file, or better yet in the template one for each port, but I’m not finding anything about how to change that value.

Thank you very much for your fast response.

Fixed it with this change to the service:

apply Service for (interface => config in host.vars.snmp_interfaces) {
import “generic-service”
display_name = "Network traffic for " + config.vars.snmp_interface
check_command = “snmp-interface”
vars.snmp_interface = config.vars.snmp_interface
vars.snmp_interface_ifname = “true”
vars.snmp_interface_bits_bytes = “true”
vars.snmp_interface_megabytes = “true”
vars.snmp_interface_noregexp = “true”
vars.snmp_warncrit_percent = “true”
vars.snmp_warn = “70,80”
vars.snmp_crit = “80,100”
vars += config

assign where host.vars.snmp_address
}

This way it establishes the different interface in each iteration.