Add a Service to Icinga2
params is an Hash with following Parameters:
| Parameter | Type | Example | Description |
|---|---|---|---|
host_name |
String | foo |
existing Host for these Service |
name |
String | ping4 |
Service Name they will be create |
display_name |
String | ping4 check |
displayed Name |
templates |
Array | ['own-service'] |
(optional) a Array of templates (default: ['generic-service']) |
check_command |
String | ping4 |
The Check Command to execute (Importand This Check-Comand must be exists! Otherwise an error will occur) |
check_interval |
Integer | 10 |
The check Interval |
retry_interval |
Integer | 30 |
The retry Interval |
notes |
String | `` | |
notes_url |
String | `` | |
action_url |
String | `` | |
check_period |
String | `` | |
check_timeout |
Integer | `` | |
command_endpoint |
String | `` | |
enable_active_checks |
Bool | `` | |
enable_event_handler |
Bool | `` | |
enable_flapping |
Bool | `` | |
enable_notifications |
Bool | `` | |
enable_passive_checks |
Bool | `` | |
enable_perfdata |
Bool | `` | |
event_command |
String | `` | |
flapping_threshold_high |
Integer | `` | |
flapping_threshold_low |
Integer | `` | |
flapping_threshold |
Integer | `` | |
icon_image_alt |
String | `` | |
icon_image |
String | `` | |
max_check_attempts |
Integer | `` | |
volatile |
Bool | `` | |
vars |
Hash | (see below) | optional config params for the check_command |
The result are an Hash
@icinga.add_services(
host_name: 'foo',
name: 'ping4',
check_command: 'ping4',
check_interval: 10,
retry_interval: 30
)
or
@icinga.add_service(
host_name: 'foo',
name: 'http',
check_command: 'http',
check_interval: 10,
retry_interval: 30,
vars: {
http_address: '127.0.0.1',
http_url: '/access/index',
http_port: 80
}
)
Delete an Service From Icinga2
params is an Hash with following Parameters:
| Parameter | Type | Example | Description |
|---|---|---|---|
host |
String | foo |
existing Host for these Service |
name |
String | ping4 |
Service Name they will be deleted |
cascade |
Bool | true |
delete service also when other objects depend on it (default: false) |
The result are an Hash
@icinga.delete_service(host_name: 'foo', name: 'ping4')
or
@icinga.delete_service(host_name: 'foo', name: 'new_ping4', cascade: true)
Modify an Service.
params is an Hash with following Parameters:
| Parameter | Type | Example | Description |
|---|---|---|---|
name |
String | ping4 |
Service Name they will be deleted |
templates |
Array | ['own-service'] |
(optional) a Array of templates (default: ['generic-service']) |
vars |
Hash | (see below) | Hash with custom options (see add_services()) |
The result are an Hash
@icinga.modify_service(
name: 'http2',
check_interval: 60,
retry_interval: 10,
vars: {
http_url: '/access/login' ,
http_address: '10.41.80.63'
}
)
return all unhandled services
The result are an Hash
@icinga.unhandled_services
returns all or a named service
the optional params is an Hash with following Parameters:
| Parameter | Type | Example | Description |
|---|---|---|---|
host |
String | foo |
Hostname |
service |
String | ping4 |
service to list |
The result are an Hash
services
@icinga.services
services( params )
@icinga.services( host_name: 'icinga2', service: 'ping4' )
check if the service exists
the optional params is an Hash with following Parameters:
| Parameter | Type | Example | Description |
|---|---|---|---|
host |
String | foo |
Hostname |
service |
String | ping4 |
servicename |
The result are an Hash
@icinga.exists_service?( host_name: 'icinga2', service: 'users' )
list service objects
the optional params is an Hash with following Parameters:
| Parameter | Type | Example | Description |
|---|---|---|---|
attrs |
Array | [] |
Array of attrs |
filter |
Array | [] |
Array of filter |
joins |
Array | [] |
Array of joins |
For more Examples for Quering Objects read the Icinga2 Documentation
- defaults for
attrsare['name', 'state', 'acknowledgement', 'downtime_depth', 'last_check'] - defaults for
filterare[] - defaults for
joinsare['host.name','host.state','host.acknowledgement','host.downtime_depth','host.last_check']
The result are an Array
@icinga.service_objects(
attrs: ['name', 'state'],
joins: ['host.name','host.state']
)
returns adjusted service state
The result are an Hash
warning, critical, unknown = @icinga.services_adjusted.values
or
s = @icinga.services_adjusted
unknown = s.dig(:unknown)
count services with problems
The result are an Integer
@icinga.count_services_with_problems
list of services with problems
The result are an Hash
problems, problems_and_severity = @icinga.list_services_with_problems(10).values
or
l = @icinga.list_services_with_problems(10)
problems_and_severity = l.dig(:services_with_problems_and_severity)
count all services
The result are an Integer
@icinga.services_all
returns data with service problems
The result are an Hash
all, warning, critical, unknown, pending, in_downtime, acknowledged, adjusted_warning, adjusted_critical, adjusted_unknown = @icinga.service_problems.values
or
p = @icinga.service_problems
warning = p.dig(:warning)
calculate a service severity (taken from the IcingaWeb2 Code)
The result are an Integer
service_severity( {'attrs' => { 'state' => 0.0, 'acknowledgement' => 0.0, 'downtime_depth' => 0.0 } } )