Skip to content

Icinga2 CheckCommand

Richard Hillmann edited this page Mar 31, 2017 · 1 revision

CheckCommand definition

This is the command definition for Icinga 2

# https://github.com/phrawzty/check_http_json
object CheckCommand "http_json" {
    import "plugin-check-command"

    command = [ PluginDir + "/check_http_json.rb" ]

    arguments = {
        # connection
        "--uri" = {
            value       = "$http_json_uri$"
            description = "Target URI. Incompatible with -f"
            required    = true
        }
        "--timeout" = {
            value       = "$http_json_timeout$"
            description = "Wait before HTTP timeout"
        }
        "--user" = {
            value       = "$http_json_user$"
            description = "HTTP basic authentication username"
        }
        "--password" = {
            value       = "$http_json_password$"
            description = "HTTP basic authentication password"
        }
        "--headers" = {
            value       = "$http_json_headers$"
            description = "Comma-separated list of HTTP headers to include (ex. HOST:somehost,AUTH:letmein)"
        }

        # additional status check
        "--status_level" = {
            value       = "$http_json_status_level$"
            description = " Comma-separated list of HTTP status codes and their associated Nagios alert levels (ex. 301:1,404:2)"
        }

        # element to check
        "--element" = {
            value       = "$http_json_element$"
            description = "Desired element (ex. foo=>bar=>ish is foo.bar.ish)"
            repeat_key  = true
        }
        "--element_regex" = {
            value       = "$http_json_element_regex$"
            description = "Desired element expressed as regular expression"
        }
        "--element_regex_global" = {
            value       = "$http_json_element_regex$"
            description = "Check all occurring matches. -E (--element_regex) is required."
        }
        "--delimiter" = {
            value       = "$http_json_delimiter$"
            description = "Element delimiter (default is .)"
        }

        # add. performance counter
        "--perf" = {
            value       = "$http_json_perf$"
            description = "Output additional fields (performance metrics); comma-separated"
        }

        # integer thresholds (nagios compatible)
        # https://nagios-plugins.org/doc/guidelines.html#THRESHOLDFORMAT
        "--warn" = {
            value       = "$http_json_warn$"
            description = "Warning threshold (integer)"
        }
        "--crit" = {
            value       = "$http_json_crit$"
            description = "Critical threshold (integer)"
        }

        # OR string result compare
        "--result" = {
            value       = "$http_json_result$"
            description = "Expected string result. No need for --warn or --crit"
        }
        "--result_regex" = {
            value       = "$http_json_result_regex$"
            description = "Expected string result expressed as regular expression. No need for --warn or --crit"
        }
        "--result_warn" = {
            value       = "$http_json_result_warnt$"
            description = "Warning if element is [string]. --result_crit is required"
        }
        "--result_crit" = {
            value       = "$http_json_result_crit$"
            description = "Critical if element is [string]. --result_warn is required"
        }
        # optional unknown
        "--result_unknown" = {
            value        = "$http_json_result_unknown$"
            description = "Unknown if element is [string]. --result_crit is required"
        }
    }
    vars.http_json_uri = "http://$address$/"
}

Example Service check

# Create template first, so we do not need to re-configure on each service check
template Service "check_http_json_aws_producer" {
  import "generic-service"
  check_command = "http_json"
  vars.http_json_uri = "http://$address$:12345/"
}

apply Service "aws producer status" {
  import "check_http_json_aws_producer"

  vars.http_json_element = "status_broker"
  vars.http_json_result = "UP_AND_RUNNING"

  assign where host.vars.aws.type == "ec2" && host.vars.aws.tags["server-type"] == "producer"
}

apply Service "aws producer status replay" {
  import "check_http_json_aws_producer"

  vars.http_json_element = "status_replay"
  vars.http_json_result = "INACTIVE" 
  vars.http_json_result_warn = "ACTIVE"
  vars.http_json_result_crit = "does not exist" # do not trigger critical

  assign where host.vars.aws.type == "ec2" && host.vars.aws.tags["server-type"] == "producer"
}

# with perf data
apply Service "aws producer heartbeat" {
  import "check_http_json_aws_producer"

  enable_perfdata = true

  vars.http_json_element = "heartbeat.current.status"
  vars.http_json_result = "OK"
  vars.http_json_perf = "heartbeat.meters.OK.rates.oneMinuteRate,heartbeat.meters.NOK.rates.oneMinuteRate"

  assign where host.vars.aws.type == "ec2" && host.vars.aws.tags["server-type"] == "producer"
}
Clone this wiki locally