NSCP Settings Escape Character

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.
TechnicallyTrue
Posts: 25
Joined: Mon May 13, 2019 11:57 am

NSCP Settings Escape Character

Post by TechnicallyTrue »

Hello,
I've been working on a script to silently install NSClient++ on target systems. I'm trying to programmatically add scheduled checks that are submitted via NSCA, which is working so far, except for one. I can't seem to properly configure check_drivesize. This is what I want the key to read:

Code: Select all

Drive Space C: = check_drivesize "warn=free<10G and free<10%" "crit=free<5G and free<5%" drive=c: show-all
This seems to have the desired behaviour of submitting a warning if there are fewer than 10 GB free on the disk AND there is less than 10% of the space free. However, for the command to add this check, I have the following:

Code: Select all

.\nscp settings --path "/settings/scheduler/schedules" --key "Drive Space C:" --set "check_drivesize "warn=free<10G and free<10%" "crit=free<5G and free<5%" drive=c: show-all"
Obviously, the issue here is that the " characters within the string aren't escaped, so I just end up with

Code: Select all

Drive Space C: = check_drivesize 
Is there a way to escape the quotation marks inside the string?
I realize that this question may be better suited to the NSClient++ forums, but that website is currently down, so I figured I'd post here on the off-chance that someone can help me.
Thank you very much.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NSCP Settings Escape Character

Post by scottwilkerson »

You should be able to use single quotes inside the double, like so

Code: Select all

.\nscp settings --path "/settings/scheduler/schedules" --key "Drive Space C:" --set "check_drivesize 'warn=free<10G and free<10%' 'crit=free<5G and free<5%' drive=c: show-all"
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
TechnicallyTrue
Posts: 25
Joined: Mon May 13, 2019 11:57 am

Re: NSCP Settings Escape Character

Post by TechnicallyTrue »

Using single quotes instead makes the check fail to run. The message it gives is

Code: Select all

Invalid command line: unrecognised option ''warn=free<10G' 
Perhaps the ' character modifies the command somehow?
Thanks again.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NSCP Settings Escape Character

Post by scottwilkerson »

That's weird, I wonder why you ended up with 2 single quotes before warn, I didn't in my test

Code: Select all

''warn=free<10G' 
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
TechnicallyTrue
Posts: 25
Joined: Mon May 13, 2019 11:57 am

Re: NSCP Settings Escape Character

Post by TechnicallyTrue »

Sorry, I should clarify: I didn't end up with 2 single quotes. This is what the resulting line in the settings looks like:

Code: Select all

Drive Space C: = check_drivesize 'warn=free<10G and free<10%' 'crit=free<5G and free<5%' drive=c: show-all
The message that says ''warn=free<10G' is just the error I get. I think the first and last single quotes are the error message, and the second single quote in front of "warn" is the actual character from the code. What it's basically saying is
Invalid command line: unrecognised option 'warn=free<10G
if that makes sense. So I suspect the issue is with that single quote in front of "warn." It must be modifying the command somehow.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NSCP Settings Escape Character

Post by scottwilkerson »

I think the following will work

Code: Select all

.\nscp settings --path "/settings/scheduler/schedules" --key "Drive Space C:" --set "check_drivesize ""warn=free<10G and free<10%"" ""crit=free<5G and free<5%"" drive=c: show-all"
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
TechnicallyTrue
Posts: 25
Joined: Mon May 13, 2019 11:57 am

Re: NSCP Settings Escape Character

Post by TechnicallyTrue »

Well, that's closer... It sets the line in the config file to

Code: Select all

Drive Space C: = check_drivesize warn=free<10G
Which is not correct (it's missing most of the parameters), but it will at least run.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NSCP Settings Escape Character

Post by scottwilkerson »

What version of NSClient++ are you running? because that command set mine to

Code: Select all

Drive Space C: = check_drivesize "warn=free<10G and free<10%" "crit=free<5G and free<5%" drive=c: show-all
Running this

Code: Select all

.\nscp settings --path "/settings/scheduler/schedules" --key "Drive Space C:" --set "check_drivesize ""warn=free<10G and free<10%"" ""crit=free<5G and free<5%"" drive=c: show-all"
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
TechnicallyTrue
Posts: 25
Joined: Mon May 13, 2019 11:57 am

Re: NSCP Settings Escape Character

Post by TechnicallyTrue »

Version 0.5.2.35.
If it makes a difference, the script I'm writing is a powershell script running on a Windows 2012 server.
Thanks again!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NSCP Settings Escape Character

Post by scottwilkerson »

Did you just run the following from the command line?

Code: Select all

nscp settings --path "/settings/scheduler/schedules" --key "Drive Space C:" --set "check_drivesize ""warn=free<10G and free<10%"" ""crit=free<5G and free<5%"" drive=c: show-all"
We have tested it on that version and it was added as expected.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked