passing a parameter to custom plugin with white spaces

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
beyondcom
Posts: 6
Joined: Wed Jun 05, 2013 12:05 pm

passing a parameter to custom plugin with white spaces

Post by beyondcom »

How can I pass a value or parameter to a powershell script with white spaces using ncpa plugin?

The command i am using: $USER1$/check_ncpa.py -H $HOSTADDRESS$ $ARG1$
$ARG1$ = -t 'mytoken' -P 5693 -M 'plugins/CheckScheduledTask.ps1' -a "Make Bot File"

It can only recognize Make and ignores the rest.

I have tried single quote -a "'Make Bot File'" which doesn't work. The output is 'Make Bot File' (it includes single quotes along with Make Bot File)

I have also tried -q "args=u 'Make Bot File'" and this doesn't work as well.

My only work around is to rename the scheduled task as one word.

Thanks,
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: passing a parameter to custom plugin with white spaces

Post by benjaminsmith »

Hi,

What version of NCPA do you have deployed on this system. I'll check the changelog for a possible bug, but it's working on my test system. Let's try running a few more combinations from the command line, and let us know the results.

Code: Select all

 $USER1$/check_ncpa.py -H $HOSTADDRESS$ $ARG1$
$ARG1$ = -t 'mytoken' -P 5693 -M 'plugins/CheckScheduledTask.ps1' -a 'Make Bot File'

 $USER1$/check_ncpa.py -H $HOSTADDRESS$ $ARG1$
$ARG1$ = -t 'mytoken' -P 5693 -M 'plugins/CheckScheduledTask.ps1' -q 'args=u Make Bot File'
--Benjamin

References
https://www.nagios.org/ncpa/help.php#api-modules
https://support.nagios.com/kb/article/n ... a-722.html
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
beyondcom
Posts: 6
Joined: Wed Jun 05, 2013 12:05 pm

Re: passing a parameter to custom plugin with white spaces

Post by beyondcom »

hi Benjamin!

I tried both options mentioned in your previous reply.

We have ncpa agent installed version 2.22 with NagiosXI version 5.8.1

First method: -t 'mytoken' -P 5693 -M 'plugins/CheckScheduledTask.ps1' -a 'Make Bot File'
Result: Make Scheduled Task Not Found

Second method: -t 'mytoken' -P 5693 -M 'plugins/CheckScheduledTask.ps1' -q 'args=u Make Bot File'
Result: u Scheduled Task Not Found

I've tried both of these methods before posting a thread on this support forum.

I've also tried https://localhost:5693 to see what I did wrong but I didn't get very far with that neither.
User avatar
jdunitz
Posts: 235
Joined: Wed Feb 05, 2020 2:50 pm

Re: passing a parameter to custom plugin with white spaces

Post by jdunitz »

I was able to make this work by doublequoting an escaped doublequote.

My script isn't powershell, but I'm not sure it makes a difference for how parameters are passed.

[root@jpd-cent-nrpe-one plugins]# more threeargs.sh
#!/bin/sh
echo "OK | You said $1 and also $2 and $3 "



So, as you're doing it, it passes as separate arguments:
[root@jpd-nagiosxi-one libexec]# ./check_ncpa.py -H nrpe-one -t 'mytoken' -P 5693 -M 'plugins/threeargs.sh' -a "Make Bot File"
OK | You said Make and also Bot and File


But if you double-quote an escaped doublequote, it seems to work:
[root@jpd-nagiosxi-one libexec]# ./check_ncpa.py -H nrpe-one -t 'mytoken' -P 5693 -M 'plugins/threeargs.sh' -a " \"Make Bot File\" "

OK | You said Make Bot File and also and
[root@jpd-nagiosxi-one libexec]#


I also modified my little script to write to a log, and this is what we see in the log on the other end:

[root@jpd-cent-nrpe-one plugins]# cat /tmp/threeargs.log
OK | You said Make Bot File and also and
[root@jpd-cent-nrpe-one plugins]#


So, I think that's it! Let us know if that works for you or not.

--Jeffrey
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
beyondcom
Posts: 6
Joined: Wed Jun 05, 2013 12:05 pm

Re: passing a parameter to custom plugin with white spaces

Post by beyondcom »

Hi Jefferey!

After trying your suggestion:
$ARG1 = -t 'mytoken' -P 5693 -M 'plugins/CheckScheduledTask.ps1' -a "\"Make Bot File\""
I get "Make Bot File" Scheduled Task Not Found.

It is not exactly where I want but I do have a work around for now. I place an if inside of my script to look for double quotes and remove them. It works for now.

Thanks for getting me this far Jefferey and Benjamin!
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: passing a parameter to custom plugin with white spaces

Post by ssax »

You should also be able to use:

Code: Select all

-a "'Make Bot File'"
beyondcom
Posts: 6
Joined: Wed Jun 05, 2013 12:05 pm

Re: passing a parameter to custom plugin with white spaces

Post by beyondcom »

-a "'Make Bot File'" will result as 'Make Bot File' which my script will error. I am happy with the way it is for now. Please close this thread when you have a moment.

Thanks!
Locked