icinga-dashing 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/icinga-dashing.rb +5 -0
- data/lib/icinga-dashing/socket.rb +36 -0
- data/lib/icinga-dashing/status.rb +388 -0
- metadata +51 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
module IcingaDashing
|
2
|
+
class Socket
|
3
|
+
require 'socket'
|
4
|
+
hostname="icinga01.lklg.net"
|
5
|
+
port=6557
|
6
|
+
|
7
|
+
def socket_initialize(hostname,port)
|
8
|
+
return TCPSocket.open(hostname,port)
|
9
|
+
end
|
10
|
+
|
11
|
+
def socket_close(s)
|
12
|
+
s.shutdown(:WR)
|
13
|
+
answer = s.read
|
14
|
+
s.close
|
15
|
+
return answer
|
16
|
+
end
|
17
|
+
|
18
|
+
def getdevices(type,columns,filters)
|
19
|
+
s = socket_initialize
|
20
|
+
s.send "GET #{type}\n", 0
|
21
|
+
s.send "Columns: #{columns}\n", 0
|
22
|
+
s.send "Filter: #{filters}\n", 0
|
23
|
+
s.send "OutputFormat: csv\n", 0
|
24
|
+
answer = socket_close(s)
|
25
|
+
end
|
26
|
+
|
27
|
+
def getstate(hostname)
|
28
|
+
s = socket_initialize
|
29
|
+
s.send "GET hosts\n", 0
|
30
|
+
s.send "Columns: state acknowledged\n", 0
|
31
|
+
s.send "Filter: name = #{hostname}\n", 0
|
32
|
+
s.send "OutputFormat: csv\n", 0
|
33
|
+
answer = socket_close(s)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,388 @@
|
|
1
|
+
module IcingaDashing
|
2
|
+
class Status
|
3
|
+
private
|
4
|
+
#
|
5
|
+
# === Args:
|
6
|
+
# +list+::
|
7
|
+
# Array with stati
|
8
|
+
#
|
9
|
+
# === Description:
|
10
|
+
# Puts a totalstatus of a array
|
11
|
+
#
|
12
|
+
# === Return:
|
13
|
+
# +status+::
|
14
|
+
# Returns a totalstatus of a array
|
15
|
+
#
|
16
|
+
def Status.stateall(list)
|
17
|
+
i = 0
|
18
|
+
list.each do |item|
|
19
|
+
if item.class.to_s != "Array"
|
20
|
+
list[i] = list[i].to_i
|
21
|
+
else
|
22
|
+
list[i] = list[i][1].to_i
|
23
|
+
end
|
24
|
+
i += 1
|
25
|
+
end
|
26
|
+
sorted = bubble(list)
|
27
|
+
i = 0
|
28
|
+
sorted = case sorted[-1]
|
29
|
+
when 0 then "normal"
|
30
|
+
when 1 then "unknownack"
|
31
|
+
when 2 then "warningack"
|
32
|
+
when 3 then "criticalack"
|
33
|
+
when 4 then "unknown"
|
34
|
+
when 5 then "warning"
|
35
|
+
when 6 then "danger"
|
36
|
+
end
|
37
|
+
return sorted
|
38
|
+
end
|
39
|
+
#
|
40
|
+
# === Args:
|
41
|
+
# +list+::
|
42
|
+
# array which should be sorted
|
43
|
+
#
|
44
|
+
# === Description:
|
45
|
+
# Sorts a array (DESC)
|
46
|
+
#
|
47
|
+
# === Return:
|
48
|
+
# +list+::
|
49
|
+
# Sorted array
|
50
|
+
#
|
51
|
+
def Status.bubble(list)
|
52
|
+
return list if list.size <= 1 # already sorted
|
53
|
+
swapped = true
|
54
|
+
while swapped do
|
55
|
+
swapped = false
|
56
|
+
0.upto(list.size-2) do |i|
|
57
|
+
if list[i] > list[i+1]
|
58
|
+
list[i], list[i+1] = list[i+1], list[i] # swap values
|
59
|
+
swapped = true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
list
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# === Args:
|
68
|
+
# +hostgroup+::
|
69
|
+
# Objectname of the hostgroup in icinga
|
70
|
+
#
|
71
|
+
# === Description:
|
72
|
+
# Gets all groupmember
|
73
|
+
#
|
74
|
+
# === Return:
|
75
|
+
# +erg+::
|
76
|
+
# Returns all groupmember [array]
|
77
|
+
#
|
78
|
+
|
79
|
+
def Status.hgm(hostgroup)
|
80
|
+
erg = `python /root/status.py hostgroups members 'name = #{hostgroup}'`.gsub!("\n\n","").split(",")
|
81
|
+
return erg
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# === Args:
|
86
|
+
# +name+::
|
87
|
+
# Name in icinga
|
88
|
+
# +qa+::
|
89
|
+
# type of the object (Hostgroup, Service, Host)
|
90
|
+
#
|
91
|
+
# === Description:
|
92
|
+
# Gets the data from the icinga host
|
93
|
+
#
|
94
|
+
# === Return:
|
95
|
+
# +erg+::
|
96
|
+
# Returns a status and the "acknowledgment"
|
97
|
+
#
|
98
|
+
|
99
|
+
def Status.get(name,qa)
|
100
|
+
erg = case qa
|
101
|
+
when "ssh" then `python /root/status.py services 'state acknowledged' 'host_name = #{name}'`.gsub!("\n\n","").split("\n")
|
102
|
+
when "hsh" then `python /root/status.py hosts 'state acknowledged' 'host_name = #{name}'`.gsub!("\n\n","")
|
103
|
+
when "hs" then `python /root/status.py #{name}`.gsub!("\n\n","")
|
104
|
+
when "ssd" then `python /root/status.py services 'state acknowledged' 'display_name = #{name}'`.gsub!("\n\n","")
|
105
|
+
end
|
106
|
+
if qa == "ssh" then
|
107
|
+
i = 0
|
108
|
+
erg.each do |item|
|
109
|
+
erg[i] = casestate(item,qa[0])
|
110
|
+
i += 1
|
111
|
+
end
|
112
|
+
erg = bubble(erg)[-1]
|
113
|
+
else
|
114
|
+
erg = casestate(erg,qa[0])
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# === Args:
|
120
|
+
# +value+::
|
121
|
+
# A value which should convert
|
122
|
+
# +type+::
|
123
|
+
# (s)ervice | (h)ost
|
124
|
+
#
|
125
|
+
# === Description:
|
126
|
+
# convert a status + "acknowledged" in a dashing-readable format
|
127
|
+
#
|
128
|
+
# === Return:
|
129
|
+
# +erg+::
|
130
|
+
# Returns the status
|
131
|
+
#
|
132
|
+
|
133
|
+
def Status.casestate(value,type)
|
134
|
+
if type == "s"
|
135
|
+
erg = case value
|
136
|
+
when "0;0" then 0
|
137
|
+
when "3;1" then 1
|
138
|
+
when "1;1" then 2
|
139
|
+
when "2;1" then 3
|
140
|
+
when "3;0" then 4
|
141
|
+
when "1;0" then 5
|
142
|
+
when "2;0" then 6
|
143
|
+
end
|
144
|
+
elsif type == "h"
|
145
|
+
erg = case value
|
146
|
+
when "0;0" then 0
|
147
|
+
when "1;1" then 3
|
148
|
+
when "1;0" then 6
|
149
|
+
end
|
150
|
+
end
|
151
|
+
return erg
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
#
|
156
|
+
# === Args:
|
157
|
+
# +state+::
|
158
|
+
# status, which schould be converted to numeric [string]
|
159
|
+
#
|
160
|
+
# === Description:
|
161
|
+
# Converts a named status to a numeric status
|
162
|
+
#
|
163
|
+
# === Return:
|
164
|
+
# +conv+::
|
165
|
+
# Returns the nummeric status
|
166
|
+
|
167
|
+
def Status.convback(state)
|
168
|
+
conv = case state
|
169
|
+
when "normal" then 0
|
170
|
+
when "unknownack" then 1
|
171
|
+
when "warningack" then 2
|
172
|
+
when "criticalack" then 3
|
173
|
+
when "unknown" then 4
|
174
|
+
when "warning" then 5
|
175
|
+
when "critical","danger" then 6
|
176
|
+
end
|
177
|
+
return conv
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# === Args:
|
182
|
+
# +groupname+::
|
183
|
+
# Name of the groupobject
|
184
|
+
#
|
185
|
+
# === Description:
|
186
|
+
# Gets the status of all hosts in a hostgroup
|
187
|
+
#
|
188
|
+
# === Return:
|
189
|
+
# +res+::
|
190
|
+
# Returns a status of all hosts
|
191
|
+
|
192
|
+
def Status.getgroup(groupname)
|
193
|
+
res = hgm(groupname)
|
194
|
+
i = 0
|
195
|
+
res.each do |item|
|
196
|
+
res[i] = get(item, "hsh")
|
197
|
+
i += 1
|
198
|
+
end
|
199
|
+
res = bubble(res)[-1]
|
200
|
+
return res
|
201
|
+
end
|
202
|
+
|
203
|
+
#
|
204
|
+
# === Args:
|
205
|
+
# +groupname+::
|
206
|
+
# Name of the groupobject
|
207
|
+
#
|
208
|
+
# === Description:
|
209
|
+
# Gets the status of all hosts in a hostgroup and its services
|
210
|
+
#
|
211
|
+
# === Return:
|
212
|
+
# +res+::
|
213
|
+
# Returns a stati of all hosts and services
|
214
|
+
|
215
|
+
def Status.groupservices(groupname)
|
216
|
+
member = hgm(groupname)
|
217
|
+
i = 0
|
218
|
+
res = []
|
219
|
+
member.each do |item|
|
220
|
+
res[i] = get(item, "ssh")
|
221
|
+
i += 1
|
222
|
+
end
|
223
|
+
res = bubble(res)[-1]
|
224
|
+
return res
|
225
|
+
end
|
226
|
+
|
227
|
+
#
|
228
|
+
# === Args:
|
229
|
+
# +pages+::
|
230
|
+
# printed pages [integer or array of integers]
|
231
|
+
#
|
232
|
+
# === Description:
|
233
|
+
# add up the printed pages
|
234
|
+
#
|
235
|
+
# === Return:
|
236
|
+
# +total+::
|
237
|
+
# Returns the total printed pages with a ahousands separator
|
238
|
+
#
|
239
|
+
=begin
|
240
|
+
def Status.countpages(pages)
|
241
|
+
if pages.class.to_s == "array"
|
242
|
+
pages.each do |item|
|
243
|
+
total += item
|
244
|
+
end
|
245
|
+
else
|
246
|
+
total = pages
|
247
|
+
end
|
248
|
+
if total > 10000
|
249
|
+
total = total.to_s.insert(2,".")
|
250
|
+
elsif total > 1000
|
251
|
+
total = total.to_s.insert(1,".")
|
252
|
+
end
|
253
|
+
return total
|
254
|
+
end
|
255
|
+
=end
|
256
|
+
public
|
257
|
+
#
|
258
|
+
#
|
259
|
+
# === Args:
|
260
|
+
# +labels+::
|
261
|
+
# the Labels [array]
|
262
|
+
# +values+::
|
263
|
+
# host- or service-states [array]
|
264
|
+
#
|
265
|
+
# === Description:
|
266
|
+
# Prepare the host- and service-states
|
267
|
+
#
|
268
|
+
# === Return:
|
269
|
+
# Returns a multidimensional array. Ready to push this to the dashboard [array]
|
270
|
+
#
|
271
|
+
|
272
|
+
def Status.prepare(labels, values)
|
273
|
+
status = []
|
274
|
+
i = 0
|
275
|
+
values.each do |item|
|
276
|
+
item = case item
|
277
|
+
when 0 then "<i class='icon-ok'></i>"
|
278
|
+
when 1,2,3 then "<i class='icon-cog icon-spin'></i>"
|
279
|
+
when 5 then "<i class='icon-warning-sign'></i>"
|
280
|
+
when 4 then "<i class='icon-question-sign'></i>"
|
281
|
+
when 6 then "<i class='icon-remove'></i>"
|
282
|
+
end
|
283
|
+
status[i] = {label: labels[i], value: item}
|
284
|
+
i +=1
|
285
|
+
end
|
286
|
+
totalstate = stateall(values)
|
287
|
+
status.push(totalstate)
|
288
|
+
return status
|
289
|
+
end
|
290
|
+
|
291
|
+
#
|
292
|
+
#
|
293
|
+
# === Args:
|
294
|
+
# +list+::
|
295
|
+
# The old tile [array]
|
296
|
+
# +label+::
|
297
|
+
# Label of the new value [string]
|
298
|
+
# +value+::
|
299
|
+
# The value with the state [array]
|
300
|
+
# +position+::
|
301
|
+
# Position at the tile [integer]
|
302
|
+
#
|
303
|
+
# === Description:
|
304
|
+
# Adds an object to a tile, which should not display by a icon
|
305
|
+
#
|
306
|
+
# === Return:
|
307
|
+
# Returns the new tile (already prepared) [array]
|
308
|
+
#
|
309
|
+
|
310
|
+
def Status.inject(list,label,value,position)
|
311
|
+
lnew = list
|
312
|
+
oldstate = list[-1]
|
313
|
+
newstate = casestate(value[1],"s")
|
314
|
+
oldstate = convback(oldstate)
|
315
|
+
gesstate = [oldstate.to_i, newstate.to_i]
|
316
|
+
gesstate = stateall(gesstate)
|
317
|
+
lnew.insert(position, {label: label, value: value[0]})
|
318
|
+
lnew.delete(list[-1])
|
319
|
+
lnew << gesstate
|
320
|
+
end
|
321
|
+
|
322
|
+
|
323
|
+
#
|
324
|
+
#
|
325
|
+
# === Args:
|
326
|
+
# +name+::
|
327
|
+
# The name of the object [string]
|
328
|
+
# +type+::
|
329
|
+
# type of the object (service or host) [string]
|
330
|
+
# +group+::
|
331
|
+
# true, if the object is a host- or servicegroup [boolean]
|
332
|
+
# +etc+::
|
333
|
+
# additional object which schould be added to the group [array]
|
334
|
+
#
|
335
|
+
# === Description:
|
336
|
+
# Gets the host- and servicestate
|
337
|
+
#
|
338
|
+
# === Return:
|
339
|
+
# Returns the state of a host, service or a group
|
340
|
+
#
|
341
|
+
|
342
|
+
def Status.getstate(name, type, group=false, etc=nil)
|
343
|
+
if group && type == "service"
|
344
|
+
res = groupservices(name)
|
345
|
+
elsif group
|
346
|
+
res = getgroup(name)
|
347
|
+
elsif type == "service"
|
348
|
+
res = get(name, "ssd")
|
349
|
+
elsif type == "servicehost"
|
350
|
+
res = get(name, "ssh")
|
351
|
+
elsif type == "host"
|
352
|
+
res = get(name, "hs")
|
353
|
+
end
|
354
|
+
return res
|
355
|
+
end
|
356
|
+
|
357
|
+
#
|
358
|
+
# === Args:
|
359
|
+
# +spoolserver+::
|
360
|
+
# Objectname(s) from the spoolserver (one or more) [string or array]
|
361
|
+
#
|
362
|
+
# === Description:
|
363
|
+
# Gets the today total printed pages from one or more spoolserver
|
364
|
+
#
|
365
|
+
# === Return:
|
366
|
+
# Returns the today total printed pages [string]
|
367
|
+
#
|
368
|
+
=begin
|
369
|
+
def Status.totalpages(spoolserver)
|
370
|
+
if spoolserver.class.to_s == "array"
|
371
|
+
pages = []
|
372
|
+
i = 0
|
373
|
+
spoolserver.each do |item|
|
374
|
+
res = `python /root/status.py services perf_data 'host_name = #{item}'`.gsub!("\n\n","").split(";")
|
375
|
+
pages[i] = res[9].split(/TotalPagesPrinted'=(.*)/).to_i
|
376
|
+
i += 1
|
377
|
+
end
|
378
|
+
else
|
379
|
+
res = `python /root/status.py services perf_data 'host_name = #{spoolserver}'`.gsub!("\n\n","").split(";")
|
380
|
+
pages = res[9].split(/TotalPagesPrinted'=(.*)/)
|
381
|
+
pages.to_i
|
382
|
+
end
|
383
|
+
total = countpages(pages)
|
384
|
+
return total
|
385
|
+
end
|
386
|
+
=end
|
387
|
+
end
|
388
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: icinga-dashing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.5'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Landkreis Lüneburg - IT-Service
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A Gem to get host- or servicestates from icinga to dashing
|
15
|
+
email: ''
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/icinga-dashing.rb
|
21
|
+
- lib/icinga-dashing/socket.rb
|
22
|
+
- lib/icinga-dashing/status.rb
|
23
|
+
homepage: http://landkreis-lueneburg.de
|
24
|
+
licenses:
|
25
|
+
- Data licence Germany âttribution âersion 1.0
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements:
|
43
|
+
- You need mk_livestatus to use Status!
|
44
|
+
- http://mathias-kettner.de/checkmk_livestatus.html
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 1.8.23
|
47
|
+
signing_key:
|
48
|
+
specification_version: 3
|
49
|
+
summary: icinga-dashing
|
50
|
+
test_files: []
|
51
|
+
has_rdoc:
|