Page 1 of 2

Event Handlers with Powershell

Posted: Tue Oct 22, 2013 3:35 am
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.

Re: Event Handlers with Powershell

Posted: Tue Oct 22, 2013 9:14 am
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)

Re: Event Handlers with Powershell

Posted: Tue Oct 22, 2013 9:30 am
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?

Re: Event Handlers with Powershell

Posted: Tue Oct 22, 2013 1:48 pm
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!

Re: Event Handlers with Powershell

Posted: Tue Oct 22, 2013 2:07 pm
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..

Re: Event Handlers with Powershell

Posted: Tue Oct 22, 2013 2:16 pm
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.

Re: Event Handlers with Powershell

Posted: Tue Oct 22, 2013 2:32 pm
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.

Re: Event Handlers with Powershell

Posted: Tue Oct 22, 2013 4:37 pm
by abrist
OP: Do you have any further questions for this thread?

Re: Event Handlers with Powershell

Posted: Tue Oct 22, 2013 4:37 pm
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! :)

Re: Event Handlers with Powershell

Posted: Wed Oct 23, 2013 2:24 am
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