Question about passing parameters

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Question about passing parameters

Post 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
Nagios XI 5.8.1
https://outsideit.net
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Question about passing parameters

Post 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\"'"
Former Nagios employee
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Question about passing parameters

Post by WillemDH »

Passing arguments between scripts is no issue anymore. Please close this thread.
Nagios XI 5.8.1
https://outsideit.net
Locked