icinga2 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/Icinga2.html +151 -0
- data/doc/Logging.html +316 -0
- data/doc/_index.html +285 -0
- data/doc/class_list.html +51 -0
- data/doc/file.README.html +278 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +278 -0
- data/doc/method_list.html +523 -0
- data/doc/status.md +12 -0
- data/doc/top-level-namespace.html +110 -0
- data/examples/test.rb +143 -102
- data/lib/icinga2.rb +12 -4
- data/lib/icinga2/converts.rb +8 -8
- data/lib/icinga2/downtimes.rb +34 -14
- data/lib/icinga2/hostgroups.rb +54 -20
- data/lib/icinga2/hosts.rb +126 -65
- data/lib/icinga2/network.rb +44 -3
- data/lib/icinga2/notifications.rb +120 -25
- data/lib/icinga2/servicegroups.rb +44 -10
- data/lib/icinga2/services.rb +100 -51
- data/lib/icinga2/status.rb +16 -10
- data/lib/icinga2/tools.rb +5 -3
- data/lib/icinga2/usergroups.rb +47 -12
- data/lib/icinga2/users.rb +49 -23
- data/lib/icinga2/version.rb +6 -4
- metadata +13 -2
data/lib/icinga2/users.rb
CHANGED
@@ -3,25 +3,34 @@
|
|
3
3
|
|
4
4
|
module Icinga2
|
5
5
|
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# namespace for User handling
|
9
7
|
module Users
|
10
8
|
|
9
|
+
# add a user
|
11
10
|
#
|
11
|
+
# @param [Hash] params
|
12
|
+
# @option params [String] :name user to create
|
13
|
+
# @option params [String] :display_name the displayed name
|
14
|
+
# @option params [String] :email ('') the user email
|
15
|
+
# @option params [String] :pager ('') optional a pager
|
16
|
+
# @option params [Bool] :enable_notifications (false) enable notifications for this user
|
17
|
+
# @option params [Array] :groups ([]) a hash with groups
|
12
18
|
#
|
19
|
+
# @example
|
20
|
+
# @icinga.add_user(name: 'foo', display_name: 'FOO', email: 'foo@bar.com', pager: '0000', groups: ['icingaadmins'])
|
21
|
+
#
|
22
|
+
# @return [Hash] result
|
13
23
|
#
|
14
24
|
def add_user( params = {} )
|
15
25
|
|
16
26
|
name = params.dig(:name)
|
17
|
-
display_name
|
27
|
+
display_name = params.dig(:display_name)
|
18
28
|
email = params.dig(:email)
|
19
29
|
pager = params.dig(:pager)
|
20
30
|
notifications = params.dig(:enable_notifications) || false
|
21
31
|
groups = params.dig(:groups) || []
|
22
32
|
|
23
33
|
if( name.nil? )
|
24
|
-
|
25
34
|
return {
|
26
35
|
status: 404,
|
27
36
|
message: 'missing user name'
|
@@ -29,7 +38,6 @@ module Icinga2
|
|
29
38
|
end
|
30
39
|
|
31
40
|
unless( groups.is_a?( Array ) )
|
32
|
-
|
33
41
|
return {
|
34
42
|
status: 404,
|
35
43
|
message: 'groups must be an array',
|
@@ -51,9 +59,7 @@ module Icinga2
|
|
51
59
|
group_validate = []
|
52
60
|
|
53
61
|
groups.each do |g|
|
54
|
-
|
55
62
|
group_validate << g if exists_usergroup?( g ) == false
|
56
|
-
|
57
63
|
end
|
58
64
|
|
59
65
|
if( group_validate.count != 0 )
|
@@ -61,77 +67,97 @@ module Icinga2
|
|
61
67
|
groups = group_validate.join(', ')
|
62
68
|
|
63
69
|
return {
|
64
|
-
|
65
70
|
status: 404,
|
66
71
|
message: "these groups are not exists: #{groups}",
|
67
72
|
data: params
|
68
73
|
}
|
69
|
-
|
70
74
|
end
|
71
75
|
|
72
|
-
|
76
|
+
Network.put( host: name,
|
73
77
|
url: format( '%s/v1/objects/users/%s', @icinga_api_url_base, name ),
|
74
78
|
headers: @headers,
|
75
79
|
options: @options,
|
76
80
|
payload: payload )
|
77
81
|
|
78
|
-
|
79
|
-
|
82
|
+
# result:
|
83
|
+
# {:status=>200, :name=>nil, :message=>"Object was created"}
|
80
84
|
end
|
81
85
|
|
86
|
+
# delete a user
|
82
87
|
#
|
88
|
+
# @param [Hash] params
|
89
|
+
# @option params [String] :name user to delete
|
83
90
|
#
|
91
|
+
# @example
|
92
|
+
# @icinga.delete_user(name: 'foo')
|
93
|
+
#
|
94
|
+
# @return [Hash] result
|
84
95
|
#
|
85
96
|
def delete_user( params = {} )
|
86
97
|
|
87
98
|
name = params.dig(:name)
|
88
99
|
|
89
100
|
if( name.nil? )
|
90
|
-
|
91
101
|
return {
|
92
102
|
status: 404,
|
93
103
|
message: 'missing user name'
|
94
104
|
}
|
95
105
|
end
|
96
106
|
|
97
|
-
|
107
|
+
Network.delete( host: name,
|
98
108
|
url: format( '%s/v1/objects/users/%s?cascade=1', @icinga_api_url_base, name ),
|
99
109
|
headers: @headers,
|
100
110
|
options: @options )
|
101
111
|
|
102
|
-
|
103
|
-
|
112
|
+
# result:
|
113
|
+
# {:status=>200, :name=>"foo", :message=>"Object was deleted."}
|
104
114
|
end
|
105
115
|
|
116
|
+
# returns all users
|
117
|
+
#
|
118
|
+
# @param [Hash] params
|
119
|
+
# @option params [String] :name ('') optional for a single user
|
106
120
|
#
|
121
|
+
# @example to get all users
|
122
|
+
# @icinga.users
|
107
123
|
#
|
124
|
+
# @example to get one user
|
125
|
+
# @icinga.users(name: 'icingaadmin')
|
126
|
+
#
|
127
|
+
# @return [Hash] returns a hash with all users
|
108
128
|
#
|
109
129
|
def users( params = {} )
|
110
130
|
|
111
131
|
name = params.dig(:name)
|
112
132
|
|
113
|
-
|
133
|
+
Network.get( host: name,
|
114
134
|
url: format( '%s/v1/objects/users/%s', @icinga_api_url_base, name ),
|
115
135
|
headers: @headers,
|
116
136
|
options: @options )
|
117
137
|
|
118
|
-
|
119
|
-
|
138
|
+
# result:
|
139
|
+
# - named user:
|
140
|
+
# {:status=>200, :data=>{"icingaadmin"=>{:name=>"icingaadmin", :display_name=>"Icinga 2 Admin", :type=>"User"}}}
|
141
|
+
# - all users:
|
142
|
+
# {:status=>200, :data=>{"icingaadmin"=>{:name=>"icingaadmin", :display_name=>"Icinga 2 Admin", :type=>"User"}, "foo"=>{:name=>"foo", :display_name=>"FOO", :type=>"User"}}}
|
120
143
|
end
|
121
144
|
|
145
|
+
# returns true if the user exists
|
122
146
|
#
|
147
|
+
# @param [String] name the name of the user
|
123
148
|
#
|
149
|
+
# @example
|
150
|
+
# @icinga.exists_user?('icingaadmin')
|
124
151
|
#
|
152
|
+
# @return [Bool] returns true if the user exists
|
125
153
|
def exists_user?( name )
|
126
154
|
|
127
155
|
result = users( name: name )
|
128
156
|
result = JSON.parse( result ) if result.is_a?( String )
|
129
|
-
status = result.dig(
|
157
|
+
status = result.dig(:status)
|
130
158
|
|
131
159
|
return true if !status.nil? && status == 200
|
132
|
-
|
133
160
|
false
|
134
|
-
|
135
161
|
end
|
136
162
|
|
137
163
|
end
|
data/lib/icinga2/version.rb
CHANGED
@@ -3,17 +3,19 @@
|
|
3
3
|
|
4
4
|
module Icinga2
|
5
5
|
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# namespace for version information
|
9
7
|
module Version
|
10
8
|
|
9
|
+
# major part of version
|
11
10
|
MAJOR = 0
|
11
|
+
# minor part of version
|
12
12
|
MINOR = 6
|
13
|
-
|
13
|
+
# tiny part of version
|
14
|
+
TINY = 2
|
14
15
|
|
15
16
|
end
|
16
17
|
|
18
|
+
# Current version of gem.
|
17
19
|
VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].compact * '.'
|
18
20
|
|
19
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icinga2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bodo Schulz
|
@@ -158,13 +158,24 @@ extra_rdoc_files: []
|
|
158
158
|
files:
|
159
159
|
- LICENSE
|
160
160
|
- README.md
|
161
|
+
- doc/Icinga2.html
|
162
|
+
- doc/Logging.html
|
163
|
+
- doc/_index.html
|
164
|
+
- doc/class_list.html
|
161
165
|
- doc/downtimes.md
|
162
166
|
- doc/examples
|
167
|
+
- doc/file.README.html
|
168
|
+
- doc/file_list.html
|
169
|
+
- doc/frames.html
|
163
170
|
- doc/hostgroups.md
|
164
171
|
- doc/hosts.md
|
172
|
+
- doc/index.html
|
173
|
+
- doc/method_list.html
|
165
174
|
- doc/notifications.md
|
166
175
|
- doc/servicegroups.md
|
167
176
|
- doc/services.md
|
177
|
+
- doc/status.md
|
178
|
+
- doc/top-level-namespace.html
|
168
179
|
- doc/usergroups.md
|
169
180
|
- doc/users.md
|
170
181
|
- examples/test.rb
|
@@ -203,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
214
|
version: '0'
|
204
215
|
requirements: []
|
205
216
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.
|
217
|
+
rubygems_version: 2.5.2
|
207
218
|
signing_key:
|
208
219
|
specification_version: 4
|
209
220
|
summary: Icinga2 API
|