Module: RunscopeStatuspage

Defined in:
lib/runscope_statuspage.rb,
lib/runscope_statuspage/version.rb,
lib/runscope_statuspage/exceptions.rb,
lib/runscope_statuspage/runscope_api.rb,
lib/runscope_statuspage/statuspage_api.rb

Defined Under Namespace

Classes: RequestFailedException, RunscopeAPI, RunscopeAPIException, StatuspageAPI, StatuspageAPIException, UserInputException

Constant Summary collapse

VERSION =
"0.1.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.msgObject

Returns the value of attribute msg.



8
9
10
# File 'lib/runscope_statuspage.rb', line 8

def msg
  @msg
end

.nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/runscope_statuspage.rb', line 8

def name
  @name
end

.rs_keyObject

Returns the value of attribute rs_key.



8
9
10
# File 'lib/runscope_statuspage.rb', line 8

def rs_key
  @rs_key
end

.sp_keyObject

Returns the value of attribute sp_key.



8
9
10
# File 'lib/runscope_statuspage.rb', line 8

def sp_key
  @sp_key
end

.sp_pageObject

Returns the value of attribute sp_page.



8
9
10
# File 'lib/runscope_statuspage.rb', line 8

def sp_page
  @sp_page
end

Class Method Details

.parameterize(radar) ⇒ Object

Splice radar hash values from keys defined in



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/runscope_statuspage.rb', line 29

def self.parameterize(radar)
  rname = @name
  rmsg = @msg

  @name.scan(/.*?(\/)([A-Za-z]*)(\/)/).each do |set|
    set.each do |token|
      if radar.has_key?(token)
        rname = rname.sub!("/#{token}/", radar[token]) unless (token == "/" and token.length == 1)
      end
    end
  end

  @msg.scan(/.*?(\/)([A-Za-z]*)(\/)/).each do |set|
    set.each do |token|
      if radar.has_key?(token)
        rmsg = rmsg.sub!("/#{token}/", radar[token]) unless (token == "/" and token.length == 1)
      end
    end
  end

  return rname, rmsg
end

.reinit_restObject

As the user may decide (for whatever reason) to change API keys after one request, we re-initialize these objects.



22
23
24
25
# File 'lib/runscope_statuspage.rb', line 22

def self.reinit_rest
  @rs = RunscopeAPI.new(@rs_key)
  @sp = StatuspageAPI.new(@sp_key)
end

.report_bucket(bucket_name, status, twitter_update) ⇒ Object

Update status page with all radars under passed bucket name.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/runscope_statuspage.rb', line 100

def self.report_bucket(bucket_name, status, twitter_update)
  reinit_rest

  @rs.buckets.each do |bucket|
    if bucket['name'] == bucket_name
      @rs.radars(bucket['key']).each do |radar|
        if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass'
          @sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([status, twitter_update]))
        end
      end
    end
  end

end

.report_buckets(bucket_names, status, twitter_update) ⇒ Object

Update status page with all radars under the specified buckets



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/runscope_statuspage.rb', line 117

def self.report_buckets(bucket_names, status, twitter_update)
  reinit_rest

  @rs.buckets.each do |bucket|
    if bucket_names.include?(bucket['name'])
      @rs.radars(bucket['key']).each do |radar|
        if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass'
          @sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([status, twitter_update]))
        end
      end
    end
  end

end

.report_everything(page, status, twitter_update) ⇒ Object

Update status page with all radars, from all buckets. An error will most likely be thrown if you have empty buckets.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/runscope_statuspage.rb', line 54

def self.report_everything(page, status, twitter_update)
  reinit_rest

  @rs.buckets.each do |bucket|
    @rs.radars(bucket['key']).each do |radar|
      if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass'
        @sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([status, twitter_update]))
      end
    end
  end
end

.report_radar(bucket_name, radar_name, status, twitter_update) ⇒ Object

Update status page with one radar, from one bucket.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/runscope_statuspage.rb', line 67

def self.report_radar(bucket_name, radar_name, status, twitter_update)
  reinit_rest

  @rs.buckets.each do |bucket|
    if bucket['name'] == bucket_name
      @rs.radars(bucket['key']).each do |radar|
        if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass' and radar['name'] == radar_name
          @sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([status, twitter_update]))
        end
      end
    end
  end

end

.report_radars(bucket_name, radar_names, status, twitter_update) ⇒ Object

Update status page with list of radars, from one bucket.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/runscope_statuspage.rb', line 83

def self.report_radars(bucket_name, radar_names, status, twitter_update)
  reinit_rest

  @rs.buckets.each do |bucket|
    if bucket['name'] == bucket_name
      @rs.radars(bucket['key']).each do |radar|
        if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass' and radar_names.include?(radar['name'])
          @sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([status, twitter_update]))
        end
      end
    end
  end

end