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.
- checksums.yaml +4 -4
- data/README.md +51 -45
- data/doc/hosts.md +62 -21
- data/doc/services.md +215 -54
- data/doc/statistics.md +28 -10
- data/doc/usergroups.md +49 -11
- data/doc/users.md +64 -13
- data/examples/_blank.rb +72 -0
- data/examples/downtimes.rb +79 -0
- data/examples/hostgroups.rb +91 -0
- data/examples/hosts.rb +180 -0
- data/examples/informations.rb +95 -0
- data/examples/notifications.rb +109 -0
- data/examples/servicegroups.rb +102 -0
- data/examples/services.rb +202 -0
- data/examples/statistics.rb +137 -0
- data/examples/test.rb +32 -377
- data/examples/usergroups.rb +95 -0
- data/examples/users.rb +98 -0
- data/lib/icinga2.rb +4 -394
- data/lib/icinga2/client.rb +431 -0
- data/lib/icinga2/downtimes.rb +40 -20
- data/lib/icinga2/hostgroups.rb +38 -22
- data/lib/icinga2/hosts.rb +308 -92
- data/lib/icinga2/network.rb +211 -213
- data/lib/icinga2/notifications.rb +30 -28
- data/lib/icinga2/servicegroups.rb +43 -24
- data/lib/icinga2/services.rb +218 -130
- data/lib/icinga2/statistics.rb +14 -10
- data/lib/icinga2/tools.rb +1 -1
- data/lib/icinga2/usergroups.rb +12 -15
- data/lib/icinga2/users.rb +16 -17
- data/lib/icinga2/version.rb +1 -15
- data/lib/monkey_patches.rb +89 -0
- metadata +21 -8
data/examples/hosts.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# 07.10.2017 - Bodo Schulz
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Examples for Hosts
|
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
|
+
puts ' ==> HOSTS'
|
58
|
+
puts ''
|
59
|
+
|
60
|
+
puts format( '= count of all hosts : %d', i.hosts_all )
|
61
|
+
puts format( '= count_hosts_with_problems: %d', i.count_hosts_with_problems)
|
62
|
+
puts ''
|
63
|
+
|
64
|
+
all, down, critical, unknown, handled, adjusted = i.host_problems.values
|
65
|
+
|
66
|
+
puts '= hosts with problems'
|
67
|
+
puts format( ' - all : %d', all )
|
68
|
+
puts format( ' - down : %d', down )
|
69
|
+
puts format( ' - critical: %d', critical )
|
70
|
+
puts format( ' - unknown : %d', unknown )
|
71
|
+
puts format( ' - handled : %d', handled )
|
72
|
+
puts format( ' - adjusted: %d', adjusted )
|
73
|
+
puts ''
|
74
|
+
|
75
|
+
puts ''
|
76
|
+
['c1-mysql-1', 'bp-foo'].each do |h|
|
77
|
+
|
78
|
+
e = i.exists_host?( h ) ? 'true' : 'false'
|
79
|
+
puts format( '= check if Host \'%s\' exists : %s', h, e )
|
80
|
+
end
|
81
|
+
|
82
|
+
puts ''
|
83
|
+
|
84
|
+
puts '= 5 Hosts with Problem '
|
85
|
+
puts i.list_hosts_with_problems
|
86
|
+
puts ''
|
87
|
+
|
88
|
+
['c1-mysql-1', 'bp-foo'].each do |h|
|
89
|
+
puts format('= list named Hosts \'%s\'', h )
|
90
|
+
puts i.hosts( name: h )
|
91
|
+
puts ''
|
92
|
+
end
|
93
|
+
|
94
|
+
puts ' = add Host \'foo\''
|
95
|
+
|
96
|
+
options = {
|
97
|
+
name: 'foo',
|
98
|
+
address: 'foo.bar.com',
|
99
|
+
display_name: 'test node',
|
100
|
+
max_check_attempts: 5,
|
101
|
+
notes: 'test node',
|
102
|
+
vars: {
|
103
|
+
description: 'spec test',
|
104
|
+
os: 'Docker',
|
105
|
+
partitions: {
|
106
|
+
'/' => {
|
107
|
+
crit: '95%',
|
108
|
+
warn: '90%'
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
puts i.add_host(options)
|
115
|
+
puts ''
|
116
|
+
|
117
|
+
puts ' = add Host \'foo\' (again)'
|
118
|
+
puts i.add_host(options)
|
119
|
+
puts ''
|
120
|
+
|
121
|
+
puts ' = modify Host \'foo\' with merge vars'
|
122
|
+
options = {
|
123
|
+
name: 'foo',
|
124
|
+
display_name: 'test node (changed)',
|
125
|
+
max_check_attempts: 10,
|
126
|
+
notes: 'spec test',
|
127
|
+
vars: {
|
128
|
+
description: 'changed at ...'
|
129
|
+
},
|
130
|
+
merge_vars: true
|
131
|
+
}
|
132
|
+
puts i.modify_host(options)
|
133
|
+
puts ''
|
134
|
+
|
135
|
+
puts ' = modify Host \'foo\' with overwrite vars'
|
136
|
+
options = {
|
137
|
+
name: 'foo',
|
138
|
+
display_name: 'test node (changed)',
|
139
|
+
max_check_attempts: 10,
|
140
|
+
notes: 'spec test',
|
141
|
+
vars: {
|
142
|
+
description: 'change and overwrite vars'
|
143
|
+
}
|
144
|
+
}
|
145
|
+
puts i.modify_host(options)
|
146
|
+
puts ''
|
147
|
+
|
148
|
+
puts ' = delete Host \'test\''
|
149
|
+
puts i.delete_host( name: 'test' )
|
150
|
+
puts ''
|
151
|
+
|
152
|
+
puts ' = delete Host \'foo\''
|
153
|
+
puts i.delete_host( name: 'foo' )
|
154
|
+
puts ''
|
155
|
+
|
156
|
+
puts ' = delete Host \'foo\' (again)'
|
157
|
+
puts i.delete_host( name: 'foo' )
|
158
|
+
puts ''
|
159
|
+
|
160
|
+
puts '= list all Hosts'
|
161
|
+
puts i.hosts
|
162
|
+
puts ''
|
163
|
+
|
164
|
+
puts '= list named Hosts \'c1-mysql-1\''
|
165
|
+
puts i.hosts(name: 'c1-mysql-1')
|
166
|
+
puts ''
|
167
|
+
|
168
|
+
puts ' ------------------------------------------------------------- '
|
169
|
+
puts ''
|
170
|
+
|
171
|
+
rescue => e
|
172
|
+
$stderr.puts( e )
|
173
|
+
$stderr.puts( e.backtrace.join("\n") )
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
# -----------------------------------------------------------------------------
|
179
|
+
|
180
|
+
# EOF
|
@@ -0,0 +1,95 @@
|
|
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
|
+
v, r = i.version.values
|
61
|
+
l, e = i.average_statistics.values
|
62
|
+
puts format( '= version: %s, revision %s', v, r )
|
63
|
+
puts format( '= avg_latency: %s, avg_execution_time %s', l, e )
|
64
|
+
puts format( '= start time: %s', i.start_time )
|
65
|
+
puts format( '= uptime: %s', i.uptime )
|
66
|
+
puts format( '= node name: %s', i.node_name )
|
67
|
+
puts ''
|
68
|
+
|
69
|
+
puts '= icinga2 status'
|
70
|
+
puts i.status_data
|
71
|
+
puts ''
|
72
|
+
|
73
|
+
puts '= icinga2 application data'
|
74
|
+
puts i.application_data
|
75
|
+
puts ''
|
76
|
+
puts '= CIB'
|
77
|
+
puts i.cib_data
|
78
|
+
puts ''
|
79
|
+
puts '= API Listener'
|
80
|
+
puts i.api_listener
|
81
|
+
puts ''
|
82
|
+
|
83
|
+
puts ' ------------------------------------------------------------- '
|
84
|
+
puts ''
|
85
|
+
|
86
|
+
rescue => e
|
87
|
+
$stderr.puts( e )
|
88
|
+
$stderr.puts( e.backtrace.join("\n") )
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
# -----------------------------------------------------------------------------
|
94
|
+
|
95
|
+
# EOF
|
@@ -0,0 +1,109 @@
|
|
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 ' ==> NOTIFICATIONS'
|
59
|
+
puts ''
|
60
|
+
puts '= list all Notifications'
|
61
|
+
puts i.notifications
|
62
|
+
puts ''
|
63
|
+
|
64
|
+
['c1-mysql-1', 'bp-foo'].each do |h|
|
65
|
+
puts format( '= enable Notifications for \'%s\'', h )
|
66
|
+
puts i.enable_host_notification( h )
|
67
|
+
end
|
68
|
+
puts ''
|
69
|
+
|
70
|
+
['c1-mysql-1', 'bp-foo'].each do |h|
|
71
|
+
puts format( '= disable Notifications for \'%s\'', h )
|
72
|
+
puts i.disable_host_notification( h )
|
73
|
+
end
|
74
|
+
puts ''
|
75
|
+
|
76
|
+
['c1-mysql-1', 'bp-foo'].each do |h|
|
77
|
+
puts format( '= enable Notifications for \'%s\' and they services', h )
|
78
|
+
puts i.enable_service_notification( h )
|
79
|
+
end
|
80
|
+
puts ''
|
81
|
+
|
82
|
+
['c1-mysql-1', 'bp-foo'].each do |h|
|
83
|
+
puts format( '= disable Notifications for \'%s\' and they services', h )
|
84
|
+
puts i.disable_service_notification( h )
|
85
|
+
end
|
86
|
+
puts ''
|
87
|
+
|
88
|
+
puts '= enable Notifications for hostgroup'
|
89
|
+
puts i.enable_hostgroup_notification( host_group: 'linux-servers')
|
90
|
+
puts ''
|
91
|
+
|
92
|
+
|
93
|
+
puts '= disable Notifications for hostgroup'
|
94
|
+
puts i.disable_hostgroup_notification( host_group: 'linux-servers')
|
95
|
+
puts ''
|
96
|
+
|
97
|
+
puts ' ------------------------------------------------------------- '
|
98
|
+
puts ''
|
99
|
+
|
100
|
+
rescue => e
|
101
|
+
$stderr.puts( e )
|
102
|
+
$stderr.puts( e.backtrace.join("\n") )
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# -----------------------------------------------------------------------------
|
108
|
+
|
109
|
+
# EOF
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# 07.10.2017 - Bodo Schulz
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Examples for Servicegroups
|
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
|
+
|
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 )
|
38
|
+
|
39
|
+
unless( i.nil? )
|
40
|
+
|
41
|
+
# run tests ...
|
42
|
+
#
|
43
|
+
#
|
44
|
+
|
45
|
+
begin
|
46
|
+
|
47
|
+
puts ' ------------------------------------------------------------- '
|
48
|
+
puts ''
|
49
|
+
|
50
|
+
puts ' ==> SERVICEGROUPS'
|
51
|
+
puts ''
|
52
|
+
|
53
|
+
%w[disk foo].each do |h|
|
54
|
+
|
55
|
+
e = i.exists_servicegroup?( h ) ? 'true' : 'false'
|
56
|
+
puts format( '= check if Servicegroup \'%s\' exists : %s', h, e )
|
57
|
+
end
|
58
|
+
puts ''
|
59
|
+
|
60
|
+
%w[disk foo].each do |h|
|
61
|
+
puts format( '= list named Servicegroup \'%s\':', h )
|
62
|
+
puts i.servicegroups( service_group: h )
|
63
|
+
end
|
64
|
+
puts ''
|
65
|
+
|
66
|
+
puts '= list all Servicegroup'
|
67
|
+
puts i.servicegroups
|
68
|
+
puts ''
|
69
|
+
|
70
|
+
puts '= add Servicegroup \'foo\''
|
71
|
+
puts i.add_servicegroup( service_group: 'foo', display_name: 'FOO' )
|
72
|
+
puts ''
|
73
|
+
|
74
|
+
puts '= add Servicegroup \'foo\' (again)'
|
75
|
+
puts i.add_servicegroup( service_group: 'foo', display_name: 'FOO' )
|
76
|
+
puts ''
|
77
|
+
|
78
|
+
puts '= list named Servicegroup \'foo\''
|
79
|
+
puts i.servicegroups( service_group: 'foo' )
|
80
|
+
puts ''
|
81
|
+
|
82
|
+
puts '= delete Servicegroup \'foo\''
|
83
|
+
puts i.delete_servicegroup( service_group: 'foo' )
|
84
|
+
puts ''
|
85
|
+
|
86
|
+
puts '= delete Servicegroup \'foo\' (again)'
|
87
|
+
puts i.delete_servicegroup( service_group: 'foo' )
|
88
|
+
puts ''
|
89
|
+
|
90
|
+
puts ' ------------------------------------------------------------- '
|
91
|
+
puts ''
|
92
|
+
|
93
|
+
rescue => e
|
94
|
+
$stderr.puts( e )
|
95
|
+
$stderr.puts( e.backtrace.join("\n") )
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# -----------------------------------------------------------------------------
|
101
|
+
|
102
|
+
# EOF
|