class Dashingstate
Public Class Methods
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
# File lib/Dashingstate.rb, line 341 def Dashingstate.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
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]
# File lib/Dashingstate.rb, line 309 def Dashingstate.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
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]
# File lib/Dashingstate.rb, line 271 def Dashingstate.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
Private Class Methods
Args:¶ ↑
list
-
array which should be sorted
Description:¶ ↑
Sorts a array (DESC)
Return:¶ ↑
list
-
Sorted array
# File lib/Dashingstate.rb, line 50 def Dashingstate.bubble(list) return list if list.size <= 1 # already sorted swapped = true while swapped do swapped = false 0.upto(list.size-2) do |i| if list[i] > list[i+1] list[i], list[i+1] = list[i+1], list[i] # swap values swapped = true end end end list end
Args:¶ ↑
value
-
A value which should convert
# File lib/Dashingstate.rb, line 132 def Dashingstate.casestate(value,type) if type == "s" erg = case value when "0;0" then 0 when "3;1" then 1 when "1;1" then 2 when "2;1" then 3 when "3;0" then 4 when "1;0" then 5 when "2;0" then 6 end elsif type == "h" erg = case value when "0;0" then 0 when "1;1" then 3 when "1;0" then 6 end end return erg end
Args:¶ ↑
state
-
status, which schould be converted to numeric [string]
Description:¶ ↑
Converts a named status to a numeric status
Return:¶ ↑
conv
-
Returns the nummeric status
# File lib/Dashingstate.rb, line 166 def Dashingstate.convback(state) conv = case state when "normal" then 0 when "unknownack" then 1 when "warningack" then 2 when "criticalack" then 3 when "unknown" then 4 when "warning" then 5 when "critical","danger" then 6 end return conv end
Args:¶ ↑
name
-
Name in icinga
# File lib/Dashingstate.rb, line 98 def Dashingstate.get(name,qa) erg = case qa when "ssh" then `python /root/status.py services 'state acknowledged' 'host_name = #{name}'`.gsub!("\n\n","").split("\n") when "hsh" then `python /root/status.py hosts 'state acknowledged' 'host_name = #{name}'`.gsub!("\n\n","") when "hs" then `python /root/status.py #{name}`.gsub!("\n\n","") when "ssd" then `python /root/status.py services 'state acknowledged' 'display_name = #{name}'`.gsub!("\n\n","") end if qa == "ssh" then i = 0 erg.each do |item| erg[i] = casestate(item,qa[0]) i += 1 end erg = bubble(erg)[-1] else erg = casestate(erg,qa[0]) end end
Args:¶ ↑
groupname
-
Name of the groupobject
Description:¶ ↑
Gets the status of all hosts in a hostgroup
Return:¶ ↑
res
-
Returns a status of all hosts
# File lib/Dashingstate.rb, line 191 def Dashingstate.getgroup(groupname) res = hgm(groupname) i = 0 res.each do |item| res[i] = get(item, "hsh") i += 1 end res = bubble(res)[-1] return res end
Args:¶ ↑
groupname
-
Name of the groupobject
Description:¶ ↑
Gets the status of all hosts in a hostgroup and its services
Return:¶ ↑
res
-
Returns a stati of all hosts and services
# File lib/Dashingstate.rb, line 214 def Dashingstate.groupservices(groupname) member = hgm(groupname) i = 0 res = [] member.each do |item| res[i] = get(item, "ssh") i += 1 end res = bubble(res)[-1] return res end
Args:¶ ↑
hostgroup
-
Objectname of the hostgroup in icinga
Description:¶ ↑
Gets all groupmember
Return:¶ ↑
erg
-
Returns all groupmember [array]
# File lib/Dashingstate.rb, line 78 def Dashingstate.hgm(hostgroup) erg = `python /root/status.py hostgroups members 'name = #{hostgroup}'`.gsub!("\n\n","").split(",") return erg end
Args:¶ ↑
list
-
Array with stati
Description:¶ ↑
Puts a totalstatus of a array
Return:¶ ↑
status
-
Returns a totalstatus of a array
# File lib/Dashingstate.rb, line 15 def Dashingstate.stateall(list) i = 0 list.each do |item| if item.class.to_s != "Array" list[i] = list[i].to_i else list[i] = list[i][1].to_i end i += 1 end sorted = bubble(list) i = 0 sorted = case sorted[-1] when 0 then "normal" when 1 then "unknownack" when 2 then "warningack" when 3 then "criticalack" when 4 then "unknown" when 5 then "warning" when 6 then "danger" end return sorted end