-
-
Notifications
You must be signed in to change notification settings - Fork 94
/
service.pp
253 lines (250 loc) · 9.71 KB
/
service.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# @summary
# Manage Icinga 2 service objects.
#
# @example A service `ping` is applied to all hosts with a valid ipv4 address.
# ::icinga2::object::service { 'ping4':
# import => ['generic-service'],
# apply => true,
# check_command => 'ping',
# assign => ['host.address'],
# target => '/etc/icinga2/zones.d/global-templates/services.conf',
# }
#
# @example A `apply Service for (disk_name =>config in host.vars.disks)` rule is applied to all Linux hosts with an Icinga Agent. Note in this example it's required that the endpoint (see `command_endpoint`) and the host object has the same name!
# ::icinga2::object::service { 'linux_disks':
# import => ['generic-service'],
# apply => 'disk_name => config in host.vars.disks',
# check_command => 'disk',
# command_endpoint => 'host.name',
# vars => '+ config',
# assign => ['host.vars.os == Linux'],
# ignore => ['host.vars.noagent'],
# target => '/etc/icinga2/zones.d/global-templates/services.conf',
# }
#
# @param ensure
# Set to present enables the object, absent disables it.
#
# @param service_name
# Set the Icinga 2 name of the service object.
#
# @param display_name
# A short description of the service.
#
# @param host_name
# The host this service belongs to. There must be a Host object with
# that name.
#
# @param groups
# The service groups this service belongs to.
#
# @param vars
# A dictionary containing custom attributes that are specific to this service,
# a string to do operations on this dictionary or an array for multiple use
# of custom attributes.
#
# @param check_command
# The name of the check command.
#
# @param max_check_attempts
# The number of times a service is re-checked before changing into a hard
# state.
#
# @param check_period
# The name of a time period which determines when this service should be
# checked.
#
# @param check_timeout
# Check command timeout in seconds. Overrides the CheckCommand's timeout
# attribute.
#
# @param check_interval
# The check interval (in seconds). This interval is used for checks when the
# service is in a HARD state.
#
# @param retry_interval
# The retry interval (in seconds). This interval is used for checks when the
# service is in a SOFT state.
#
# @param enable_notifications
# Whether notifications are enabled.
#
# @param enable_active_checks
# Whether active checks are enabled.
#
# @param enable_passive_checks
# Whether passive checks are enabled.
#
# @param enable_event_handler
# Enables event handlers for this host.
#
# @param enable_flapping
# Whether flap detection is enabled.
#
# @param enable_perfdata
# Whether performance data processing is enabled.
#
# @param event_command
# The name of an event command that should be executed every time the
# service's state changes or the service is in a SOFT state.
#
# @param flapping_threshold_low
# Flapping lower bound in percent for a host to be considered not flapping.
#
# @param flapping_threshold_high
# Flapping upper bound in percent for a host to be considered flapping.
#
# @param volatile
# The volatile setting enables always HARD state types if NOT-OK state changes
# occur.
#
# @param zone
# The zone this object is a member of.
#
# @param command_endpoint
# The endpoint where commands are executed on.
#
# @param notes
# Notes for the service.
#
# @param notes_url
# Url for notes for the service (for example, in notification commands).
#
# @param action_url
# Url for actions for the service (for example, an external graphing tool).
#
# @param icon_image
# Icon image for the service. Used by external interfaces only.
#
# @param icon_image_alt
# Icon image description for the service. Used by external interface only.
#
# @param template
# Set to true creates a template instead of an object.
#
# @param apply
# Dispose an apply instead an object if set to 'true'. Value is taken as statement,
# i.e. 'vhost => config in host.vars.vhosts'.
#
# @param prefix
# Set service_name as prefix in front of 'apply for'. Only effects if apply is a string.
#
# @param assign
# Assign service using the assign rules.
#
# @param ignore
# Exclude service using the ignore rules.
#
# @param import
# Sorted List of templates to include.
#
# @param target
# Destination config file to store in this object. File will be declared the
# first time.
#
# @param order
# String or integer to set the position in the target file, sorted alpha numeric.
#
# @param export
# Export object to destination, collected by class `icinga2::query_objects`.
#
define icinga2::object::service (
Stdlib::Absolutepath $target,
Enum['absent', 'present'] $ensure = present,
String[1] $service_name = $title,
Optional[String[1]] $display_name = undef,
Optional[String[1]] $host_name = undef,
Optional[Array[String[1]]] $groups = undef,
Optional[Icinga2::CustomAttributes] $vars = undef,
Optional[String[1]] $check_command = undef,
Optional[Integer[1]] $max_check_attempts = undef,
Optional[String[1]] $check_period = undef,
Optional[Icinga2::Interval] $check_timeout = undef,
Optional[Icinga2::Interval] $check_interval = undef,
Optional[Icinga2::Interval] $retry_interval = undef,
Optional[Boolean] $enable_notifications = undef,
Optional[Boolean] $enable_active_checks = undef,
Optional[Boolean] $enable_passive_checks = undef,
Optional[Boolean] $enable_event_handler = undef,
Optional[Boolean] $enable_flapping = undef,
Optional[Boolean] $enable_perfdata = undef,
Optional[String[1]] $event_command = undef,
Optional[Integer[1]] $flapping_threshold_low = undef,
Optional[Integer[1]] $flapping_threshold_high = undef,
Optional[Boolean] $volatile = undef,
Optional[String[1]] $zone = undef,
Optional[String[1]] $command_endpoint = undef,
Optional[String[1]] $notes = undef,
Optional[String[1]] $notes_url = undef,
Optional[String[1]] $action_url = undef,
Optional[String[1]] $icon_image = undef,
Optional[String[1]] $icon_image_alt = undef,
Variant[Boolean, String[1]] $apply = false,
Variant[Boolean, String[1]] $prefix = false,
Array[String[1]] $assign = [],
Array[String[1]] $ignore = [],
Array[String[1]] $import = [],
Boolean $template = false,
Variant[String[1], Integer[0]] $order = 60,
Variant[Array[String[1]], String[1]] $export = [],
) {
require icinga2::globals
# compose the attributes
$attrs = {
'display_name' => $display_name,
'host_name' => $host_name,
'check_command' => $check_command,
'check_timeout' => $check_timeout,
'check_interval' => $check_interval,
'check_period' => $check_period,
'retry_interval' => $retry_interval,
'max_check_attempts' => $max_check_attempts,
'groups' => $groups,
'enable_notifications' => $enable_notifications,
'enable_active_checks' => $enable_active_checks,
'enable_passive_checks' => $enable_passive_checks,
'enable_event_handler' => $enable_event_handler,
'enable_flapping' => $enable_flapping,
'enable_perfdata' => $enable_perfdata,
'event_command' => $event_command,
'flapping_threshold_low' => $flapping_threshold_low,
'flapping_threshold_high' => $flapping_threshold_high,
'volatile' => $volatile,
'zone' => $zone,
'command_endpoint' => $command_endpoint,
'notes' => $notes,
'notes_url' => $notes_url,
'action_url' => $action_url,
'icon_image' => $icon_image,
'icon_image_alt' => $icon_image_alt,
'vars' => $vars,
}
# create object
$config = {
'object_name' => $service_name,
'object_type' => 'Service',
'import' => $import,
'apply' => $apply,
'prefix' => $prefix,
'assign' => $assign,
'ignore' => $ignore,
'template' => $template,
'attrs' => delete_undef_values($attrs),
'attrs_list' => keys($attrs),
}
unless empty($export) {
@@icinga2::config::fragment { "icinga2::object::Service::${title}":
tag => prefix(any2array($export), 'icinga2::instance::'),
content => epp('icinga2/object.conf.epp', $config),
target => $target,
order => $order,
}
} else {
icinga2::object { "icinga2::object::Service::${title}":
ensure => $ensure,
target => $target,
order => $order,
* => $config,
}
}
}