class Bosh::Monitor::Events::Alert

Constants

SEVERITY_MAP

Considering Bosh::Agent::Alert

Attributes

created_at[R]
source[R]
title[R]

Public Class Methods

new(attributes = {}) click to toggle source
Calls superclass method
# File lib/bosh/monitor/events/alert.rb, line 16
def initialize(attributes = {})
  super
  @kind = :alert

  @id         = @attributes["id"]
  @severity   = @attributes["severity"]
  @title      = @attributes["title"]
  @summary    = @attributes["summary"] || @title
  @source     = @attributes["source"]

  # This rescue is just to preserve existing test behavior. However, this
  # seems like a pretty wacky way to handle errors - wouldn't we rather
  # have a nice exception?
  @created_at = Time.at(@attributes["created_at"]) rescue @attributes["created_at"]
end

Public Instance Methods

metrics() click to toggle source
# File lib/bosh/monitor/events/alert.rb, line 86
def metrics
  [ ]
end
severity() click to toggle source
# File lib/bosh/monitor/events/alert.rb, line 52
def severity
  SEVERITY_MAP[@severity] || @severity
end
short_description() click to toggle source
# File lib/bosh/monitor/events/alert.rb, line 48
def short_description
  "Severity #{@severity}: #{@source} #{@title}"
end
to_hash() click to toggle source
# File lib/bosh/monitor/events/alert.rb, line 56
def to_hash
  {
    :kind       => "alert",
    :id         => @id,
    :severity   => @severity,
    :title      => @title,
    :summary    => @summary,
    :source     => @source,
    :created_at => @created_at.to_i
  }
end
to_json() click to toggle source
# File lib/bosh/monitor/events/alert.rb, line 68
def to_json
  Yajl::Encoder.encode(self.to_hash)
end
to_plain_text() click to toggle source
# File lib/bosh/monitor/events/alert.rb, line 76
def to_plain_text
  result = ""
  result << "#{@source}\n" unless @source.nil?
  result << (@title || "Unknown Alert") << "\n"
  result << "Severity: #{@severity}\n"
  result << "Summary: #{@summary}\n" unless @summary.nil?
  result << "Time: #{@created_at.utc}\n"
  result
end
to_s() click to toggle source
# File lib/bosh/monitor/events/alert.rb, line 72
def to_s
  "Alert @ #{@created_at.utc}, severity #{@severity}: #{@summary}"
end
validate() click to toggle source
# File lib/bosh/monitor/events/alert.rb, line 32
def validate
  add_error("id is missing") if @id.nil?
  add_error("severity is missing") if @severity.nil?

  if @severity && (!@severity.kind_of?(Integer) || @severity < 0)
    add_error("severity is invalid (non-negative integer expected)")
  end

  add_error("title is missing") if @title.nil?
  add_error("timestamp is missing") if @created_at.nil?

  if @created_at && !@created_at.kind_of?(Time)
    add_error('created_at is invalid UNIX timestamp')
  end
end