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