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: MissingArgumentException, RunscopeAPI, RunscopeAPIException, StatuspageAPI, StatuspageAPIException

Constant Summary collapse

VERSION =
'0.1.4'

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

.rsObject

Returns the value of attribute rs.



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

def rs
  @rs
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

.spObject

Returns the value of attribute sp.



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

def sp
  @sp
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



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

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.



20
21
22
23
# File 'lib/runscope_statuspage.rb', line 20

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

.report_bucket(opts = {}) ⇒ Object

Update status page with all radars under passed bucket name.

Parameters: => name of bucket containing radars,

:status => page status (either 'investigating|identified|monitoring|resolved'),
:twitter_update => do you want to post status to twitter (bool),
:fail_on => number of failures to induce statuspage update (int, default 0)

Raises:



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/runscope_statuspage.rb', line 167

def self.report_bucket(opts={})
  raise MissingArgumentException.new, 'report_bucket is missing arguments' \
    if not (opts.key?(:status) or opts.key?(:twitter_update) \
    or opts.key?(:bucket_name))

  opts[:fail_on] = opts.key?(:fail_on) ? opts[:fail_on] : 0
  failed_radars = []

  reinit_rest
  @rs.buckets.each do |bucket|
    if bucket['name'] == opts[:bucket_name]
      @rs.radars(bucket['key']).each do |radar|
        begin
          if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass'
            failed_radars.push radar
          end
        rescue RunscopeAPIException => r
          p r
          next
        end
      end
    end
  end

  if failed_radars.length >= opts[:fail_on]
    failed_radars.each do |radar|
      @sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([opts[:status], opts[:twitter_update]]))
    end
  end
end

.report_buckets(bucket_names, status, twitter_update) ⇒ Object

Update status page with all radars under the specified buckets

Parameters: => list of names of buckets containing radars,

:status => page status (either 'investigating|identified|monitoring|resolved'),
:twitter_update => do you want to post status to twitter (bool),
:fail_on => number of failures to induce statuspage update (int, default 0)

Raises:



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/runscope_statuspage.rb', line 205

def self.report_buckets(bucket_names, status, twitter_update)
  raise MissingArgumentException.new, 'report_buckets is missing arguments' \
    if not (opts.key?(:status) or opts.key?(:twitter_update) \
    or opts.key?(:bucket_name))

  opts[:fail_on] = opts.key?(:fail_on) ? opts[:fail_on] : 0
  failed_radars = []

  reinit_rest

  @rs.buckets.each do |bucket|
    if opts[:bucket_names].include?(bucket['name'])
      @rs.radars(bucket['key']).each do |radar|
        begin
          if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass'
            failed_radars.push radar
          end
        rescue RunscopeAPIException => r
          p r
          next
        end
      end
    end
  end

  if failed_radars.length >= opts[:fail_on]
    failed_radars.each do |radar|
      @sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([opts[:status], opts[:twitter_update]]))
    end
  end
end

.report_everything(opts = {}) ⇒ Object

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

Parameters: => page status (either ‘investigating|identified|monitoring|resolved’),

:twitter_update => do you want to post status to twitter (bool),
:fail_on => number of failures to induce statuspage update (int, default 0)

Raises:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/runscope_statuspage.rb', line 56

def self.report_everything(opts={})
  raise MissingArgumentException.new, 'report_everything is missing arguments' \
    if not (opts.key?(:status) or opts.key?(:twitter_update))

  opts[:fail_on] = opts.key?(:fail_on) ? opts[:fail_on] : 0
  failed_radars = []

  reinit_rest
  @rs.buckets.each do |bucket|
    @rs.radars(bucket['key']).each do |radar|
      begin
        if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass'
          failed_radars.push radar
        end
      rescue RunscopeAPIException => r
        p r
        next
      end
    end
  end

  if failed_radars.length >= opts[:fail_on]
    failed_radars.each do |radar|
      @sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([opts[:status], opts[:twitter_update]]))
    end
  end
end

.report_radar(opts = {}) ⇒ Object

Update status page with one radar, from one bucket.

Parameters: => name of bucket containing radars,

:radar_name => name of radar within bucket,
:status => page status (either 'investigating|identified|monitoring|resolved'),
:twitter_update => do you want to post status to twitter (bool),
:fail_on => number of failures to induce statuspage update (int, default 0)

Raises:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/runscope_statuspage.rb', line 91

def self.report_radar(opts = {})
  raise MissingArgumentException.new, 'report_radar is missing arguments' \
    if not (opts.key?(:status) or opts.key?(:twitter_update) \
    or opts.key?(:bucket_name) or opts.key?(:radar_name))

  opts[:fail_on] = opts.key?(:fail_on) ? opts[:fail_on] : 0
  failed_radars = []

  reinit_rest
  @rs.buckets.each do |bucket|
    if bucket['name'] == bucket_name
      @rs.radars(bucket['key']).each do |radar|
        begin
          if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass' and radar['name'] == radar_name
            failed_radars.push radar
          end
        rescue RunscopeAPIException => r
          p r
          next
        end
      end
    end
  end

  if failed_radars.length >= opts[:fail_on]
    failed_radars.each do |radar|
      @sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([opts[:status], opts[:twitter_update]]))
    end
  end
end

.report_radars(opts = {}) ⇒ Object

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

Parameters: => name of bucket containing radars,

:radar_names => list of names of radars within bucket,
:status => page status (either 'investigating|identified|monitoring|resolved'),
:twitter_update => do you want to post status to twitter (bool),
:fail_on => number of failures to induce statuspage update (int, default 0)

Raises:



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/runscope_statuspage.rb', line 129

def self.report_radars(opts = {})
  raise MissingArgumentException.new, 'report_radars is missing arguments' \
    if not (opts.key?(:status) or opts.key?(:twitter_update) \
    or opts.key?(:bucket_name) or opts.key?(:radar_names))

  opts[:fail_on] = opts.key?(:fail_on) ? opts[:fail_on] : 0
  failed_radars = []

  reinit_rest
  @rs.buckets.each do |bucket|
    if bucket['name'] == opts[:bucket_name]
      @rs.radars(bucket['key']).each do |radar|
        begin
          if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass' and opts[:radar_names].include?(radar['name'])
            failed_radars.push radar
          end
        rescue RunscopeAPIException => r
          p r
          next
        end
      end
    end
  end

  if failed_radars.length >= opts[:fail_on]
    failed_radars.each do |radar|
      @sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([opts[:status], opts[:twitter_update]]))
    end
  end
end