Page 1 of 2

Monitoring Disk Space by Size, not Percentage

Posted: Mon Jan 09, 2017 7:02 am
by neworderfac33
Good morning,
Moderators - please accept my apologies if I should have continued my quest in my original thread:
https://support.nagios.com/forum/viewto ... =7&t=41721
which had turned towards using check_nrpe to monitor available disk space by amount, rather than by percentage.
Through no fault of the excellent support provided here, I was getting nowhere, so requested that the thread be closed.
I have found a number of suggestions as to how I could address this requirement at http://serverfault.com/questions/309913 ... nt-co?rq=1
I've got as far as creating the three wrapper scripts provided there (which i can't get to work from the command prompt, let alone using them to define a NAGIOS service!), however, I don't want to go any further with THIS thread until I know that you'd be prepared to provide assistance on this externally provided solution?

Thanks
Pete

Re: Monitoring Disk Space by Size, not Percentage

Posted: Mon Jan 09, 2017 1:06 pm
by lmiltchev
Pete, did you decide not to use "check_nrpe" with NSClient++? The reason I am asking is that "check_nrpe" seems to work just fine for me.

Code: Select all

# /usr/local/nagios/libexec/check_nrpe -H x.x.x.x -t 30 -c check_drivesize -a drive=C: 'warning=free<10G' 'critical=free<5G' show-all 'perf-config=*(unit:G)' detail-syntax='{${drive_or_name} ${free} free / ${size} total}' top-syntax='${status}: ${problem_list}'
OK: {C: 55.269GB free / 107.47GB total}|'C: free'=55.26886G;10;5;0;107.46972 'C: free %'=51%;9;4;0;100
Can you run the same command from the command line on the Nagios box, and show the output? What is the version of NSClient++ that ou are currently using?

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x
Post the entire nsclient.ini file from the Windows machine. Hide sensitive info.

Re: Monitoring Disk Space by Size, not Percentage

Posted: Mon Jan 09, 2017 1:09 pm
by dwhitfield
One thing to note about NSClient in general is that if you install a new version, cruft from the old version gets left behind. Also, particularly with .3.x versus .4.x, the configs are very different.

Re: Monitoring Disk Space by Size, not Percentage

Posted: Tue Jan 10, 2017 5:26 am
by neworderfac33
Good morning - when i type the command in as shown, I get:

Code: Select all

Request command contained illegal metachars!
My NRPE version is 2.15, by the way. Do I need to have NRPE installed and running on the remote PC (which is Windows, not Linux) too?
You can see why I preferred to go with one of the solutions referenced in the link I provided, if possible - I don't want to have to amend the NSClient.ini file on 500+ servers!
Here's the nsclient.ini file from my test target machine:

Code: Select all

# If you want to fill this file with all avalible options run the following command:
#   nscp settings --generate --add-defaults --load-all
# If you want to activate a module and bring in all its options use:
#   nscp settings --activate-module <MODULE NAME> --add-defaults
# For details run: nscp settings --help


; Undocumented section
[/settings/default]

; ALLOWED HOSTS - A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.
allowed hosts = 99.99.99.99


; Undocumented section
[/modules]

; Undocumented key
Scheduler = 0

; CheckSystem - Various system related checks, such as CPU load, process state, service state memory usage and PDH counters.
CheckSystem = 1

; NSClientServer - A server that listens for incoming check_nt connection and processes incoming requests.
NSClientServer = 1

; CheckExternalScripts - Execute external scripts
CheckExternalScripts = 1

; CheckHelpers - Various helper function to extend other checks.
CheckHelpers = 1

; CheckEventLog - Check for errors and warnings in the event log.
CheckEventLog = 1

; CheckNSCP - Use this module to check the healt and status of NSClient++ it self
CheckNSCP = 1

; CheckDisk - CheckDisk can check various file and disk related things.
CheckDisk = 1

; NRPEServer - A server that listens for incoming NRPE connection and processes incoming requests.
NRPEServer = 1


; A list of templates for wrapped scripts.
[/settings/external scripts/wrappings]

; WRAPPING - An external script wrapping
ps1 = cmd /c echo scripts\\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -

; WRAPPING - An external script wrapping
bat = scripts\\%SCRIPT% %ARGS%

; WRAPPING - An external script wrapping
An alias is an internal command that has been predefined to provide a single command without arguments. Be careful so you don't create loops (ie check_loop = check_a, check_a=check_loop)

; WRAPPING - An external script wrapping
vbs = cscript.exe //T:30 //NoLogo scripts\\lib\\wrapper.vbs %SCRIPT% %ARGS%


[/settings/external scripts/alias]

; ALIAS - Query alias
alias_volumes_loose = check_drivesize

; ALIAS - Query alias
alias_volumes = check_drivesize

; ALIAS - Query alias
alias_sched_all = check_tasksched show-all "syntax=${title}: ${exit_code}" "crit=exit_code ne 0"

; ALIAS - Query alias
alias_process_stopped = check_process "process=$ARG1$" "crit=state != 'stopped'"

; ALIAS - Query alias
alias_service = check_service

