NagiosEnterprises / ncpa

Nagios Cross-Platform Agent
Other
176 stars 95 forks source link

Documentation issue: NCPA Active plugin checks with arguments #1078

Open pittagurneyi opened 6 months ago

pittagurneyi commented 6 months ago

Contrary to what is described here https://www.nagios.org/ncpa/help/3.0/active.html the order of "" and '' has to be reversed, i.e.

-q "args=-u 'one argument',args=-p 'another argument'"
# to
-q 'args=-u "one argument",args=-p "another argument"'

The inner arguments have to be enclosed in "", otherwise the '' would remain as part of the argument and not be removed. At least that is what happened, when I tried to pass an inner argument 70,80, which the program told me was invalid - I have validation checks for that argument - as the value it got was '70,80' if I gave it to NCPA via Nagios in the way that is described in the documentation.

ne-bbahn commented 6 months ago

How are you validating your arguments? I'm having trouble replicating this behavior.

Also are you using NCPA 2 or 3?

pittagurneyi commented 6 months ago

Hi, thank you for looking into it.

I'm using NCPA 3.0.1.

This is a bash script and the option argument is parsed via getopts.

The option is used for setting two values, one for the warning and the other error condition: -f 80,90.

So I'm testing the value given, here 80,90 with:

re='^[0-9]+,[0-9]+$'
[[ $OPTARG =~ $re ]] || die "Error invalid value for -f given: $OPTARG"

And the error message shows me the value given. If I enclose 80,90 in the command arguments in Nagios with '', so -f '80,90', then the error message shows me -f given: '80,90'.

The only combination I've yet been able to find in which this works as is intended, is by using -f "80,90".

EDIT: This works:

-M 'plugins/check-zpool' -q 'args=-p zroot,args=-s "60,90",args=-e,args=-f "80,90"'
Matty-uk commented 6 months ago

Can you try:

re='^['\''"]?[0-9]+,[0-9]+['\''"]?$' [[ $OPTARG =~ $re ]] || die "Error invalid value for -f given: $OPTARG"

Regards

Matt Dennison From: pittagurneyi @.> Sent: Friday, December 15, 2023 1:42 PM To: NagiosEnterprises/ncpa @.> Cc: Subscribed @.***> Subject: Re: [NagiosEnterprises/ncpa] Documentation issue: NCPA Active plugin checks with arguments (Issue #1078)

Hi, thank you for looking into it.

I'm using NCPA 3.0.1.

This is a bash script and the option argument is parsed via getopts.

The option is used for setting two values, one for the warning and the other error condition: -f 80,90.

So I'm testing the value given, here 80,90 with:

re='^[0-9]+,[0-9]+$'

[[ $OPTARG =~ $re ]] || die "Error invalid value for -f given: $OPTARG"

And the error message shows me the value given. If I enclose 80,90 in the command arguments in Nagios with '', so -f '80,90', then the error message shows me -f given: '80,90'.

The only combination I've yet been able to find in which this works as is intended, is by using -f "80,90".

— Reply to this email directly, view it on GitHubhttps://github.com/NagiosEnterprises/ncpa/issues/1078#issuecomment-1857901249, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARMKHKJGUFS5JBO5UWHX7DLYJRHSTAVCNFSM6AAAAABAVOOVP6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJXHEYDCMRUHE. You are receiving this because you are subscribed to this thread.Message ID: @.**@.>>

pittagurneyi commented 6 months ago

I'm most certainly not going to create workarounds in my script in order to fix buggy NCPA option parsing.

This whole thing here you proposed

re='^['\''"]?[0-9]+,[0-9]+['\''"]?$'

doesn't help me when I want to correctly parse the values in the following line:

IFS=',' read -r val1 val2 <<<"$OPTARG"

Then I'd have to replace "$OPTARG" by $OPTARG, allowing bash to "eat" the '', which is hacky as well. No, I'm not going to create on-purpose programming errors to work around this problem.