Page 1 of 1

Question about passing parameters

Posted: Sat Mar 22, 2014 6:53 am
by WillemDH
Hello,

I'm trying to extend my check_ms_win_tasks.ps1 script. At this point, I'm passing three parameters and they are all mandatory. As I do not want them to be mandatory, as it can happen there are no excluding folder or task patterns, I removed the [Parameter(Mandatory=$true)] form the parameters.

Now normally I should be able to call the script like this in Powershell: .\check_ms_win_tasks.ps1 -computername "localhost" -ExclFolders "Microsoft" -ExclTasks "Google", which gives the expected result.

But when I try this from cli, I get:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H servername -p 5666 -t 60 -c check_ms_win_tasks -a '-Computername "localhost"' '-ExclFolders Microsoft,OG_WZD,EHRM,F5,Backup_Maintenance'  '-ExclTasks "Jeff","Copy Fimacs"'
/usr/local/nagios/libexec/check_nrpe: invalid option -- 'E'
/usr/local/nagios/libexec/check_nrpe: invalid option -- 'x'
/usr/local/nagios/libexec/check_nrpe: invalid option -- 'E'
/usr/local/nagios/libexec/check_nrpe: invalid option -- 'x'

NRPE Plugin for Nagios
Copyright (c) 1999-2008 Ethan Galstad ([email protected])
Version: 2.12
Last Modified: 03-10-2008
License: GPL v2 with exemptions (-l for more info)
SSL/TLS Available: Anonymous DH Mode, OpenSSL 0.9.6 or higher required

Usage: check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]

Options:
 -n         = Do no use SSL
 -u         = Make socket timeouts return an UNKNOWN state instead of CRITICAL
 <host>     = The address of the host running the NRPE daemon
 [port]     = The port on which the daemon is running (default=5666)
 [timeout]  = Number of seconds before connection times out (default=10)
 [command]  = The name of the command that the remote daemon should run
 [arglist]  = Optional arguments that should be passed to the command.  Multiple
              arguments should be separated by a space.  If provided, this must be
              the last option supplied on the command line

So apparently nrpe thinks the parameters I'm passing are for nrpe, not for my Powershell script. Any advice how to handle something like this. When I make the parameters mandatory and provide them, the script works fine.

The command made in nsclient.ini looks like this:

Code: Select all

check_ms_win_tasks=cmd /c echo scripts\check_ms_win_tasks.ps1 $ARG1$ $ARG2$ $ARG3$; exit $LastExitCode | powershell.exe -command -
So is there any way to add -computername, -exclfolders and -excltasks as optional parameters with a Powershell script called by nrpe?

The Nagios command look like this now:

Code: Select all

$USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -t 60 -c check_ms_win_tasks -a $ARG1$ $ARG2$ $ARG3$


Any advice on this?

Willem

Re: Question about passing parameters

Posted: Mon Mar 24, 2014 9:59 am
by tmcdonald
You might need to do some fancy footwork with the quoting, wrap everything after -a in quotes and escape it out:

Code: Select all

-a "'-Computername \"localhost\"' '-ExclFolders Microsoft,OG_WZD,EHRM,F5,Backup_Maintenance'  '-ExclTasks \"Jeff\",\"Copy Fimacs\"'"

Re: Question about passing parameters

Posted: Fri Jun 05, 2015 4:55 pm
by WillemDH
Passing arguments between scripts is no issue anymore. Please close this thread.