Page 1 of 1
passing a parameter to custom plugin with white spaces
Posted: Wed Feb 24, 2021 10:43 pm
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,
Re: passing a parameter to custom plugin with white spaces
Posted: Thu Feb 25, 2021 11:32 am
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
Re: passing a parameter to custom plugin with white spaces
Posted: Thu Feb 25, 2021 1:26 pm
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.
Re: passing a parameter to custom plugin with white spaces
Posted: Fri Feb 26, 2021 6:01 pm
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
Re: passing a parameter to custom plugin with white spaces
Posted: Sun Feb 28, 2021 6:56 pm
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!
Re: passing a parameter to custom plugin with white spaces
Posted: Mon Mar 01, 2021 7:02 pm
by ssax
You should also be able to use:
Re: passing a parameter to custom plugin with white spaces
Posted: Tue Mar 02, 2021 12:52 pm
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!