3

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.

3 Answers3

3

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

Community
  • 1
  • 1
sxc731
  • 2,418
  • 2
  • 28
  • 30
  • 1
    As an improvement I suggent using the following line in `/etc/zabbix/zabbix_agentd.d/userparameter_niclink.conf`: `UserParameter=net.if.link[*],if [ -r /sys/class/net/$1/carrier ] ; then cat /sys/class/net/$1/carrier ; else echo 0 ; fi` This prevents the item from going to "unsupported" state. – dsteinkopf Mar 10 '17 at 09:30
1

No, there is no such check. You can achieve it using UserParameter. As for how, depends on the OS that runs the agent. On linux you can use either mii-tool or ethtool to check periodically. Or you can do some scripting and connect to D-Bus if you use NetworkManager. Or you can monitor the system logs, drivers usually log link detection to the kernel log.

On windows I have no idea. Probably netsh or ipconfig with some findstr can get you on polling the status. Or powershell. Ask on serverfault, I bet you will have exact answers.

Michael Tabolsky
  • 3,429
  • 2
  • 18
  • 11
1

@sxc731 is right, there is no such existing item in net.if keys.

If you want to make this solution universal, you can use discovery rules for discovering network interfaces. This will find all interfaces, also the virtual, bridge, etc. But you can use regular expressions to match only interfaces which are physical. I was deploying this in my work with multiple OS on many servers. Here is my approach:

  1. Create or use existing Zabbix template.
  2. In Administration -> General menu, go to Regular Expressions and do the following:
    1. Add new regular expression Physical network interface discovery.
    2. Use regular expression ^em[0-9]{1,}|p[0-9]{1,}p[0-9]{1,}|eth[0-9]{1,}|ens[0-9]{1,}$.
  3. Create a discovery rule to your template with key net.if.discovery.
  4. Create filter with Macro {#PHYSNET} and regular expression @Physical network interface discovery.
  5. Add item prototype with key net.if.link[{#PHYSNET}] and trigger if you need one.
  6. Create UserParameter on Zabbix client servers (example at the end).

There is one issue with using cat /sys/class/net/$1/carrier as UserParameter. If network interface is down (eg. with ip link set eth0 down), the result of cat command is Invalid Argument.

I personally use this one-liner for UserParameter:

UserParameter=net.if.link[*], if [ $(cat /sys/class/net/$1/operstate) = "up" ]; then cat /sys/class/net/$1/carrier; else echo "0"; fi;

Resources:

Chait
  • 1,052
  • 2
  • 18
  • 30
Lirt
  • 407
  • 5
  • 8