Icinga2 Custom Pluggins to Add in Check_command

I have been using all my plugins from ITL templates…At this time there is a custom plugin check_cpu.sh which i wanted to use… I have downloaded check_cpu.sh plugin on client host from exchange under /usr/lib/nagios/plugins.

At this time how can we update the check_command syntax? when i do the check_cpu.sh help its coming as below
check_cpu.sh Revision 1.0 - CPU Utilization check script for Nagios

Usage: check_cpu.sh [flags]

Flags:
-w : Global Warning level in % for user/system/io-wait cpu
-uw : Warning level in % for user cpu
-iw : Warning level in % for IO_wait cpu
-sw : Warning level in % for system cpu
-c : Global Critical level in % for user/system/io-wait cpu
-uc : Critical level in % for user cpu
-ic : Critical level in % for IO_wait cpu
-sc : Critical level in % for system cpu
-i : Interval in seconds for iostat (default : 1)
-n : Number report for iostat (default : 3)
-h Show this page

Usage: check_cpu.sh
Usage: check_cpu.sh --help

but under ITL templates check_command & arguments are different approach as below.

object CheckCommand “cpu-utlization” {
command = [ PluginDir + “/check_cpu_usage” ]

    arguments = {
            "-w" = {
                    value = "$load_wload1$,$load_wload5$,$load_wload15$"
                    description = "Exit with WARNING status if load average exceeds WLOADn"
            }
            "-c" = {
                    value = "$load_cload1$,$load_cload5$,$load_cload15$"
                    description = "Exit with CRITICAL status if load average exceed CLOADn; the load average format is the same used by 'uptime' and 'w'"
            }
            "-r" = {
                    set_if = "$load_percpu$"
                    description = "Divide the load averages by the number of CPUs (when possible)"
            }
    }

I want to understand how can i make these templates files (check_command syntax for check_cpu)?

I am also not able to understand for custom-pluggins where i should i add the checkcommand syntax?

the documentation is very detailed about it , and you can just follow the examples.
But just to help you , you may want to see this small plugin I wrote AND built the command definition object for it

This should give you a good indicator on how to build the command and add all the options.

1 Like

Hi,

I’ve recently updated the corresponding docs for plugins and their integration, please read them if you haven’t done this yet.

I’m not sure what exactly

but under ITL templates check_command & arguments are different approach as below.

means … you’re referring to check_cpu.sh while the check command example refers to check_cpu_usage as script. Is that the same and just renamed?

If so, please keep a note on the parameter names as well as the check command name. There are certain best practices on the naming schema here, e.g. using the descriptive way like this instead of the load_prefixed parameters.

object CheckCommand "cpu_usage" {
  command = [ PluginDir + "/check_cpu_usage" ]

  arguments = {
    "-w" = {
      value = "$cpu_usage_wload1$,$cpu_usage_wload5$,$cpu_usage_wload15$"
      description = "Exit with WARNING status if load average exceeds WLOADn"
    }
    "-c" = {
      value = "$cpu_usage_cload1$,$cpu_usage_cload5$,$cpu_usage_cload15$"
      description = "Exit with CRITICAL status if load average exceeds CLOADn"
    }
    "-r" = {
      set_if = "$cpu_usage_percpu$"
      description = "Divide the load averages by the number of CPUs (when possible)"
    }
  }

  // Set some default values
  vars.cpu_usage_wload1 = 1
  vars.cpu_usage_wload5 = ...
}

For a service apply rule, go with this:

apply Service "cpu-usage" {
  check_command = "cpu_usage"

  vars.cpu_usage_wload1 = ...
  vars.cpu_usage_wload5 = ...
  vars.cpu_usage_wload10 = ...

  assign where host.vars.os_type == "Linux" //or a different pattern
}

Try that - the corresponding configuration (commands, apply rules, etc.) should be put into an included directory from your icinga2.conf. If you’re planning with a distributed setup with agents, put them into a global zone, e.g. zones.d/global-templates/commands.conf.

Cheers,
Michael