Event Handlers with Powershell

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Event Handlers with Powershell

Post by WillemDH »

Hello,

Just saw the documentation about event handlers Andy Wrote:
http://labs.nagios.com/2013/10/16/take- ... nagios-xi/

As we use 98 % Windows servers and all our scripts are Powershell based, is there anyone who knows how I could configure an event handler to execute a powershell script?

Thanks.
Nagios XI 5.8.1
https://outsideit.net
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Event Handlers with Powershell

Post by sreinhardt »

Your best option would be to call nrpe or another windows agent that would kick off your powershell script. On this same note, I have some very nice things in the works for powershell and nagios, along the lines of some solid enterprise M$ monitoring and a framework for others to script with. I'm hoping to have it tested and released in month or so. (sorry to hijack the thread, figured you might find it interesting if you're using powershell often)
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Event Handlers with Powershell

Post by WillemDH »

No problem. I'm very much interested to anything related to MS server monitoring. And yes we are using Powershell often. In fact I'm going to an advanced Powershell training the third week of November.
As I'm trying to make some more use of the quick actions (see my other thread I just made), it would be very nice to be able to somehow execute a powershell script from the quick action menu.
Things I have in mind for example if I could execute Powershell script from quick actions:
- Install new version of nsclient
- Update nsclient.ini (as we do realtime monitoring of eventlogs with nsclient), which works way better imo then nageventlog and the nsclient.ini tends to update a lot this way.
- Take a VMWare snapshot for virtual server
- Take a backup with Netbackup for physical server
- Install wsus updates and reboot
- Cleanup server temp files etc
- Upate McAfee agent

The possibilities are endless as we already have a lot of Powershell scripts. The question just remains how to do this with not too much work... I guess the quick action can't make use of nrpe to remotely execute ps scripts?
Nagios XI 5.8.1
https://outsideit.net
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Event Handlers with Powershell

Post by sreinhardt »

Provided you can kick those off with a call to check_nt or check_nrpe to run the powershell scripts you want, they absolutely should work via event handlers. Have fun at the class!
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Event Handlers with Powershell

Post by WillemDH »

So I could host all the Powershell script on some Windows console server, add the external commands to the nsclient.ini file on this console server and make a bash script which calls check_nrpe and reference an external command in the ini file. I'm gonna test this as soon as Michael Medin releases his 0.4.2. and will to try to add an action to the Windows hosts that kind of updates the agent from 0.4.1.101 to 0.4.2..
Nagios XI 5.8.1
https://outsideit.net
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Event Handlers with Powershell

Post by sreinhardt »

That would seem logical to me yes! Short of, I would never run a brand new install from nsclient. Personally I prefer to stick with the old 3.9 branch since everything is still beta\unstable anyway and I have yet to see major feature jumps that make me want to move.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Event Handlers with Powershell

Post by WillemDH »

Ok, we don't have any issues here with the 0.4.101. The only issue I have now is checkdisk has a problem with Windows quota's.
But realtime eventlog monitoring is imo a nice feature? I tried using nageventlog, but it was a nightmare to maintain and configure on multiple servers. Plus there is not a decent build for Windows Server 64 bit... And we have 75 % 64 bit.. And I don't want two 'monitor' related clients one a server....
I never worked with earlier builds, so I cant really compare.. :)

But 0.4.2 will have the ability to combine multiple performance counters in one service and have different thresholds for each counter. For example now I have for Exchange 2010, more than 30 performance counters. It wil be very nice when I'm able to combine some of them in one graph.
Nagios XI 5.8.1
https://outsideit.net
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Event Handlers with Powershell

Post by abrist »

OP: Do you have any further questions for this thread?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Event Handlers with Powershell

Post by slansing »

Well we are currently working on a way to stack your performance graphs together to compare them and view them all in one. This should be a great feature! :)
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Event Handlers with Powershell

Post by WillemDH »

I wrote a basic Powershell script to test connectivity and parameter passing:

Code: Select all

param(
	[Parameter(Mandatory=$true)][string]$hostname
)

$loglocal="c:\Nagios\NagiosInstallLog.txt"

if (!(Test-path -Path \\$hostname\c$\Nagios)) {
	New-Item -ItemType directory -Path \\$hostname\c$\Nagios
	$date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
	"$date : Directory created on $hostname" > $loglocal 	
	}
$logremote="\\$hostname\c$\Nagios\Nagioslog.txt"
	
$hostname > $log
Gonna start working on the bash script tomorrow to pass the parameter hostname. After that I can install the agent with:

Code: Select all

robocopy $packagefolder $PackageDest /R:1 /W:2
$InstallScript = "C:\Nagios\install.ps1"
$InstallString = "powershell.exe -File `"$InstallScript`""
$process = ([WMICLASS]"\\$hostname\ROOT\CIMV2:Win32_Process").Create($InstallString)
Could this thread be left open untill I made it work pls? :) I have the feeling I'll need some help with the bash script..... :oops: I'll share the scripts when I'm done.

Grtz
Nagios XI 5.8.1
https://outsideit.net
Locked