; ALIAS - Query alias
alias_process_hung = check_process "filter=is_hung" "crit=count>0"

; ALIAS - Query alias
alias_process_count = check_process "process=$ARG1$" "warn=count > $ARG2$" "crit=count > $ARG3$"

; ALIAS - Query alias
alias_process = check_process "process=$ARG1$" "crit=state != 'started'"

; ALIAS - Query alias
alias_mem = check_memory

; ALIAS - Query alias
alias_file_size = check_files "path=$ARG1$" "crit=size > $ARG2$" "top-syntax=${list}" "detail-syntax=${filename] ${size}" max-dir-depth=10

; ALIAS - Query alias
alias_event_log = check_eventlog

; ALIAS - Query alias
alias_service_ex = check_service "exclude=Net Driver HPZ12" "exclude=Pml Driver HPZ12" exclude=stisvc

; ALIAS - Query alias
alias_disk = check_drivesize

; ALIAS - Query alias
alias_file_age = check_files "path=$ARG1$" "crit=written > $ARG2$" "top-syntax=${list}" "detail-syntax=${filename] ${written}" max-dir-depth=10

; ALIAS - Query alias
alias_cpu_ex = check_cpu "warn=load > $ARG1$" "crit=load > $ARG2$" time=5m time=1m time=30s

; ALIAS - Query alias
alias_cpu = check_cpu

; ALIAS - Query alias
alias_up = check_uptime

; ALIAS - Query alias
alias_disk_loose = check_drivesize

; ALIAS - Query alias
alias_sched_task = check_tasksched show-all "filter=title eq '$ARG1$'" "detail-syntax=${title} (${exit_code})" "crit=exit_code ne 0"

; ALIAS - Query alias
alias_sched_long = check_tasksched "filter=status = 'running'" "detail-syntax=${title} (${most_recent_run_time})" "crit=most_recent_run_time < -$ARG1$"


; Undocumented section
[/settings/NRPE/server]
ssl options =
verify mode = none
insecure = true
allow arguments = true
allow_nasty_meta_characters = 1
And NSClient++ is version 0.4.3.143-x64

Thanks

Pete

Re: Monitoring Disk Space by Size, not Percentage

Posted: Tue Jan 10, 2017 12:52 pm
by rkennedy
You need to add allow nasty characters=true under two sections in your config file -

Code: Select all

[/settings/NRPE/server]
allow nasty characters=true

[/settings/external scripts]
allow nasty characters=true
Then restart the nscp service on the Windows machine, and try once again

Re: Monitoring Disk Space by Size, not Percentage

Posted: Wed Jan 11, 2017 4:25 am
by neworderfac33
Good morning - I didn't have an [/settings/external scripts] section in my NSCLIENT.INI, so I added it at the bottom - here's the resulting file:

Code: Select all

# If you want to fill this file with all avalible options run the following command:
#   nscp settings --generate --add-defaults --load-all
# If you want to activate a module and bring in all its options use:
#   nscp settings --activate-module <MODULE NAME> --add-defaults
# For details run: nscp settings --help


; Undocumented section
[/settings/default]

; ALLOWED HOSTS - A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.
allowed hosts = my.nagios.core.master


; Undocumented section
[/modules]

; Undocumented key
Scheduler = 0

; CheckSystem - Various system related checks, such as CPU load, process state, service state memory usage and PDH counters.
CheckSystem = 1

; NSClientServer - A server that listens for incoming check_nt connection and processes incoming requests.
NSClientServer = 1

; CheckExternalScripts - Execute external scripts
CheckExternalScripts = 1

; CheckHelpers - Various helper function to extend other checks.
CheckHelpers = 1

; CheckEventLog - Check for errors and warnings in the event log.
CheckEventLog = 1

; CheckNSCP - Use this module to check the healt and status of NSClient++ it self
CheckNSCP = 1

; CheckDisk - CheckDisk can check various file and disk related things.
CheckDisk = 1

; NRPEServer - A server that listens for incoming NRPE connection and processes incoming requests.
NRPEServer = 1


; A list of templates for wrapped scripts.
[/settings/external scripts/wrappings]

; WRAPPING - An external script wrapping
ps1 = cmd /c echo scripts\\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -

; WRAPPING - An external script wrapping
bat = scripts\\%SCRIPT% %ARGS%

; WRAPPING - An external script wrapping
An alias is an internal command that has been predefined to provide a single command without arguments. Be careful so you don't create loops (ie check_loop = check_a, check_a=check_loop)

; WRAPPING - An external script wrapping
vbs = cscript.exe //T:30 //NoLogo scripts\\lib\\wrapper.vbs %SCRIPT% %ARGS%


[/settings/external scripts/alias]

; ALIAS - Query alias
alias_volumes_loose = check_drivesize

; ALIAS - Query alias
alias_volumes = check_drivesize

; ALIAS - Query alias
alias_sched_all = check_tasksched show-all "syntax=${title}: ${exit_code}" "crit=exit_code ne 0"

; ALIAS - Query alias
alias_process_stopped = check_process "process=$ARG1$" "crit=state != 'stopped'"

; ALIAS - Query alias
alias_service = check_service

