Page 2 of 2

Re: check_nrpe unexpected result with powershell script

Posted: Thu Jun 02, 2016 4:36 pm
by Box293
It might be that the NSClient++ service needs to be running as an Exchange Admin to be verified to query the required information. By default it runs under the system account.

Re: check_nrpe unexpected result with powershell script

Posted: Fri Jun 03, 2016 7:20 am
by sc00354007
The problem is that the Powershell script runs on a windows 2008 probe which in turn will connect to the exchange 2010 environment and give the results back to Nagios.

So, the user "DOMAIN\ABC" on the windows probe is also setup on the exchange as well.

Is there any other way to achieve the desired output ?

Re: check_nrpe unexpected result with powershell script

Posted: Fri Jun 03, 2016 2:08 pm
by rkennedy
From the sounds of it, you need to have your Powershell script escalate to the right permissions.

Take a look at this article which should help I believe -
http://stackoverflow.com/questions/2524 ... ws-command

Re: check_nrpe unexpected result with powershell script

Posted: Wed Jun 08, 2016 5:21 am
by sc00354007
Thanks a lot

Below is the updated code :

Code: Select all


#check_scripts.ps1

$returnStateOK =0
$returnStateWarning =1
$returnStateCritical =2
$returnStateUnknown =3

$servers = "ABCWPMBX1-ABC","GHIWPMBX3-DEF","DEFWPMBX2-ABC","KLMWPMBX4-DEF","PQRWVJAR2-DEF"


$username = "DOMAIN/ABC"
$password = "abc@123"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr

$flag = 0
$c_servers = @()
foreach ( $s in $servers )
{


$c = (Invoke-Command -ComputerName  $s -Credential $cred -ScriptBlock { Get-Counter -ListSet MSExchangeIS |select-object -ExpandProperty CounterSetName}  -ea silentlycontinue)


	if($c -Match "MSExchangeIS" )  {
		$flag = 1
		#write-host $c
      $c_servers += $s
	}

}

if ( $flag -eq 1 ) {
$errorString = "MSExchangeIS counter is enabled for " 
      Write-Host "CRITICAL:"$errorString"" "$c_servers"
	 exit $returnStateCritical 
}
else {
		$errorString = "MSExchangeIS counter is disabled"
      Write-Host "OK:"$errorString""
	  exit $returnStateOK
	 }
	 



Is there a way to add performance data to this script ?

Re: check_nrpe unexpected result with powershell script

Posted: Wed Jun 08, 2016 9:33 am
by rkennedy
Yes, the way you can add performance data is by appending a |variable= part to where you echo the result, for example -

Code: Select all

[root@localhost libexec]# ./check_http -H google.com
HTTP OK: HTTP/1.1 301 Moved Permanently - 559 bytes in 0.066 second response time |time=0.065955s;;;0.000000 size=559B;;;0
The performance data on this part is |time=0.065955s;;;0.000000 size=559B;;;0