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,
passing a parameter to custom plugin with white spaces
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: passing a parameter to custom plugin with white spaces
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.
--Benjamin
References
https://www.nagios.org/ncpa/help.php#api-modules
https://support.nagios.com/kb/article/n ... a-722.html
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'
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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: passing a parameter to custom plugin with white spaces
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.
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
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
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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: passing a parameter to custom plugin with white spaces
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!
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
You should also be able to use:
Code: Select all
-a "'Make Bot File'"Re: passing a parameter to custom plugin with white spaces
-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!
Thanks!