check_nrpe unexpected result with powershell script

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: check_nrpe unexpected result with powershell script

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
sc00354007
Posts: 8
Joined: Wed Dec 03, 2014 11:21 pm

Re: check_nrpe unexpected result with powershell script

Post 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 ?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: check_nrpe unexpected result with powershell script

Post 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
Former Nagios Employee
sc00354007
Posts: 8
Joined: Wed Dec 03, 2014 11:21 pm

Re: check_nrpe unexpected result with powershell script

Post 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 ?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: check_nrpe unexpected result with powershell script

Post 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
Former Nagios Employee
Locked