icinga2 0.9.2.1 → 0.9.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -22
  3. data/doc/Array.html +4 -6
  4. data/doc/Boolean.html +4 -6
  5. data/doc/FalseClass.html +4 -6
  6. data/doc/Hash.html +126 -8
  7. data/doc/Icinga2.html +7 -9
  8. data/doc/Logging.html +5 -7
  9. data/doc/Object.html +8 -10
  10. data/doc/Time.html +4 -6
  11. data/doc/TrueClass.html +4 -6
  12. data/doc/_index.html +20 -7
  13. data/doc/class_list.html +1 -1
  14. data/doc/file.README.html +32 -30
  15. data/doc/frames.html +1 -1
  16. data/doc/index.html +32 -30
  17. data/doc/method_list.html +34 -2
  18. data/doc/services.md +45 -62
  19. data/doc/top-level-namespace.html +4 -6
  20. data/examples/_blank.rb +2 -2
  21. data/examples/config.rb +23 -0
  22. data/examples/downtimes.rb +4 -33
  23. data/examples/hostgroups.rb +4 -33
  24. data/examples/hosts.rb +18 -33
  25. data/examples/informations.rb +4 -33
  26. data/examples/notifications.rb +4 -33
  27. data/examples/servicegroups.rb +4 -25
  28. data/examples/services.rb +46 -67
  29. data/examples/statistics.rb +4 -33
  30. data/examples/test.rb +7 -28
  31. data/examples/usergroups.rb +4 -33
  32. data/examples/users.rb +4 -33
  33. data/lib/icinga2/client.rb +16 -42
  34. data/lib/icinga2/converts.rb +16 -54
  35. data/lib/icinga2/downtimes.rb +46 -44
  36. data/lib/icinga2/hostgroups.rb +35 -35
  37. data/lib/icinga2/hosts.rb +235 -228
  38. data/lib/icinga2/network.rb +53 -125
  39. data/lib/icinga2/notifications.rb +37 -46
  40. data/lib/icinga2/servicegroups.rb +31 -41
  41. data/lib/icinga2/services.rb +211 -236
  42. data/lib/icinga2/tools.rb +10 -9
  43. data/lib/icinga2/usergroups.rb +22 -32
  44. data/lib/icinga2/users.rb +64 -59
  45. data/lib/icinga2/validator.rb +59 -0
  46. data/lib/icinga2/version.rb +1 -1
  47. metadata +78 -7
  48. data/lib/icinga2/network.rb-SAVE +0 -1004
@@ -9,40 +9,11 @@
9
9
  # -----------------------------------------------------------------------------
10
10
 
11
11
  require_relative '../lib/icinga2'
12
+ require_relative 'config'
12
13
 
13
14
  # -----------------------------------------------------------------------------
14
15
 
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 )
16
+ i = Icinga2::Client.new( @config )
46
17
 
47
18
  unless( i.nil? )
48
19
 
@@ -84,8 +55,8 @@ unless( i.nil? )
84
55
  puts ''
85
56
 
86
57
  rescue => e
87
- $stderr.puts( e )
88
- $stderr.puts( e.backtrace.join("\n") )
58
+ warn( e )
59
+ warn( e.backtrace.join("\n") )
89
60
  end
90
61
  end
91
62
 
@@ -9,40 +9,11 @@
9
9
  # -----------------------------------------------------------------------------
10
10
 
11
11
  require_relative '../lib/icinga2'
12
+ require_relative 'config'
12
13
 
13
14
  # -----------------------------------------------------------------------------
14
15
 
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 )
16
+ i = Icinga2::Client.new( @config )
46
17
 
47
18
  unless( i.nil? )
48
19
 
@@ -98,8 +69,8 @@ unless( i.nil? )
98
69
  puts ''
99
70
 
100
71
  rescue => e
101
- $stderr.puts( e )
102
- $stderr.puts( e.backtrace.join("\n") )
72
+ warn( e )
73
+ warn( e.backtrace.join("\n") )
103
74
  end
104
75
  end
105
76
 
@@ -9,32 +9,11 @@
9
9
  # -----------------------------------------------------------------------------
10
10
 
11
11
  require_relative '../lib/icinga2'
12
+ require_relative 'config'
12
13
 
13
14
  # -----------------------------------------------------------------------------
