Powershell script with first argument containing a space

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Post Reply
riahc3
Posts: 59
Joined: Thu Apr 05, 2018 9:36 am

Powershell script with first argument containing a space

Post 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.
riahc3
Posts: 59
Joined: Thu Apr 05, 2018 9:36 am

Re: Powershell script with first argument containing a space

Post by riahc3 »

This makes no sense

Image

The fact that Nagios and NCPA does this in 2023 is absurd
bbahn
Posts: 147
Joined: Thu Jan 12, 2023 5:42 pm

Re: Powershell script with first argument containing a space

Post 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?
April: Actively advancing awesome answers with ardent alliteration, aptly addressing all ambiguities. Amplify your acumen and avail our amicable assistance. Eagerly awaiting your astute assessments of our advice.
riahc3
Posts: 59
Joined: Thu Apr 05, 2018 9:36 am

Re: Powershell script with first argument containing a space

Post 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.
rosydam
Posts: 5
Joined: Sun Aug 27, 2023 10:12 pm
Contact:

Re: Powershell script with first argument containing a space

Post by rosydam »

riahc3 wrote: Wed Oct 25, 2023 2:20 am
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.
Geometry Dash
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.
me too
wojeye
Posts: 1
Joined: Tue Jun 11, 2024 9:19 am
Contact:

Re: Powershell script with first argument containing a space

Post 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.
Post Reply