Page 1 of 2
NSCP Settings Escape Character
Posted: Thu Nov 28, 2019 1:16 pm
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
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.
Re: NSCP Settings Escape Character
Posted: Mon Dec 02, 2019 9:03 am
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"
Re: NSCP Settings Escape Character
Posted: Tue Dec 03, 2019 11:17 am
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.
Re: NSCP Settings Escape Character
Posted: Tue Dec 03, 2019 11:24 am
by scottwilkerson
That's weird, I wonder why you ended up with 2 single quotes before
warn, I didn't in my test
Re: NSCP Settings Escape Character
Posted: Tue Dec 03, 2019 11:31 am
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.
Re: NSCP Settings Escape Character
Posted: Tue Dec 03, 2019 12:23 pm
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"
Re: NSCP Settings Escape Character
Posted: Tue Dec 03, 2019 1:19 pm
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.
Re: NSCP Settings Escape Character
Posted: Tue Dec 03, 2019 1:26 pm
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"
Re: NSCP Settings Escape Character
Posted: Tue Dec 03, 2019 3:05 pm
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!
Re: NSCP Settings Escape Character
Posted: Tue Dec 03, 2019 3:38 pm
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.