Class: IcingaDashing::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/icinga-dashing/status.rb

Class Method Summary collapse

Class Method Details

.getstate(name, type, group = false, etc = nil) ⇒ Object

Args:

name

The name of the object [string]

type

type of the object (service or host) [string]

group

true, if the object is a host- or servicegroup [boolean]

etc

additional object which schould be added to the group [array]

Description:

Gets the host- and servicestate

Return:

Returns the state of a host, service or a group



342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/icinga-dashing/status.rb', line 342

def Status.getstate(name, type, group=false, etc=nil)
  if group && type == "service"
    res = groupservices(name)
  elsif group
    res = getgroup(name)
  elsif type == "service"
    res = get(name, "ssd")
  elsif type == "servicehost"
    res = get(name, "ssh")
  elsif type == "host"
    res = get(name, "hs")
  end
  return res
end

.inject(list, label, value, position) ⇒ Object

Args:

list

The old tile [array]

label

Label of the new value [string]

value

The value with the state [array]

position

Position at the tile [integer]

Description:

Adds an object to a tile, which should not display by a icon

Return:

Returns the new tile (already prepared) [array]



310
311
312
313
314
315
316
317
318
319
320
# File 'lib/icinga-dashing/status.rb', line 310

def Status.inject(list,label,value,position)
  lnew = list
  oldstate = list[-1]
  newstate = casestate(value[1],"s")
  oldstate = convback(oldstate)
  gesstate = [oldstate.to_i, newstate.to_i]
  gesstate = stateall(gesstate)
  lnew.insert(position, {label: label, value: value[0]})
  lnew.delete(list[-1])
  lnew << gesstate
end

.prepare(labels, values) ⇒ Object

Args:

labels

the Labels [array]

values

host- or service-states [array]

Description:

Prepare the host- and service-states

Return:

Returns a multidimensional array. Ready to push this to the dashboard [array]



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/icinga-dashing/status.rb', line 272

def Status.prepare(labels, values)
  status = []
  i = 0
  values.each do |item|
    item = case item
      when 0 then "<i class='icon-ok'></i>"
      when 1,2,3 then "<i class='icon-cog icon-spin'></i>"
 when 5 then "<i class='icon-warning-sign'></i>"
    when 4 then "<i class='icon-question-sign'></i>"
    when 6 then "<i class='icon-remove'></i>"
    end
    status[i] = {label: labels[i], value: item}
    i +=1
  end
  totalstate = stateall(values)
  status.push(totalstate)
  return status
end