; ALIAS - Query alias
alias_process_hung = check_process "filter=is_hung" "crit=count>0"

; ALIAS - Query alias
alias_process_count = check_process "process=$ARG1$" "warn=count > $ARG2$" "crit=count > $ARG3$"

; ALIAS - Query alias
alias_process = check_process "process=$ARG1$" "crit=state != 'started'"

; ALIAS - Query alias
alias_mem = check_memory

; ALIAS - Query alias
alias_file_size = check_files "path=$ARG1$" "crit=size > $ARG2$" "top-syntax=${list}" "detail-syntax=${filename] ${size}" max-dir-depth=10

; ALIAS - Query alias
alias_event_log = check_eventlog

; ALIAS - Query alias
alias_service_ex = check_service "exclude=Net Driver HPZ12" "exclude=Pml Driver HPZ12" exclude=stisvc

; ALIAS - Query alias
alias_disk = check_drivesize

; ALIAS - Query alias
alias_file_age = check_files "path=$ARG1$" "crit=written > $ARG2$" "top-syntax=${list}" "detail-syntax=${filename] ${written}" max-dir-depth=10

; ALIAS - Query alias
alias_cpu_ex = check_cpu "warn=load > $ARG1$" "crit=load > $ARG2$" time=5m time=1m time=30s

; ALIAS - Query alias
alias_cpu = check_cpu

; ALIAS - Query alias
alias_up = check_uptime

; ALIAS - Query alias
alias_disk_loose = check_drivesize

; ALIAS - Query alias
alias_sched_task = check_tasksched show-all "filter=title eq '$ARG1$'" "detail-syntax=${title} (${exit_code})" "crit=exit_code ne 0"

; ALIAS - Query alias
alias_sched_long = check_tasksched "filter=status = 'running'" "detail-syntax=${title} (${most_recent_run_time})" "crit=most_recent_run_time < -$ARG1$"

[/settings/external scripts]
allow nasty characters=true

; Undocumented section
[/settings/NRPE/server]
ssl options =
verify mode = none
insecure = true
allow arguments = true
allow nasty characters = true
but

Code: Select all

[root@MYNAGIOSMASTER libexec]# /usr/local/nagios/libexec/check_nrpe -H 99.99.99.99 -t 30 -c check_drivesize -a drive=C: 'warning=free<10G' 'critical=free<5G' show-all 'perf-config=*(unit:G)' detail-syntax='{${drive_or_name} ${free} free / ${size} total}' top-syntax='${status}: ${problem_list}'
still returns:

Code: Select all

Exception processing request: Request command contained illegal metachars!
after I've restarted the NSCLIENT++ service. Is this a positioning problem in terms of where I've placed:

Code: Select all

[/settings/external scripts]
allow nasty characters=true

; Undocumented section
[/settings/NRPE/server]
ssl options =
verify mode = none
insecure = true
allow arguments = true
allow nasty characters = true
i.e. right at the end of the file?

Finally, I remembered that a previously suggested solution was to use "allow nasty_META_characters", including underscores so I tried this, but it still doesn't work.

As always, thanks for your help

Pete

Re: Monitoring Disk Space by Size, not Percentage

Posted: Wed Jan 11, 2017 6:15 am
by neworderfac33
...oh, and NSCLIENT.txt on the target server reported:

Code: Select all

2017-01-11 09:35:41: error:D:\source\nscp\modules\NRPEServer\NRPEServer.cpp:185: Request arguments contained illegal metachars!
Pete

Re: Monitoring Disk Space by Size, not Percentage

Posted: Wed Jan 11, 2017 1:54 pm
by dwhitfield
It looks like you can do this with check_wmi_plus.pl -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$ -m checkdrivesize -a 'C|D' -w _FreeGB=5G -c_FreeGB_4G

Obviously, you'll need to change things for your drives and the numbers you want to check.

It's written for XI, but you'll find more check_wmi_plus info at: https://assets.nagios.com/downloads/nag ... pgrade.pdf

Re: Monitoring Disk Space by Size, not Percentage

Posted: Wed Jan 11, 2017 2:06 pm
by mcapra
Using your exact NSClient++ configuration and exact NSClient++ version, I didn't have any issues:

Code: Select all

[root@xi-stable ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.67.99 -t 30 -c check_drivesize -a drive=C: 'warning=free<10G' 'critical=free<5G' show-all 'perf-config=*(unit:G)' detail-syntax='{${drive_or_name} ${free} free / ${size} total}' top-syntax='${status}: ${problem_list}'
OK: {C: 29.412GB free / 50.232GB total}|'C: free'=29.41158G;10;5;0;50.23241 'C: free %'=58%;19;9;0;100
[root@xi-stable ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.67.99
I (0.4.3.143 2015-04-29) seem to be doing fine...
Are you certain you restarted the nscp service on the remote machine after altering the configuration?

Re: Monitoring Disk Space by Size, not Percentage

Posted: Thu Jan 12, 2017 6:07 am
by neworderfac33
No, definitely restarted the service on the remote box.
I'm using Nagios 4.0.8 - could THAT be the problem?
Cheers
Pete