How to monitor network card link status in zabbix

Ruslan Gustomyasov picture Ruslan Gustomyasov · Jul 18, 2013 · Viewed 7.6k times · Source

I need to monitor physical interfaces link status in zabbix, and wondering, if there an internal zabbix check for that, or i need to write my own. If so, how to determine if there is cable plugged in network card, and there is an voltage in the interface.

Answer

sxc731 picture sxc731 · Feb 7, 2017

So yes a UserParameter it is (even in Zabbix 3.0) and it's reasonably easy to setup, at least on modern Linux boxes. By parametrizing the UserParameter (if you follow...), it's possible to define a single Parameter to support monitoring of multiple NICs; here's how:

  1. On a target box, locate the agent's directory where UserParamter definitions are stored, smth like /etc/zabbix/zabbix_agentd.d/
  2. Create a new file for the definition or amend an existing one; I did this:

    cat > /etc/zabbix/zabbix_agentd.d/userparameter_niclink.conf << EOF
    UserParameter=net.if.link[*],cat /sys/class/net/$1/carrier
    EOF
    
  3. Restart the agent, eg: service zabbix-agent restart
  4. In the Zabbix UI, create an Item against the host as follows:
    • Type: Zabbix agent (active if appropriate).
    • Key: has the actual NIC to be monitored between brackets, eg: net.if.link[em1],
    • Type of information: Numeric (unsigned); Data type: Decimal
    • Show Value: as "Service state" (displays them as "Up/Down")
    • Application: Network Interfaces

That's it; go to Latest data; wait 30 secs or so and your NIC state should start populating. It might also be useful to define a Trigger against the Item to be alerted if the link goes down.

Here are some other ways to detect a NIC link's state; the above cat /sys/class/net/${nic}/carrier works well for me (Ubuntu 14.04 server, physical NIC).