Page 1 of 1

check_nrpe put $ at end of check string

Posted: Wed Feb 12, 2014 11:44 am
by clarkseth
Hi to all!

i've a problem with my powershell nagios script, mounted on a MS Windows Server 2008 64bit, with a NRPE_NT daemon.

I've declared the command like this:

Code: Select all

command[check_files]=cmd /c echo C:\nrpe\libexec\check_file.ps1 $ARG1$; exit($lastexitcode) | powershell.exe -command - 
I've set ExecutionPolicy as unrestricted

I've restart NRPE_NT Services and declared command on console, like this:

Code: Select all

$USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -c check_files -a $ARG1$
Now, why if i run it locally, it works good:

Code: Select all

C:\>cmd /c echo C:\nrpe\libexec\_file.ps1 C:\nrpe; exit($lastexitcode)| powershell.exe -command -
[b]No file/s present with this string[/b]
But if i run it by check_nrpe i receive this output:

'-' was specified with the -Command parameter: no other arguments to -Command are permitted.

In Debug mode, on NRPE.log i can see this:

Code: Select all

Running command: cmd /c echo C:\nrpe\libexec\check_file.ps1 C:\nrpe; exit($lastexitcode) | powershell.exe -command - [b]$[/b]
Command completed with return code 0
Why in this way, check_nrpe add a dollar character ($) at end string, derailing the entire control ?

This is the powershell script:

Code: Select all

#Nagios Status
$returnStateOK = 0
$returnStateWarning = 1
$returnStateCritical = 2
$returnStateUnknown = 3

if ($args.count -lt 1) {
						echo "Miss Argument"
						exit $returnStateUnknown
					}
elseif ($args.count -eq 1) {
							$test = Test-Path $args
							if ($test -eq "True") {
												$result = ls $args -Filter *.err|Measure-Object -Line | select -expand lines
												if ($result -ne 0) {
																	echo "$result file/s presents with *.err ext"
																	exit $returnStateCritical
																	}
														else {
																echo "No file/s present with this string"
																exit $returnStateOK
															}
											}
							else { 
								echo "Path not found"
								exit $returnStateUnknown
								}
								        }
else {
		echo "Write only 1 argument"
		exit $returnStateUnknown
	}
Thanks in advance

Re: check_nrpe put $ at end of check string

Posted: Wed Feb 12, 2014 12:19 pm
by slansing
Just a heads up that NRPE_NT is no longer supported and has been depreciated for over 3 years, NCPA or NSClient are now used in it's place. I'm curious as to why you are seeing output in tags. Can you share the check_files.pl plugin you are using?

Re: check_nrpe put $ at end of check string

Posted: Fri Feb 14, 2014 3:22 am
by clarkseth
slansing wrote:Just a heads up that NRPE_NT is no longer supported and has been depreciated for over 3 years, NCPA or NSClient are now used in it's place. I'm curious as to why you are seeing output in tags. Can you share the check_files.pl plugin you are using?
Hi Slansing,

i've share powershell script yesterday, you can see it, in append of principal thread

thanks

Re: check_nrpe put $ at end of check string

Posted: Fri Feb 14, 2014 12:45 pm
by lmiltchev
You can use check_nrpe with NSClient++. Copy your script to NSClient++ scripts directory. Set your command in the NSC.ini (nsclient.ini) as such:

Code: Select all

check_files=cmd /c echo scripts\check_file.ps1 $ARG1$; exit($lastexitcode) | powershell.exe -command -
Restart NSClient++ service, and test it from the CLI on the Nagios server:

Code: Select all

./check_nrpe -H <client ip> -c check_files -a "your arg goes here"