Sensu plugin to check NIC on windows and linux is it up or down and alert

Is there ant sensu plugin or extension that can solve my problem on an easy way? We need to have a new sensu check deployed to all Linux and Windows servers that alerts us when NICs are down.

I’m not aware of a prexisting check for this, but I can help you with the linux situation.

if you are running a reasonably recent linux and you know the device name of the nic you can do something like this as your check command

grep -q “up” /sys/class/net/<device_name>/operstate

where you replace <device_name> with the name of the nic.

On my system this will return exit status:
0 if the device is up
1 if the device exists and is down
2 if the device does not exist

Working example on my laptop for my currently unplugged wired connection:

grep -q “up” /sys/class/net/enp0s31f6/operstate
returns exit status 1, device exists and connection is down

For my wifi nic:
grep -q "up" /sys/class/net/wlp3s0/operstate ; echo $?
returns exit status of 0, device exists and connection is up

I’m not much help with Windows, as I don’t have day to day operational knowledge. But If you can write a powershell script to check the nic status and return 0,1 or 2 accordingly. Maybe another Windows user in the community can help with that.

Thank you very much the help, actually my question is on the sensu side, how to implement the script to alert. The script I have just the sensu side is not clear how to implement :slight_smile:

Here’s the check configuration yaml file that makes use of the command example I gave previously:

type: CheckConfig
api_version: core/v2
  name: nic_check
  command: grep -q "up" /sys/class/net/enp0s31f6/operstate
  interval: 60
  publish: true
  - linux

I have this check running now on my laptop and it’s alerting with a warning, indicating the nic is down:

sensuctl event info fedora_laptop nic_check
=== summit-yolo - nic_check
Entity: summit-yolo
Check: nic_check
Status: 1
History: 1,1,1,1,1
Silenced: false
Timestamp: 2019-10-10 00:27:22 -0800 AKDT

Thank you very much, I’ll take a look :wink:

yeah, sorry i’m no help with the Windows specifics…
but the general pattern for creating checks using your own custom commands goes like this:

  1. write a script that does what you want manually on the target and make sure it returns status 0,1,2 for conditions of interest.
  2. call that script as the “check command” in the Sensu check configuration.
  3. If needed package up dependancies with the script in an asset

So once you have a powershell script for Windows that does what you want, you should be able to use it as a check command.

Okay, thank you so much :slight_smile: