Module: DashingContrib::Jobs::PingdomUptime

Extended by:
RunnableJob
Defined in:
lib/dashing-contrib/jobs/pingdom_uptime.rb

Constant Summary

Constants included from RunnableJob

RunnableJob::CRITICAL, RunnableJob::OK, RunnableJob::WARNING

Class Method Summary collapse

Methods included from RunnableJob

metrics, run, validate_state

Class Method Details

.metrics(options) ⇒ Object



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
# File 'lib/dashing-contrib/jobs/pingdom_uptime.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]
  )

  user_opt = self.default_date_ranges.merge(options)

  id = user_opt[:check_id]
  current_uptime = client.uptime(id, user_opt[:default_date_range], user_opt[:now])
  first_uptime   = client.uptime(id, user_opt[:first_date_range], user_opt[:now])
  second_uptime  = client.uptime(id, user_opt[:second_date_range], user_opt[:now])
  status   = client.checks(id)

  if status[:check][:lasterrortime].nil?
    last_down = "never"
  else
    last_down = ::DashingContrib::Time.readable_diff(::Time.at(status[:check][:lasterrortime]))
  end

  # returns this dataset
  {
    current: current_uptime.to_s,
    first:  first_uptime.to_s,
    first_title: user_opt[:first_title],
    second: second_uptime.to_s,
    second_title: user_opt[:second_title],
    is_up: status[:check][:status] == 'up',
    current_response_time: status[:check][:lastresponsetime],
    last_downtime: last_down
  }
end

.validate_state(metrics, options = {}) ⇒ Object



43
44
45
46
# File 'lib/dashing-contrib/jobs/pingdom_uptime.rb', line 43

def self.validate_state(metrics, options = {})
  return DashingContrib::RunnableJob::OK if metrics[:is_up]
  DashingContrib::RunnableJob::CRITICAL
end