14
15
 
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
-
22
- config = {
23
- icinga: {
24
- host: icinga_host,
25
- api: {
26
- port: icinga_api_port,
27
- user: icinga_api_user,
28
- password: icinga_api_pass,
29
- pki_path: icinga_api_pki_path,
30
- node_name: icinga_api_node_name
31
- }
32
- }
33
- }
34
-
35
- # ---------------------------------------------------------------------------------------
36
-
37
- i = Icinga2::Client.new( config )
16
+ i = Icinga2::Client.new( @config )
38
17
 
39
18
  unless( i.nil? )
40
19
 
@@ -91,8 +70,8 @@ unless( i.nil? )
91
70
  puts ''
92
71
 
93
72
  rescue => e
94
- $stderr.puts( e )
95
- $stderr.puts( e.backtrace.join("\n") )
73
+ warn( e )
74
+ warn( e.backtrace.join("\n") )
96
75
  end
97
76
  end
98
77
 
@@ -9,40 +9,11 @@
9
9
  # -----------------------------------------------------------------------------
10
10
 
11
11
  require_relative '../lib/icinga2'
12
+ require_relative 'config'
12
13
 
13
14
  # -----------------------------------------------------------------------------
14
15
 
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 )
16
+ i = Icinga2::Client.new( @config )
46
17
 
47
18
  unless( i.nil? )
48
19
 
@@ -63,7 +34,32 @@ unless( i.nil? )
63
34
  puts ''
64
35
 
65
36
  puts '= service objects with \'attrs\' and \'joins\''
66
- puts i.service_objects( attrs: %w[name state], joins: ['host.name','host.state'] )
37
+ puts i.service_objects(
38
+ attrs: %w[name state],
39
+ joins: ['host.name','host.state']
40
+ )
41
+ puts ''
42
+
43
+ puts '= service objects with \'attrs\', \'filter\' and \'joins\''
44
+ puts ' match host.address = 1.2.3.4'
45
+ puts i.service_objects(
46
+ attrs: %w[display_name check_command],
47
+ filter: 'match("1.2.3.4", host.address)',
48
+ joins: ['host.name','host.address']
49
+ )
50
+ puts ''
51
+
52
+ # Get all services in critical state and filter out the ones for which active checks are disabled
53
+ # service.states - 0 = OK, 1 = WARNING, 2 = CRITICAL
54
+ #
55
+ # { "joins": ["host.name", "host.address"], "filter": "service.state==2", "attrs": ["display_name", "check_command", "enable_active_checks"] }
56
+ puts '= service objects with \'attrs\', \'filter\' and \'joins\''
57
+ puts ' filter service.sate == 1'
58
+ puts i.service_objects(
59
+ attrs: %w[display_name check_command enable_active_checks],
60
+ filter: 'service.state == 1' ,
61
+ joins: ['host.name', 'host.address']
62
+ )
67
63
  puts ''
68
64
 
69
65
  puts '= unhandled services'
@@ -118,26 +114,17 @@ unless( i.nil? )
118
114
  puts format( ' - problems and severity: %s', problems_and_severity )
119
115
  puts ''
120
116
 
121
-
122
- puts '= get service Objects'
123
- puts i.service_objects
124
- puts ''
125
-
126
117
  puts '= add service'
127
118
  puts i.add_service(
128
119
  host_name: 'c1-mysql-1',
129
120
  name: 'http2',
121
+ check_command: 'http',
122
+ check_interval: 10,
123
+ retry_interval: 30,
130
124
  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
- }
125
+ http_address: '127.0.0.1',
126
+ http_url: '/access/index',
127
+ http_port: 80
141
128
  }
142
129
  )
143
130
 
@@ -145,32 +132,24 @@ unless( i.nil? )
145
132
  puts i.add_service(
146
133
  host_name: 'c1-mysql-1',
147
134
  name: 'http2',
135
+ check_command: 'http',
136
+ check_interval: 10,
137
+ retry_interval: 30,
148
138
  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
- }
139
+ http_address: '127.0.0.1',
140
+ http_url: '/access/index',
141
+ http_port: 80
159
142
  }
160
143
  )
161
144
 
162
145
  puts '= modify service'
163
146
  puts i.modify_service(
164
147
  name: 'http2',
148
+ check_interval: 60,
149
+ retry_interval: 10,
165
150
  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
- }
151
+ http_url: '/access/login' ,
152
+ http_address: '10.41.80.63'
174
153
  }
