PowerShell, Nagios and NSClient++

Nagios is a very powerful open source tool for monitoring networks and infrastructures.  The number of plugins available on Nagios Exchange and extensions make this tool essential to not just to be reactive but to create workflows and escalations if needed in a matter of minutes.
The installation and configuration of this tool under a major linux distributions is not difficult.

The default tool for monitoring a Windows network are SCCM/SCOM and OMS, but if your environment is a mixed environment I think personally that Nagios can be considered a safe bet!

NSClient++ is the agent needed for performing some interesting checks on windows and you can leverage your powershell scripting ability to perform custom checks on the environment.

Once installed, copy your powershell script into the script folder of NSClient and add to the nsclient.ini file your script definition :

Just remember that NSClient will look for the exit code in your powershell script to triage the status:

  • exit 0, Normal
  • exit 1,  Warning
  • exit 2,  Critical

and use Write-OutPut if you want to provide a more verbose description of the error.

This is a simple example :

Why should you care about writing your own script?

Even if your requirements are standard the probability that you want to monitor and create an escalation event is pretty high. Think about how powerful can be when the event monitored by your powershell script is solved or mitigated by the script itself automatically.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.