module RunscopeStatuspage

Constants

VERSION

Attributes

msg[RW]
name[RW]
rs[RW]
rs_key[RW]
sp[RW]
sp_key[RW]
sp_page[RW]

Public Class Methods

parameterize(radar) click to toggle source

Splice radar hash values from keys defined in @name and @msg.

# 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_rest() click to toggle source

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

# 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={}) click to toggle source

Update status page with all radars under passed bucket name.

Parameters: {:bucket_name => 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}
# File lib/runscope_statuspage.rb, line 203
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
        latest = @rs.latest_radar_result(bucket['key'], radar['uuid'])
        
        if latest['result'] != 'pass' and latest['result'] != 'working'
          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) click to toggle source

Update status page with all radars under the specified buckets

Parameters: {:bucket_names => 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}
# File lib/runscope_statuspage.rb, line 252
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
        latest = @rs.latest_radar_result(bucket['key'], radar['uuid'])
        
        if latest['result'] != 'pass' and latest['result'] != 'working'
          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={}) click to toggle source

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

Parameters: {: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}
# 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
        latest = @rs.latest_radar_result(bucket['key'], radar['uuid'])
        
        if latest['result'] != 'pass' and latest['result'] != 'working'
          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 = {}) click to toggle source

Update status page with one radar, from one bucket.

Parameters: {:bucket_name => 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}
# File lib/runscope_statuspage.rb, line 105
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
          latest = @rs.latest_radar_result(bucket['key'], radar['uuid'])
          
          if latest['result'] != 'pass' and radar['name'] == radar_name and latest['result'] != 'working'
            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 = {}) click to toggle source

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

Parameters: {:bucket_name => 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}
# File lib/runscope_statuspage.rb, line 154
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
          latest = @rs.latest_radar_result(bucket['key'], radar['uuid'])

          if latest['result'] != 'pass' and opts[:radar_names].include?(radar['name']) and latest['result'] != 'working'
            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