Page 1 of 1

Powershell script with first argument containing a space

Posted: Tue Oct 24, 2023 7:59 am
by riahc3
I have the following check:

/usr/local/nagios/libexec/check_ncpa.py -H thehost -t '' -P 5693 -M 'plugins/CheckClusterResourceGroupStatus.ps1' -a "'Cluster Group'"

But I get the following error

UNKNOWN - Resource group \'Cluster/Group\' not found

From what you can tell, the issue is that the argument contains a space and there is only one argument (Ive seen examples where there is two arguments and it works)

How can I fix this? I doubt its the script per say because it passes other non space arguments correctly.

Re: Powershell script with first argument containing a space

Posted: Tue Oct 24, 2023 8:26 am
by riahc3
This makes no sense

Image

The fact that Nagios and NCPA does this in 2023 is absurd

Re: Powershell script with first argument containing a space

Posted: Tue Oct 24, 2023 5:09 pm
by bbahn
The first example (black CLI) indicates that the string is properly passed to the script, but the script could not find the resource group. This means that either the resource group doesn't exist or the script can't find it for whatever reason. This indicates that it IS working properly..

The second example (light CLI) on the other hand lends towards the issue being as you've described.

This discrepancy makes me wonder if you could explain the difference in environment that led to this?

Re: Powershell script with first argument containing a space

Posted: Wed Oct 25, 2023 2:20 am
by riahc3
bbahn wrote: Tue Oct 24, 2023 5:09 pm The second example (light CLI) on the other hand lends towards the issue being as you've described.

This discrepancy makes me wonder if you could explain the difference in environment that led to this?
Obviously Im referring to the second example.

There is no difference in the environment. As you can see, both are exactly the same and Ive also tested this against the standalone.

Ive also tested it with the parameter hard coded and it works.

Re: Powershell script with first argument containing a space

Posted: Tue Jun 11, 2024 9:23 am
by wojeye
riahc3 wrote: Tue Oct 24, 2023 7:59 am I have the following check:

/usr/local/nagios/libexec/check_ncpa.py -H thehost -t '' -P 5693 -M 'plugins/CheckClusterResourceGroupStatus.ps1' -a "'Cluster Group'"

But I get the following error

UNKNOWN - Resource group \'Cluster/Group\' not found

From what you can tell, the issue is that the argument contains a space and there is only one argument (Ive seen examples where there is two arguments and it works)

How can I fix this? I doubt its the script per say because it passes other non space arguments correctly.
It seems like the issue is indeed related to how the script handles arguments containing spaces. Since the argument you're passing contains a space ('Cluster Group'), it might not be parsed correctly by the script.

One approach to fix this is to encapsulate the argument containing spaces within double quotes. However, since you're already using single quotes around the entire argument string, you'll need to ensure that the single quotes around the argument are escaped properly. Here's how you can modify your command:

Code: Select all

/usr/local/nagios/libexec/check_ncpa.py -H thehost -t '' -P 5693 -M 'plugins/CheckClusterResourceGroupStatus.ps1' -a "\"'Cluster Group'\""
By adding the escaped double quotes (\") around the argument, you ensure that the entire argument ('Cluster Group') is treated as a single entity by the script.

Try running the command with this modification and see if it resolves the issue.

Re: Powershell script with first argument containing a space

Posted: Thu Jun 20, 2024 2:41 am
by Vennpauly
riahc3 wrote: Tue Oct 24, 2023 7:59 am I have the following check:

/usr/local/nagios/libexec/check_ncpa.py -H thehost -t '' -P 5693 -M 'plugins/CheckClusterResourceGroupStatus.ps1' -a "'Cluster Group'"

But I get the following error

UNKNOWN - Resource group \'Cluster/Group\' not found

From what you can tell, the issue is that the argument contains a space and there is only one argument (Ive seen examples where there is two arguments and it works)

How can I fix this? I doubt its the script per say because it passes other non space arguments correctly.
it seems that the issue is with the way the argument is being passed to the script. When the argument contains a space, it needs to be properly quoted or escaped to ensure that the script recognizes it as a single argument.