Discussion:
icinga2: how do I set command parameters?
Tomasz Chmielewski
2014-09-27 19:56:07 UTC
Permalink
I'm trying to use Icinga 2.1.1, but I'm not sure how I can set custom
command parameters.

By default, /etc/icinga2/conf.d/hosts/localhost/http.conf was defined
as:

/*
* The CheckCommand object `http` is provided by
* the plugin check command templates.
* Check the documentation for details.
*/
object Service "http" {
import "generic-service"

host_name = "localhost"
check_command = "http"
vars.sla = "24x7"
}


I also see "http" command was defined in
/usr/share/icinga2/include/command-plugins.conf as:

object CheckCommand "http" {
import "plugin-check-command"

command = [ PluginDir + "/check_http" ]

arguments = {
"-H" = "$http_vhost$"
"-I" = "$http_address$"
"-u" = "$http_uri$"
"-p" = "$http_port$"
"-S" = {
set_if = "$http_ssl$"
}
"--sni" = {
set_if = "$http_sni$"
}
"-a" = {
value = "$http_auth_pair$"
description = "Username:password on sites with
basic authentication"
}
"--no-body" = {
set_if = "$http_ignore_body$"
}
"-r" = "$http_expect_body_regex$"
"-w" = "$http_warn_time$"
"-c" = "$http_critical_time$"
"-e" = "$http_expect$"
}

vars.http_address = "$address$"
vars.http_ssl = false
vars.http_sni = false
}


Now, how do I modify /etc/icinga2/conf.d/hosts/localhost/http.conf so
that it contains several other parameters available from
/usr/lib/nagios/plugins/check_http command?

For example, I would like /etc/icinga2/conf.d/hosts/localhost/http.conf
check to contain -H and -s parameters.
--
Tomasz Chmielewski
http://www.sslrack.com
Markus Frosch
2014-09-28 12:27:17 UTC
Permalink
Hi Tomasz,
Post by Tomasz Chmielewski
I'm trying to use Icinga 2.1.1, but I'm not sure how I can set custom
command parameters.
By default, /etc/icinga2/conf.d/hosts/localhost/http.conf was defined
/*
* The CheckCommand object `http` is provided by
* the plugin check command templates.
* Check the documentation for details.
*/
object Service "http" {
import "generic-service"
host_name = "localhost"
check_command = "http"
vars.sla = "24x7"
}
I also see "http" command was defined in
object CheckCommand "http" {
import "plugin-check-command"
command = [ PluginDir + "/check_http" ]
arguments = {
"-H" = "$http_vhost$"
"-I" = "$http_address$"
"-u" = "$http_uri$"
"-p" = "$http_port$"
"-S" = {
set_if = "$http_ssl$"
}
"--sni" = {
set_if = "$http_sni$"
}
"-a" = {
value = "$http_auth_pair$"
description = "Username:password on sites with
basic authentication"
}
"--no-body" = {
set_if = "$http_ignore_body$"
}
"-r" = "$http_expect_body_regex$"
"-w" = "$http_warn_time$"
"-c" = "$http_critical_time$"
"-e" = "$http_expect$"
}
vars.http_address = "$address$"
vars.http_ssl = false
vars.http_sni = false
}
Now, how do I modify /etc/icinga2/conf.d/hosts/localhost/http.conf so
that it contains several other parameters available from
/usr/lib/nagios/plugins/check_http command?
For example, I would like /etc/icinga2/conf.d/hosts/localhost/http.conf
check to contain -H and -s parameters.
Thats simple, just add the appropriate vars to the service definition.

object Service "http" {
import "generic-service"

host_name = "localhost"
check_command = "http"
vars.sla = "24x7"
vars.http_ssl = 1
vars.http_vhost = "host.domain.com"
}

http_address (-I) is automatically set to the hosts address.

Cheers
Markus
--
Markus Frosch
markus-***@public.gmane.org
http://www.lazyfrosch.de
Tomasz Chmielewski
2014-09-28 13:12:21 UTC
Permalink
Post by Markus Frosch
Thats simple, just add the appropriate vars to the service definition.
object Service "http" {
import "generic-service"
host_name = "localhost"
check_command = "http"
vars.sla = "24x7"
vars.http_ssl = 1
vars.http_vhost = "host.domain.com"
}
http_address (-I) is automatically set to the hosts address.
Thanks - and what would be the best way to achieve the following?

Coming from Nagios, I was using the following check which was useful to
set custom parameters:

1) first, I've defined a custom http command - very simple:

define command {
command_name check_http_cmd
command_line $USER1$/check_http $ARG1$
}


2) then, it allowed me to use a check like this:

define service {
use generic-service-nknews
hosts web1.example.com,
web2.example.com, web3.example.com
service_description HTTP - www.example.com
max_check_attempts 3
normal_check_interval 10
retry_check_interval 1
check_command check_http_cmd!-I $HOSTADDRESS$
-H www.example.com -s "2014 Example Inc" -t 10
}


And with a few lines, I was able to:

a) monitor several hosts at once (web1, web2, web3)

b) use custom check_http parameters for any other hosts

Now, I'm struggling to recreate a similar thing in Icinga 2.
--
Tomasz Chmielewski
http://www.sslrack.com
Markus Frosch
2014-09-28 13:26:25 UTC
Permalink
Post by Tomasz Chmielewski
Thanks - and what would be the best way to achieve the following?
Coming from Nagios, I was using the following check which was useful to
define command {
command_name check_http_cmd
command_line $USER1$/check_http $ARG1$
}
define service {
use generic-service-nknews
hosts web1.example.com,
web2.example.com, web3.example.com
service_description HTTP - www.example.com
max_check_attempts 3
normal_check_interval 10
retry_check_interval 1
check_command check_http_cmd!-I $HOSTADDRESS$
-H www.example.com -s "2014 Example Inc" -t 10
}
a) monitor several hosts at once (web1, web2, web3)
b) use custom check_http parameters for any other hosts
Now, I'm struggling to recreate a similar thing in Icinga 2.
Well, as -s is not yet included in the default object, you would have to
extend (not copy) the http CheckCommand:

object CheckCommand "http_custom" {
import "http"

// add own params
arguments += {
"-s" = "$http_search$"
"-t" = "$http_timeout$"
}
}

And use apply Service to add the monitoring:

apply Service "website" {
import "generic-service"

check_command = "http_custom"
vars.sla = "24x7"

vars += {
http_vhost = "www.example.com"
http_search = "2014 Example Inc."
http_timeout = 10
}

assign where match(host.name, "web*.example.com")
// or some other assignment that makes sense
}

Cheers
Markus
--
Markus Frosch
markus-***@public.gmane.org
http://www.lazyfrosch.de
Loading...