check_nrpe put $ at end of check string

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.
Locked
clarkseth
Posts: 2
Joined: Wed Jul 04, 2012 7:28 am

check_nrpe put $ at end of check string

Post 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
Last edited by clarkseth on Wed Feb 12, 2014 6:25 pm, edited 1 time in total.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: check_nrpe put $ at end of check string

Post 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?
clarkseth
Posts: 2
Joined: Wed Jul 04, 2012 7:28 am

Re: check_nrpe put $ at end of check string

Post 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
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: check_nrpe put $ at end of check string

Post 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"
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked