icinga2 0.9.0.1 → 0.9.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,202 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # 07.10.2017 - Bodo Schulz
5
+ #
6
+ #
7
+ # Examples for Hostgroups
8
+
9
+ # -----------------------------------------------------------------------------
10
+
11
+ require_relative '../lib/icinga2'
12
+
13
+ # -----------------------------------------------------------------------------
14
+
15
+ icinga_host = ENV.fetch( 'ICINGA_HOST' , 'icinga2' )
16
+ icinga_api_port = ENV.fetch( 'ICINGA_API_PORT' , 5665 )
17
+ icinga_api_user = ENV.fetch( 'ICINGA_API_USER' , 'admin' )
18
+ icinga_api_pass = ENV.fetch( 'ICINGA_API_PASSWORD' , nil )
19
+ icinga_api_pki_path = ENV.fetch( 'ICINGA_API_PKI_PATH' , '/etc/icinga2' )
20
+ icinga_api_node_name = ENV.fetch( 'ICINGA_API_NODE_NAME' , nil )
21
+ icinga_cluster = ENV.fetch( 'ICINGA_CLUSTER' , false )
22
+ icinga_satellite = ENV.fetch( 'ICINGA_CLUSTER_SATELLITE', nil )
23
+
24
+
25
+ # convert string to bool
26
+ icinga_cluster = icinga_cluster.to_s.eql?('true') ? true : false
27
+
28
+ config = {
29
+ icinga: {
30
+ host: icinga_host,
31
+ api: {
32
+ port: icinga_api_port,
33
+ user: icinga_api_user,
34
+ password: icinga_api_pass,
35
+ pki_path: icinga_api_pki_path,
36
+ node_name: icinga_api_node_name
37
+ },
38
+ cluster: icinga_cluster,
39
+ satellite: icinga_satellite
40
+ }
41
+ }
42
+
43
+ # ---------------------------------------------------------------------------------------
44
+
45
+ i = Icinga2::Client.new( config )
46
+
47
+ unless( i.nil? )
48
+
49
+ # run tests ...
50
+ #
51
+ #
52
+
53
+ begin
54
+
55
+ puts ' ------------------------------------------------------------- '
56
+ puts ''
57
+
58
+ puts ' ==> SERVICES'
59
+ puts ''
60
+
61
+ puts '= service objects'
62
+ puts i.service_objects
63
+ puts ''
64
+
65
+ puts '= service objects with \'attrs\' and \'joins\''
66
+ puts i.service_objects( attrs: %w[name state], joins: ['host.name','host.state'] )
67
+ puts ''
68
+
69
+ puts '= unhandled services'
70
+ puts i.unhandled_services
71
+ puts ''
72
+
73
+ puts format( '= count of all services: %s', i.services_all )
74
+ puts ''
75
+
76
+ puts format( '= count of services with problems: %d', i.count_services_with_problems)
77
+ puts ''
78
+
79
+ all, warning, critical, unknown, pending, in_downtime, acknowledged,
80
+ adjusted_warning, adjusted_critical, adjusted_unknown,
81
+ handled_all, handled_warning, handled_critical, handled_unknown = i.service_problems.values
82
+
83
+ puts '= services with problems'
84
+ puts i.service_problems
85
+ puts format( ' - all : %d', all )
86
+ puts format( ' - warning : %d', warning )
87
+ puts format( ' - critical : %d', critical )
88
+ puts format( ' - unknown : %d', unknown )
89
+ puts format( ' - pending : %d', pending )
90
+ puts format( ' - in_downtime : %d', in_downtime )
91
+ puts format( ' - acknowledged : %d', acknowledged )
92
+ puts format( ' - adj. warning : %d', adjusted_warning )
93
+ puts format( ' - adj. critical : %d', adjusted_critical )
94
+ puts format( ' - adj. unknown : %d', adjusted_unknown )
95
+ puts format( ' - handled all : %d', handled_all )
96
+ puts format( ' - handled warning : %d', handled_warning )
97
+ puts format( ' - handled critical: %d', handled_critical )
98
+ puts format( ' - handled unknown : %d', handled_unknown )
99
+ puts ''
100
+
101
+ puts '= check if Service exists'
102
+ ['c1-mysql-1', 'bp-foo'].each do |h|
103
+ e = i.exists_service?( host_name: h, name: 'ssh' ) ? 'true' : 'false'
104
+ puts format( ' - Service \'ssh\' for Host \'%s\' : %s', h, e )
105
+ end
106
+ puts ''
107
+ ['c1-mysql-1', 'bp-foo'].each do |h|
108
+ e = i.exists_service?( host_name: h, name: 'hdb' ) ? 'true' : 'false'
109
+ puts format( ' - Service \'hdb\' for Host \'%s\' : %s', h, e )
110
+ end
111
+ puts ''
112
+
113
+ puts '= 5 Services with Problems'
114
+
115
+ problems, problems_and_severity = i.list_services_with_problems.values
116
+
117
+ puts format( ' - problems: %s', problems )
118
+ puts format( ' - problems and severity: %s', problems_and_severity )
119
+ puts ''
120
+
121
+
122
+ puts '= get service Objects'
123
+ puts i.service_objects
124
+ puts ''
125
+
126
+ puts '= add service'
127
+ puts i.add_service(
128
+ host_name: 'c1-mysql-1',
129
+ name: 'http2',
130
+ vars: {
131
+ attrs: {
132
+ check_command: 'http',
133
+ check_interval: 10,
134
+ retry_interval: 30,
135
+ vars: {
136
+ http_address: '127.0.0.1',
137
+ http_url: '/access/index',
138
+ http_port: 80
139
+ }
140
+ }
141
+ }
142
+ )
143
+
144
+ puts '= add service (again)'
145
+ puts i.add_service(
146
+ host_name: 'c1-mysql-1',
147
+ name: 'http2',
148
+ vars: {
149
+ attrs: {
150
+ check_command: 'http',
151
+ check_interval: 10,
152
+ retry_interval: 30,
153
+ vars: {
154
+ http_address: '127.0.0.1',
155
+ http_url: '/access/index',
156
+ http_port: 80
157
+ }
158
+ }
159
+ }
160
+ )
161
+
162
+ puts '= modify service'
163
+ puts i.modify_service(
164
+ name: 'http2',
165
+ vars: {
166
+ attrs: {
167
+ check_interval: 60,
168
+ retry_interval: 10,
169
+ vars: {
170
+ http_url: '/access/login' ,
171
+ http_address: '10.41.80.63'
172
+ }
173
+ }
174
+ }
175
+ )
176
+
177
+ puts '= delete service'
178
+ puts i.delete_service(host_name: 'c1-mysql-1', name: 'http2' )
179
+
180
+ puts '= delete service (again)'
181
+ puts i.delete_service(host_name: 'c1-mysql-1', name: 'http2' )
182
+
183
+ puts ''
184
+ puts '= list named Service \'ping4\' from Host \'icinga2\''
185
+ puts i.services( host_name: 'c1-mysql-1', service: 'ping4' )
186
+ puts ''
187
+ puts '= list all Services'
188
+ puts i.services
189
+
190
+ puts ' ------------------------------------------------------------- '
191
+ puts ''
192
+
193
+ rescue => e
194
+ $stderr.puts( e )
195
+ $stderr.puts( e.backtrace.join("\n") )
196
+ end
197
+ end
198
+
199
+
200
+ # -----------------------------------------------------------------------------
201
+
202
+ # EOF
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # 07.10.2017 - Bodo Schulz
5
+ #
6
+ #
7
+ # Examples for Hostgroups
8
+
9
+ # -----------------------------------------------------------------------------
10
+
11
+ require_relative '../lib/icinga2'
12
+
13
+ # -----------------------------------------------------------------------------
14
+
15
+ icinga_host = ENV.fetch( 'ICINGA_HOST' , 'icinga2' )
16
+ icinga_api_port = ENV.fetch( 'ICINGA_API_PORT' , 5665 )
17
+ icinga_api_user = ENV.fetch( 'ICINGA_API_USER' , 'admin' )
18
+ icinga_api_pass = ENV.fetch( 'ICINGA_API_PASSWORD' , nil )
19
+ icinga_api_pki_path = ENV.fetch( 'ICINGA_API_PKI_PATH' , '/etc/icinga2' )
20
+ icinga_api_node_name = ENV.fetch( 'ICINGA_API_NODE_NAME' , nil )
21
+ icinga_cluster = ENV.fetch( 'ICINGA_CLUSTER' , false )
22
+ icinga_satellite = ENV.fetch( 'ICINGA_CLUSTER_SATELLITE', nil )
23
+
24
+
25
+ # convert string to bool
26
+ icinga_cluster = icinga_cluster.to_s.eql?('true') ? true : false
27
+
28
+ config = {
29
+ icinga: {
30
+ host: icinga_host,
31
+ api: {
32
+ port: icinga_api_port,
33
+ user: icinga_api_user,
34
+ password: icinga_api_pass,
35
+ pki_path: icinga_api_pki_path,
36
+ node_name: icinga_api_node_name
37
+ },
38
+ cluster: icinga_cluster,
39
+ satellite: icinga_satellite
40
+ }
41
+ }
42
+
43
+ # ---------------------------------------------------------------------------------------
44
+
45
+ i = Icinga2::Client.new( config )
46
+
47
+ unless( i.nil? )
48
+
49
+ # run tests ...
50
+ #
51
+ #
52
+
53
+ begin
54
+
55
+ i.cib_data
56
+
57
+ puts ' ------------------------------------------------------------- '
58
+ puts ''
59
+
60
+ latency, execution_time = i.average_statistics.values
61
+
62
+ puts format( '= latency: %s', latency )
63
+ puts format( '= execution_time: %s', execution_time )
64
+ puts ''
65
+
66
+ interval_stats = i.interval_statistics
67
+ host_stats = i.host_statistics
68
+ service_stats = i.service_statistics
69
+ work_queue_stats = i.work_queue_statistics
70
+
71
+ hosts_active_checks = interval_stats.dig(:hosts_active_checks)
72
+ hosts_passive_checks = interval_stats.dig(:hosts_passive_checks)
73
+ services_active_checks = interval_stats.dig(:services_active_checks)
74
+ services_passive_checks = interval_stats.dig(:services_passive_checks)
75
+
76
+ host_stats_up = host_stats.dig(:up)
77
+ host_stats_down = host_stats.dig(:down)
78
+ host_stats_pending = host_stats.dig(:pending)
79
+ host_stats_unreachable = host_stats.dig(:unreachable)
80
+ host_stats_in_downtime = host_stats.dig(:in_downtime)
81
+ host_stats_acknowledged = host_stats.dig(:acknowledged)
82
+
83
+ service_stats_ok = service_stats.dig(:ok)
84
+ service_stats_warning = service_stats.dig(:warning)
85
+ service_stats_critical = service_stats.dig(:critical)
86
+ service_stats_unknown = service_stats.dig(:unknown)
87
+ service_stats_pending = service_stats.dig(:pending)
88
+ service_stats_in_downtime = service_stats.dig(:in_downtime)
89
+ service_stats_acknowledged = service_stats.dig(:acknowledged)
90
+
91
+ puts format( '= hosts')
92
+ puts format( ' active checks : %s', hosts_active_checks )
93
+ puts format( ' passive checks: %s', hosts_passive_checks )
94
+ puts ''
95
+ puts format( '= host statistics')
96
+ puts format( ' up : %s', host_stats_up )
97
+ puts format( ' down : %s', host_stats_down )
98
+ puts format( ' pending : %s', host_stats_pending )
99
+ puts format( ' unreachable : %s', host_stats_unreachable )
100
+ puts format( ' in downtime : %s', host_stats_in_downtime )
101
+ puts format( ' acknowledged : %s', host_stats_acknowledged )
102
+ puts ''
103
+
104
+ puts format( '= services')
105
+ puts format( ' active checks : %s', services_active_checks )
106
+ puts format( ' passive checks: %s', services_passive_checks )
107
+ puts ''
108
+ puts format( '= service statistics')
109
+ puts format( ' ok : %s', service_stats_ok )
110
+ puts format( ' warning : %s', service_stats_warning )
111
+ puts format( ' critical : %s', service_stats_critical )
112
+ puts format( ' unknown : %s', service_stats_unknown )
113
+ puts format( ' pending : %s', service_stats_pending )
114
+ puts format( ' in downtime : %s', service_stats_in_downtime )
115
+ puts format( ' acknowledged : %s', service_stats_acknowledged )
116
+ puts ''
117
+ puts format( '= workqueue statistics')
118
+
119
+ work_queue_stats.each do |k,v|
120
+ puts format(' %s : %s', k, v )
121
+ end
122
+ puts ''
123
+
124
+ puts ' ------------------------------------------------------------- '
125
+ puts ''
126
+
127
+ rescue => e
128
+ $stderr.puts( e )
129
+ $stderr.puts( e.backtrace.join("\n") )
130
+ end
131
+ end
132
+
133
+
134
+ # -----------------------------------------------------------------------------
135
+
136
+ # EOF
137
+
@@ -18,12 +18,6 @@ icinga_api_user = ENV.fetch( 'ICINGA_API_USER' , 'admin' )
18
18
  icinga_api_pass = ENV.fetch( 'ICINGA_API_PASSWORD' , nil )
19
19
  icinga_api_pki_path = ENV.fetch( 'ICINGA_API_PKI_PATH' , '/etc/icinga2' )
20
20
  icinga_api_node_name = ENV.fetch( 'ICINGA_API_NODE_NAME' , nil )
21
- icinga_cluster = ENV.fetch( 'ICINGA_CLUSTER' , false )
22
- icinga_satellite = ENV.fetch( 'ICINGA_CLUSTER_SATELLITE', nil )
23
-
24
-
25
- # convert string to bool
26
- icinga_cluster = icinga_cluster.to_s.eql?('true') ? true : false
27
21
 
28
22
  config = {
29
23
  icinga: {
@@ -34,9 +28,7 @@ config = {
34
28
  password: icinga_api_pass,
35
29
  pki_path: icinga_api_pki_path,
36
30
  node_name: icinga_api_node_name
37
- },
38
- cluster: icinga_cluster,
39
- satellite: icinga_satellite
31
+ }
40
32
  }
41
33
  }
42
34
 
@@ -49,375 +41,38 @@ unless( i.nil? )
49
41
  # run tests ...
50
42
  #
51
43
  #
52
-
53
- puts ''
54
- puts ' ============================================================= '
55
- puts '= icinga2 available'
56
- puts i.available?
57
- puts ''
58
- puts '= icinga2 status'
59
- puts i.status_data
60
- puts ''
61
-
62
- puts '= icinga2 application data'
63
- puts i.application_data
64
- puts ''
65
- puts '= CIB'
66
- puts i.cib_data
67
- puts ''
68
- puts '= API Listener'
69
- puts i.api_listener
70
- puts ''
71
-
72
- v, r = i.version
73
- l, e = i.average_statistics
74
- puts format( '= version: %s, revision %s', v, r )
75
- puts format( '= avg_latency: %s, avg_execution_time %s', l, e )
76
- puts format( '= start time: %s', i.start_time )
77
- puts format( '= uptime: %s', i.uptime )
78
- puts ''
79
-
80
- puts ''
81
- puts ' ------------------------------------------------------------- '
82
- puts ''
83
- puts ' ==> HOSTS'
84
- puts ''
85
-
86
- i.cib_data
87
- i.host_objects
88
-
89
- p, a = i.hosts_adjusted
90
-
91
- puts format( '= host handled problems : %s', p )
92
- puts format( '= host down adjusted : %s', a )
93
-
94
- puts '= host objects'
95
-
96
- all, down, critical, unknown = i.host_problems.values
97
-
98
- puts format( '= count of all hosts : %d', i.hosts_all )
99
- puts format( '= hosts with problems: %s', i.list_hosts_with_problems )
100
- puts format( '= hosts are down : %d', down )
101
- puts format( '= hosts are critical : %d', critical )
102
- puts format( '= hosts are unknown : %d', unknown )
103
- puts format( '= count hosts w. problems: %d', i.count_hosts_with_problems )
104
-
105
- ['icinga2', 'bp-foo'].each do |h|
106
- puts format( '= check if Host \'%s\' exists', h )
107
- puts i.exists_host?( h ) ? 'true' : 'false'
44
+ begin
45
+ # examples from: https://github.com/saurabh-hirani/icinga2-api-examples
46
+ #
47
+ # Get display_name, check_command attribute for services applied for filtered hosts matching host.address == 1.2.3.4.
48
+ # Join the output with the hosts on which these checks run (services are applied to hosts)
49
+ #
50
+ puts i.service_objects(
51
+ attrs: ['display_name', 'check_command'],
52
+ filter: 'match("1.2.3.4",host.address)' ,
53
+ joins: ['host.name', 'host.address']
54
+ )
55
+ puts ''
56
+ # Get all services in critical state and filter out the ones for which active checks are disabled
57
+ # service.states - 0 = OK, 1 = WARNING, 2 = CRITICAL
58
+ #
59
+ # { "joins": ['host.name', 'host.address'], "filter": "service.state==2", "attrs": ['display_name', 'check_command', 'enable_active_checks'] }
60
+ puts i.service_objects(
61
+ attrs: ['display_name', 'check_command', 'enable_active_checks'],
62
+ filter: 'service.state==1',
63
+ joins: ['host.name', 'host.address']
64
+ )
65
+ puts ''
66
+ # Get host name, address of hosts belonging to a specific hostgroup
67
+ puts i.host_objects(
68
+ attrs: ['display_name', 'name', 'address'],
69
+ filter: '"windows-servers" in host.groups'
70
+ )
71
+
72
+ rescue => e
73
+ $stderr.puts( e )
74
+ $stderr.puts( e.backtrace.join("\n") )
108
75
  end
109
-
110
- puts ''
111
- puts '= Problem Hosts'
112
- puts i.list_hosts_with_problems
113
- puts ''
114
-
115
- ['icinga2', 'bp-foo'].each do |h|
116
- puts format('= list named Hosts \'%s\'', h )
117
- puts i.hosts( host: h )
118
- end
119
-
120
- puts ''
121
- puts '= list all Hosts'
122
- puts i.hosts
123
- puts ''
124
- puts ' = delete Host'
125
- puts i.delete_host( host: 'foo' )
126
- puts ''
127
- puts ' = add Host'
128
- puts i.add_host(
129
- host: 'foo',
130
- fqdn: 'foo.bar.com',
131
- display_name: 'test node',
132
- max_check_attempts: 5,
133
- notes: 'test node'
134
- )
135
- puts ''
136
- puts ' ------------------------------------------------------------- '
137
- puts ''
138
-
139
- puts ' ------------------------------------------------------------- '
140
- puts ''
141
- puts ' ==> HOSTGROUPS'
142
- puts ''
143
- puts '= check if Hostgroup \'linux-servers\' exists'
144
- puts i.exists_hostgroup?( 'linux-servers' ) ? 'true' : 'false'
145
- puts ''
146
- puts '= list named Hostgroup \'linux-servers\''
147
- puts i.hostgroups( host_group: 'linux-servers' )
148
- puts '= list named Hostgroup \'foo\''
149
- puts i.hostgroups( host_group: 'foo' )
150
- puts ''
151
- puts '= list all Hostgroups'
152
- puts i.hostgroups
153
- puts ''
154
- puts '= add hostgroup \'foo\''
155
- puts i.add_hostgroup( host_group: 'foo', display_name: 'FOO' )
156
- puts ''
157
- puts '= delete Hostgroup \'foo\''
158
- puts i.delete_hostgroup( host_group: 'foo' )
159
- puts ''
160
- puts ' ------------------------------------------------------------- '
161
- puts ''
162
-
163
- puts ''
164
- puts ' ------------------------------------------------------------- '
165
- puts ''
166
- puts ' ==> SERVICES'
167
- puts ''
168
- i.cib_data
169
- i.service_objects
170
-
171
- all, warning, critical, unknown, pending, in_downtime, acknowledged = i.service_problems.values
172
- puts format( '= count of all services: %d', i.services_all )
173
- puts format( '= services warning: %d', warning)
174
- puts format( '= services critical: %d', critical)
175
- puts format( '= services unknown: %d', unknown)
176
- puts format( '= services in downtime: %d', in_downtime)
177
- puts format( '= services acknowledged: %d', acknowledged)
178
-
179
- puts ''
180
- all, warning, critical, unknown = i.service_problems_handled.values
181
- puts format( '= services handled warning problems: %d', warning)
182
- puts format( '= services handled critical problems: %d', critical)
183
- puts format( '= services handled unknown problems: %d', unknown)
184
- puts ''
185
- warning, critical, unknown = i.services_adjusted.values
186
- puts format( '= services adjusted warning: %d', warning)
187
- puts format( '= services adjusted critical: %d', critical)
188
- puts format( '= services adjusted unknown: %d', unknown)
189
-
190
- puts ''
191
- puts '= check if service \'users\' on host \'icinga2\' exists'
192
- puts i.exists_service?( host: 'icinga2', service: 'users' ) ? 'true' : 'false'
193
- puts ''
194
- puts '= get service Objects'
195
- puts i.service_objects
196
- puts ''
197
- puts '= Services with problems'
198
- puts i.count_services_with_problems
199
- puts ''
200
- puts '= Problem Services'
201
- a,b = i.list_services_with_problems
202
- puts a
203
- puts b
204
- puts ''
205
- puts i.list_services_with_problems(10)
206
- puts ''
207
- puts '= list named Service \'ping4\' from Host \'icinga2\''
208
- puts i.services( host: 'icinga2', service: 'ping4' )
209
- puts ''
210
- puts '= list all Services'
211
- puts i.services
212
- puts ''
213
- puts '= add Service'
214
- puts i.add_services(
215
- host: 'icinga2',
216
- service_name: 'new_http',
217
- vars: {
218
- attrs: {
219
- check_command: 'http',
220
- check_interval: 10,
221
- retry_interval: 30,
222
- vars: {
223
- http_address: '127.0.0.1',
224
- http_url: '/access/index',
225
- http_port: 80
226
- }
227
- }
228
- }
229
- )
230
- puts ''
231
- puts '= list new named Service \'new_http\' from Host \'icinga2\''
232
- puts i.services( host: 'icinga2', service: 'new_http' )
233
- puts ''
234
- puts '= modify named Service \'new_http\' from Host \'icinga2\''
235
- puts JSON.pretty_generate i.modify_service(
236
- service_name: 'new_http',
237
- vars: {
238
- attrs: {
239
- check_interval: 60,
240
- retry_interval: 10,
241
- vars: {
242
- http_url: '/access/login' ,
243
- http_address: '10.41.80.63'
244
- }
245
- }
246
- }
247
- )
248
- puts ''
249
- puts '= list modified named Service \'new_http\' from Host \'icinga2\''
250
- puts JSON.pretty_generate i.services( host: 'icinga2', service: 'new_http' )
251
- puts ''
252
- puts '= delete named Service \'new_http\' from Host \'icinga2\''
253
- puts i.delete_service(
254
- host: 'icinga2',
255
- service_name: 'new_http',
256
- cascade: true
257
- )
258
- puts ''
259
- puts ' ------------------------------------------------------------- '
260
- puts ''
261
-
262
- puts ''
263
- puts ' ------------------------------------------------------------- '
264
- puts ''
265
- puts ' ==> SERVICEGROUPS'
266
- puts ''
267
- puts 'check if Servicegroup \'disk\' exists'
268
- puts i.exists_servicegroup?( 'disk' ) ? 'true' : 'false'
269
- puts 'check if Servicegroup \'foo\' exists'
270
- puts i.exists_servicegroup?( 'foo' ) ? 'true' : 'false'
271
- puts ''
272
- puts 'list named Servicegroup \'foo\''
273
- puts i.servicegroups( service_group: 'foo' )
274
- puts 'list named Servicegroup \'disk\''
275
- puts i.servicegroups( service_group: 'disk' )
276
- puts ''
277
- puts 'list all Servicegroup'
278
- puts i.servicegroups
279
- puts ''
280
- puts 'add Servicegroup \'foo\''
281
- puts i.add_servicegroup( service_group: 'foo', display_name: 'FOO' )
282
- puts ''
283
- puts 'delete Servicegroup \'foo\''
284
- puts i.delete_servicegroup( service_group: 'foo' )
285
- puts ''
286
- puts ' ------------------------------------------------------------- '
287
- puts ''
288
-
289
- puts ''
290
- puts ' ------------------------------------------------------------- '
291
- puts ''
292
- puts ' ==> USERS'
293
- puts ''
294
- puts 'check if User \'icingaadmin\' exists'
295
- puts i.exists_user?( 'icingaadmin' ) ? 'true' : 'false'
296
- puts ''
297
- puts 'list named User \'icingaadmin\''
298
- puts i.users( user_name: 'icingaadmin' )
299
- puts ''
300
- puts 'list all User'
301
- puts i.users
302
- puts ''
303
- puts 'add User \'foo\''
304
- puts i.add_user( user_name: 'foo', display_name: 'FOO', email: 'foo@bar.com', pager: '0000', groups: ['icingaadmins'] )
305
- puts ''
306
- puts 'delete User \'foo\''
307
- puts i.delete_user( user_name: 'foo' )
308
- puts ''
309
- puts ' ------------------------------------------------------------- '
310
- puts ''
311
- puts ''
312
- puts ' ------------------------------------------------------------- '
313
- puts ''
314
- puts ' ==> USERGROUPS'
315
- puts ''
316
- puts 'check if Usergroup \'icingaadmins\' exists'
317
- puts i.exists_usergroup?( 'icingaadmins' ) ? 'true' : 'false'
318
- puts ''
319
- puts 'list named Usergroup \'icingaadmins\''
320
- puts i.usergroups( user_group: 'icingaadmins' )
321
- puts ''
322
- puts 'list all Usergroup'
323
- puts i.usergroups
324
- puts ''
325
- puts 'add Usergroup \'foo\''
326
- puts i.add_usergroup( user_group: 'foo', display_name: 'FOO' )
327
- puts ''
328
- puts 'delete Usergroup \'foo\''
329
- puts i.delete_usergroup( user_group: 'foo' )
330
- puts ''
331
- puts ''
332
- puts ' ------------------------------------------------------------- '
333
- puts ''
334
-
335
- puts ''
336
- puts ' ------------------------------------------------------------- '
337
- puts ''
338
- puts ' ==> DOWNTIMES'
339
- puts ''
340
- puts 'add Downtime \'test\''
341
- puts i.add_downtime( name: 'test', type: 'service', host: 'foo', comment: 'test downtime', author: 'icingaadmin', start_time: Time.now.to_i, end_time: Time.now.to_i + 20 )
342
- puts ''
343
- puts 'list all Downtimes'
344
- puts i.downtimes
345
- puts ''
346
- puts ' ------------------------------------------------------------- '
347
- puts ''
348
-
349
- puts ''
350
- puts ' ------------------------------------------------------------- '
351
- puts ''
352
- puts ' ==> NOTIFICATIONS'
353
- puts ''
354
- puts 'list all Notifications'
355
- puts i.notifications
356
- puts ''
357
- puts 'enable Notifications for host'
358
- puts i.enable_host_notification( 'icinga2' )
359
- puts ''
360
- puts 'disable Notifications for host'
361
- puts i.disable_host_notification( 'icinga2' )
362
- puts ''
363
- puts 'enable Notifications for host and services'
364
- puts i.enable_service_notification('icinga2')
365
- puts ''
366
- puts 'disable Notifications for host and services'
367
- puts i.disable_service_notification( 'icinga2' )
368
- puts ''
369
- puts 'enable Notifications for hostgroup'
370
- puts i.enable_hostgroup_notification( host: 'icinga2', host_group: 'linux-servers')
371
- puts ''
372
- puts 'disable Notifications for hostgroup'
373
- puts i.disable_hostgroup_notification( host: 'icinga2', host_group: 'linux-servers')
374
- puts ''
375
- puts ''
376
- puts ' ------------------------------------------------------------- '
377
- puts ''
378
-
379
- puts ''
380
- puts ' ------------------------------------------------------------- '
381
- puts ''
382
- puts ' ==> WORK QUEUE STATISTICS'
383
- puts ''
384
- puts 'work queue statistics'
385
- puts i.work_queue_statistics
386
- puts ''
387
- puts ' ------------------------------------------------------------- '
388
- puts ''
389
-
390
-
391
- # # examples from: https://github.com/saurabh-hirani/icinga2-api-examples
392
- # #
393
- # # Get display_name, check_command attribute for services applied for filtered hosts matching host.address == 1.2.3.4.
394
- # # Join the output with the hosts on which these checks run (services are applied to hosts)
395
- # #
396
- # puts i.service_objects(
397
- # attrs: ["display_name", "check_command"],
398
- # filter: "match(\"1.2.3.4\",host.address)" ,
399
- # joins: ["host.name", "host.address"]
400
- # )
401
- #
402
- # puts ''
403
- #
404
- # # Get all services in critical state and filter out the ones for which active checks are disabled
405
- # # service.states - 0 = OK, 1 = WARNING, 2 = CRITICAL
406
- # #
407
- # # { "joins": ["host.name", "host.address"], "filter": "service.state==2", "attrs": ["display_name", "check_command", "enable_active_checks"] }
408
- # puts i.service_objects(
409
- # attrs: ["display_name", "check_command", "enable_active_checks"],
410
- # filter: "service.state==1" ,
411
- # joins: ["host.name", "host.address"]
412
- # )
413
- #
414
- # puts ''
415
- # # Get host name, address of hosts belonging to a specific hostgroup
416
- # puts i.host_objects(
417
- # attrs: ["display_name", "name", "address"],
418
- # filter: "\"windows-servers\" in host.groups"
419
- # )
420
-
421
76
  end
422
77
 
423
78