Check_drivesize multiple warn/crit thresholds


#1

I want to set different warn/crit thresholds for different drives.

I was hoping to use “warning= …” as full-featured filter creating complex query like that:

warning = (( used > 90% ) and ( drive != F: )) or ( ( used > 99% ) and ( drive = F: ))

But can’t identify correct syntax.

Docs says that ‘drive’ is correct key in warning filter, but i can’t find any example of using it such way. Is it possible at all?

Note: i want to limit server/agent side with single check_disk command and service definition. Multiple service/command definition is not an option.

Let’s say - i want to Check disks across infrastructure with single command ( which will do disks auto-discovery, yeah ) and mangle with thresholds for some individual drives letter as exclusions.

NSClient version: ‘0.4.4.23’


#2

Strings need to be qouted (single ticks) like so:

check_drivesize "warning=(( used > 90% ) and ( drive != 'F' )) or ( ( used > 99% ) and ( drive = 'F' ))"

In your case you can make it a tad simpler though:

check_drivesize "warning=(used > 90% and drive != 'F') or used > 99%"

#3

Thanks Mike It was really helpful

I ended up with following monster.

2 drawbacks for such solution:

  1. Its complex and hard to understand
  2. Perfdata for each drive uses first occurrence of warn/crit thresholds filtering query (warn=80%, crit=90% in example ).

Chef things NSClient configuration managed with Chef, and it’s being done like that:

Cookbook/recipe code

attributes/default.rb
...
default['nsclient_checks'] = {
    alias_disk_warn: 'used>=80%',
    alias_disk_crit: 'used>=90%',
    alias_disk_drive: 'all-drives',
    alias_disk_exclude: '',
    custom_disks: {},
...

Then a bit of madness in erb template:

templates/default/nsclient.ini.erb
...
<%
  # Dynamically create check_disk query if custom_disk thresholds set for given node.
  # dw_sx1 = disk_warning_suffix1 , dw_sx2 = disk_warning_suffix2
  dw_sx1 = ''
  dw_sx2 = ''
  # dc_sx1 = disc_critical_suffix1, dc_sx2 = disk_critical_suffix2
  dc_sx1 = ''
  dc_sx2 = ''
  alias_disk_warn = node['nsclient_checks']['alias_disk_warn']
  alias_disk_crit = node['nsclient_checks']['alias_disk_crit']

  # Iterate over custom disks and create check_drivesize query if any custom limits defined.
  node['nsclient_checks']['custom_disks'].each do |disk,limits|
    if limits.key?('warn')
      dw_sx1 +=" and drive!='#{disk}:\\\\'"
      dw_sx2 +=" or ((#{limits.warn}) and (drive='#{disk}:\\\\'))"
    end
    if limits.key?('crit')
      dc_sx1 +=" and drive!='#{disk}:\\\\'"
      dc_sx2 +=" or ((#{limits.crit}) and (drive='#{disk}:\\\\'))"
    end
  end

  alias_disk_warn = "(#{alias_disk_warn}#{dw_sx1})#{dw_sx2}" unless dw_sx2.empty?
  alias_disk_crit = "(#{alias_disk_crit}#{dc_sx1})#{dc_sx2}" unless dc_sx2.empty?
%>
...
alias_disk2=check_drivesize "warn=<%= alias_disk_warn %>" "crit=<%= alias_disk_crit %>" drive=<%= @alias_disk_drive%> "filter=type in ('FIXED')" <% unless @alias_disk_exclude.empty? %><%= @alias_disk_exclude %>"<% end %>

By default this code will generate simple alias_disk definition that’s checks all drives with common default thresholds

When there is need to redefine warn/crit for some node we may specify on node level something similar to that:

node.override['nsclient_checks']['custom_disks'] = {
  'C' => {
    warn: 'used>=20%',
    crit: 'used>=30%'
  },
  'D' => {
    warn: 'used>=95%',
    crit: 'used>=98%'
  }
}

Last will generate check_drivesize query given on top of that comment.