8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/dashing-contrib/jobs/pingdom_summary.rb', line 8
def self.metrics(options)
client = DashingContrib::Pingdom::Client.new(
username: options[:username],
password: options[:password],
api_key: options[:api_key],
team_account: options[:team_account]
)
status = client.summary()
sum_status = 'ok'
sum_total = status["up"][:value] +
status["paused"][:value] +
status["unconfirmed_down"][:value] +
status["down"][:value] +
status["unknown"][:value]
sum_ok = status["up"][:value] + status["paused"][:value]
sum_warn = status["unknown"][:value]
sum_crit = status["down"][:value] + status["unconfirmed_down"][:value]
sum_status = 'warning' if sum_warn > 0
sum_status = 'critical' if sum_crit > 0
tofind = options[:list_top] || 3
list = Array.new
stateMap = { 'up' => 'ok',
'paused' => 'warning',
'unknown' => 'warning',
'down' => 'critical',
'unconfirmed_down' => 'critical' }
repStates = ["down","unconfirmed_down","unknown","paused"]
repStates.insert(-1, "up") if options[:include_up] || false
repStates.each { |state|
if tofind > 0
touse = status[state][:checks].keys.sort.take(tofind)
tofind = tofind - touse.size
touse.each { |key|
list.concat( [ { state: stateMap[state], label: status[state][:checks][key] } ] )
}
end
}
{
status: sum_status,
total: sum_total,
ok: sum_ok,
error: sum_crit,
up: status["up"][:value],
down: status["down"][:value],
unknown: status["unknown"][:value],
paused: status["paused"][:value],
unconfirmed_down: status["unconfirmed_down"][:value],
items: list,
}
end
|