Script

– Nagios + SCOM – Uninstall Nagios Agent remotely using Powershell

I don’t like to clean up very much, but there are certain cases where it really makes fun to clean up. Especially if there a Non-Microsoft product, Powershell and SCOM involved.

In my case a customer decided to replace his Nagios system through SCOM 2012. Cool!!!

Because Nagios also uses an agent for monitoring, one of my first things I did was to write a script to uninstall the Nagios agent from several windows systems.

The idea is to provide a text file containing server names which the script will use to check if the Nagios agent (service) is installed or not. If the service is installed it will uninstall the software. I don’t delete the source files though. I found the sources in the C:\NagiosClient\WindowsClient directory. The “NSClient++.exe” is the actual installation file for the Nagios agent.

The service looks like this…

1

…and the source files for Nagios like this…

2

The logic behind the script is like that:

  1. Define a UNC path to provide a place to store the log file and the server.txt file $serverfile) which has one server name per line.

image

  • $nagiospath defines the directory where the “NSClient++.exe” file is installed on the servers
  • $log defines the log file path
  • Next the script will read the $serverfile and iterate through each server and checks if the “NSClientpp” service is installed. If this is the case it will call the Invoke-WmiMethod to uninstall the agent remotely. Lastly the time, action and server name is being written to the log file.

And here is the script:

image

So far I tested the script against Windows 2008 R2 and Windows 2003 servers and it worked.

Start doing some spring cleaning and get rid off Nagios and install SCOM 2012!

You can download the script here.

3 Replies to “– Nagios + SCOM – Uninstall Nagios Agent remotely using Powershell

  1. Hi,
    to replace a Nagios implementation is a good idea. But in larger environments we need a transition phase. Did you know a nagios to scom connector?
    Thx Norman

    1. Hi Norman,

      Well, a transition phase could be to let Nagios run as before and implement SCOM in parallel. Then deploy SCOM and the SCOM Agent to the Servers and if the SCOM Monitoring is o.k. remove the Nagios Agent from the servers.

      I don’t know a nagios to scomconnector.

      Regards,

      Stefan

  2. There’s an error in your script. The ; before the final ‘else’ is wrong. The ; closes your if statemant and it can’t go to else anymore.

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.