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.6'

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
49
50
# 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)
        next if radar["#{token}"].nil?
        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)
        next if radar["#{token}"].nil?
        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),
:no_sp => skip statuspage.io report and return data

Raises:



197
198
199
200
201
202
203
204
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
# File 'lib/runscope_statuspage.rb', line 197

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
  opts[:no_sp] = opts.key?(:no_sp) ? opts[:no_sp] : false

  failed_radars = []
  event_info = []

  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|
      data = *parameterize(radar)

      @sp.create_realtime_incident(@sp_page, data.concat([opts[:status], opts[:twitter_update]])) if not opts[:no_sp]
      event_info.push data if opts[:no_sp]
    end
  end

  event_info if opts[:no_sp]
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),
:no_sp => skip statuspage.io report and return data

Raises:



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/runscope_statuspage.rb', line 244

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
  opts[:no_sp] = opts.key?(:no_sp) ? opts[:no_sp] : false
  
  failed_radars = []
  event_info = []

  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|
      data = *parameterize(radar)

      @sp.create_realtime_incident(@sp_page, data.concat([opts[:status], opts[:twitter_update]])) if not opts[:no_sp]
      event_info.push data if opts[:no_sp]
    end
  end

  event_info if opts[:no_sp]
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),
:no_sp => skip statuspage.io report and return data

Raises:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/runscope_statuspage.rb', line 59

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
  opts[:no_sp] = opts.key?(:no_sp) ? opts[:no_sp] : false

  failed_radars = []
  event_info = []

  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|
      data = *parameterize(radar)

      @sp.create_realtime_incident(@sp_page, data.concat([opts[:status], opts[:twitter_update]])) if not opts[:no_sp]
      event_info.push data if opts[:no_sp]
    end
  end

  event_info if opts[:no_sp]
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),
:no_sp => skip statuspage.io report and return data

Raises:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/runscope_statuspage.rb', line 103

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
  opts[:no_sp] = opts.key?(:no_sp) ? opts[:no_sp] : false

  failed_radars = []
  event_info = []

  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|
      data = *parameterize(radar)

      @sp.create_realtime_incident(@sp_page, data.concat([opts[:status], opts[:twitter_update]])) if not opts[:no_sp]
      event_info.push data if opts[:no_sp]
    end
  end

  event_info if opts[:no_sp]
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),
:no_sp => skip statuspage.io report and return data

Raises:



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/runscope_statuspage.rb', line 150

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
  opts[:no_sp] = opts.key?(:no_sp) ? opts[:no_sp] : false

  failed_radars = []
  event_info = []

  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|
      data = *parameterize(radar)

      @sp.create_realtime_incident(@sp_page, data.concat([opts[:status], opts[:twitter_update]])) if not opts[:no_sp]
      event_info.push data if opts[:no_sp]
    end
  end

  event_info if opts[:no_sp]
end