175
154
  )
176
155
 
@@ -191,8 +170,8 @@ unless( i.nil? )
191
170
  puts ''
192
171
 
193
172
  rescue => e
194
- $stderr.puts( e )
195
- $stderr.puts( e.backtrace.join("\n") )
173
+ warn( e )
174
+ warn( e.backtrace.join("\n") )
196
175
  end
197
176
  end
198
177
 
@@ -9,40 +9,11 @@
9
9
  # -----------------------------------------------------------------------------
10
10
 
11
11
  require_relative '../lib/icinga2'
12
+ require_relative 'config'
12
13
 
13
14
  # -----------------------------------------------------------------------------
14
15
 
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 )
16
+ i = Icinga2::Client.new( @config )
46
17
 
47
18
  unless( i.nil? )
48
19
 
@@ -125,8 +96,8 @@ unless( i.nil? )
125
96
  puts ''
126
97
 
127
98
  rescue => e
128
- $stderr.puts( e )
129
- $stderr.puts( e.backtrace.join("\n") )
99
+ warn( e )
100
+ warn( e.backtrace.join("\n") )
130
101
  end
131
102
  end
132
103
 
@@ -9,32 +9,11 @@
9
9
  # -----------------------------------------------------------------------------
10
10
 
11
11
  require_relative '../lib/icinga2'
12
+ require_relative 'config'
12
13
 
13
14
  # -----------------------------------------------------------------------------
14
15
 
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
-
22
- config = {
23
- icinga: {
24
- host: icinga_host,
25
- api: {
26
- port: icinga_api_port,
27
- user: icinga_api_user,
28
- password: icinga_api_pass,
29
- pki_path: icinga_api_pki_path,
30
- node_name: icinga_api_node_name
31
- }
32
- }
33
- }
34
-
35
- # ---------------------------------------------------------------------------------------
36
-
37
- i = Icinga2::Client.new( config )
16
+ i = Icinga2::Client.new( @config )
38
17
 
39
18
  unless( i.nil? )
40
19
 
@@ -48,7 +27,7 @@ unless( i.nil? )
48
27
  # Join the output with the hosts on which these checks run (services are applied to hosts)
49
28
  #
50
29
  puts i.service_objects(
51
- attrs: ['display_name', 'check_command'],
30
+ attrs: %w[display_name check_command],
52
31
  filter: 'match("1.2.3.4",host.address)' ,
53
32
  joins: ['host.name', 'host.address']
54
33
  )
@@ -58,20 +37,20 @@ unless( i.nil? )
58
37
  #
59
38
  # { "joins": ['host.name', 'host.address'], "filter": "service.state==2", "attrs": ['display_name', 'check_command', 'enable_active_checks'] }
60
39
  puts i.service_objects(
61
- attrs: ['display_name', 'check_command', 'enable_active_checks'],
40
+ attrs: %w[display_name check_command enable_active_checks],
62
41
  filter: 'service.state==1',
63
42
  joins: ['host.name', 'host.address']
64
43
  )
65
44
  puts ''
66
45
  # Get host name, address of hosts belonging to a specific hostgroup
67
46
  puts i.host_objects(
68
- attrs: ['display_name', 'name', 'address'],
47
+ attrs: %w[display_name name address],
69
48
  filter: '"windows-servers" in host.groups'
70
49
  )
71
50
 
72
51
  rescue => e
73
- $stderr.puts( e )
74
- $stderr.puts( e.backtrace.join("\n") )
52
+ warn( e )
53
+ warn( e.backtrace.join("\n") )
75
54
  end
76
55
  end
77
56
 
@@ -9,40 +9,11 @@
9
9
  # -----------------------------------------------------------------------------
10
10
 
11
11
  require_relative '../lib/icinga2'
12
+ require_relative 'config'
12
13
 
13
14
  # -----------------------------------------------------------------------------
14
15
 
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 )
16
+ i = Icinga2::Client.new( @config )
46
17
 
47
18
  unless( i.nil? )
48
19
 
@@ -84,8 +55,8 @@ unless( i.nil? )
84
55
  puts ''
85
56
 
86
57
  rescue => e
87
- $stderr.puts( e )
88
- $stderr.puts( e.backtrace.join("\n") )
58
+ warn( e )
59
+ warn( e.backtrace.join("\n") )
89
60
  end
90
61
  end
91
62