Page 1 of 2

exchange 2013 powershell script

Posted: Mon Mar 31, 2014 5:22 am
by MichielvM
Hi.

I got a request to monitor a Exchange 2013 server. Found a powershell script on the Exchange site.
I've tried to implement it, but run into a few things:

What I did:
Uploaded script to host in ~nsclient++\Scripts
Modified nsclient.ini file (section Wrapped Scripts)
Added command on Nagios Xi server
Added service.

When I click Apply configuration I get an error:

Code: Select all

Error: Service check command 'check_exch_2013_SiteMailbox ' specified in service 'check SiteMailbox' for host 'stb-exch-01' not defined anywhere!
Checked out the commands.cfg. It's there!

Code: Select all

define command {
       command_name                  	check_exch_2013_SiteMailbox 
       command_line                  		$USER1$/check_nrpe -H $HOSTADDRESS$ -c exchange_serverhealth $ARG2$
}
I'm missing something. Is there a clear step-by-step instruction as howto implement a powershell script in Nagios?

**Edit: I got it to work, but the powershell scripts fails with this:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H [IPADDRESS] -t 30 -c exchange_serverhealth -a SiteMailbox
Get-ServerHealth : Cannot process command because of one or more missing mandat
ory parameters: Identity.
At C:\Program Files\NSClient++\scripts\exchange-serverhealth.ps1:28 char:21
+ $HealthSetResult = (get-serverhealth |'Where-Object'=0 '{$_.HealthSetName'=0 '-eq'=0 '$He
alt'=0 '...
+'=0 '~~~~~~~~~~~~~~~~
'=0 '+'=0 'CategoryInfo'=0 ':'=0 'InvalidArgument:'=0 '(:)'=0 '[Get-ServerHealth],'=0 'Paramet'=0 '
'=0 'erBindingException
'=0 '+'=0 'FullyQualifiedErrorId'=0 ':'=0 'MissingMandatoryParameter,Microsoft.Exchange.Man'=0 '
'=0 'agement.Tasks.GetServerHealth
'=0 '
OK:'=0 'SiteMailbox'=0 '-'=0 '0'=0 'checks'=0 'are'=0 'OK'=0
The snapin is installed on the host (v1.0)
there's a lot of info out there on "missing mandatory parameter: identity"
But my powershell knowledge is barely existent, therefore at a loss...

Re: exchange 2013 powershell script

Posted: Mon Mar 31, 2014 10:41 am
by sreinhardt
Could you post a link to the script that you are attempting to use? I have tried out several of them with minimal issues, and could check this one out too if I have not already.

Re: exchange 2013 powershell script

Posted: Tue Apr 01, 2014 2:36 am
by MichielvM
http://exchange.nagios.org/directory/Pl ... th/details

This the script I tried. But I'm open to suggestions...

Re: exchange 2013 powershell script

Posted: Tue Apr 01, 2014 10:13 am
by sreinhardt
OK so based on your output there, the script ran, it got the needed arguent SiteMailbox, however my guess is that the $_.HealthSetName was not properly available on your system. So, let's try this by hand and see what we get. Open a powershell terminal with administrative rights, and run the following commands. Please send back full output sort of anything that needs to be sanitized.

Code: Select all

$status = 0
$HeathSet = "SiteMailbox"
add-pssnapin Microsoft.Exchange.Management.PowerShell.SnapIn
$HealthSetResult = get-serverhealth
$HealthSetResult | fl
$HealthSetResult.HealthSetName | fl

Re: exchange 2013 powershell script

Posted: Wed Apr 02, 2014 8:27 am
by detronict
On the third command I'm prompted to enter a "Identity"
When I enter the server name i get :

Code: Select all

WARNING: A server-side Active monitoring operation has failed. Active monitoring operation failed with message: Error
0x5 (Access is denied) from cli_RpccGenericRequest
command 4 and 5 give:

Code: Select all

PS C:\Users\admin_micman> $HealthSetResult | fl


Server                  : {servername}
CurrentHealthSetState   : Unknown
Name                    : Unknown
TargetResource          :
HealthSetName           : Unknown
HealthGroupName         : Unknown
AlertValue              : Unknown
FirstAlertObservedTime  : 1-1-0001 01:00:00
Description             :
IsHaImpacting           : False
RecurranceInterval      : 0
DefinitionCreatedTime   : 1-1-0001 01:00:00
HealthSetDescription    :
ServerComponentName     : Unknown
LastTransitionTime      : 1-1-0001 01:00:00
LastExecutionTime       : 1-1-0001 01:00:00
LastExecutionResult     : Abandoned
ResultId                : 0
WorkItemId              : 0
IsStale                 : False
Error                   :
Exception               :
IsNotified              : False
LastFailedProbeId       : 0
LastFailedProbeResultId : 0
ServicePriority         : 0
Identity                : Unknown\Unknown\
IsValid                 : True
ObjectState             : New



PS C:\Users\admin_micman> $HealthSetResult.HealthSetName | fl
Unknown
I suppose I have get the proper permission first.
What strikes me odd is that the information supplied with this script is insufficient.
There's more to it than just embedding it in the client and creating a service.
Do I have to edit the powershell script in order to set the Identity param?
Or use an $ARGn$ in Nagios?

Re: exchange 2013 powershell script

Posted: Wed Apr 02, 2014 10:21 am
by MichielvM
sorry, I replied with another account. My colleague decided it would be nice to have a common account so we can watch each others posts and progress..
It's me!!

Re: exchange 2013 powershell script

Posted: Wed Apr 02, 2014 4:46 pm
by sreinhardt
Just to make sure, while I test on one of my systems, are you running this on the exchange server, or is this another system that has access to it? It just seems strange that loading the snapin (presuming thats what you meant by my third command) is asking for identity, as you thought, likely meaning the server you wish to connect to.

Re: exchange 2013 powershell script

Posted: Thu Apr 03, 2014 2:15 am
by MichielvM
Yep, the commands are fired from the exchange server.
By the 3rd I mean the "add-pssnapin" command.
I reckon by the awarded stars on the exchange board, that a number of admins are already using the script.

Re: exchange 2013 powershell script

Posted: Thu Apr 03, 2014 11:00 am
by sreinhardt
In addition to the actual exchange services and roles, do you have the exchange management tools installed on this machine? Apparently the snapin only comes with that particular install, which is mostly separate from the main exchange install.

http://technet.microsoft.com/en-us/libr ... 50%29.aspx

Re: exchange 2013 powershell script

Posted: Mon Apr 07, 2014 4:36 am
by MichielvM
management tools are installed.