Class: Wavefront::Alerting

Inherits:
Object
  • Object
show all
Defined in:
lib/wavefront/alerting.rb

Constant Summary collapse

DEFAULT_HOST =
'metrics.wavefront.com'
DEFAULT_PATH =
'/api/alert/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, debug = false) ⇒ Alerting

Returns a new instance of Alerting.



30
31
32
33
# File 'lib/wavefront/alerting.rb', line 30

def initialize(token, debug=false)
  @token = token
  debug(debug)
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



28
29
30
# File 'lib/wavefront/alerting.rb', line 28

def token
  @token
end

Instance Method Details

#active(options = {}) ⇒ Object



35
36
37
# File 'lib/wavefront/alerting.rb', line 35

def active(options={})
  get_alerts('active', options)
end

#affected_by_maintenance(options = {}) ⇒ Object



51
52
53
# File 'lib/wavefront/alerting.rb', line 51

def affected_by_maintenance(options={})
  get_alerts('affected_by_maintenance', options)
end

#all(options = {}) ⇒ Object



39
40
41
# File 'lib/wavefront/alerting.rb', line 39

def all(options={})
  get_alerts('all', options)
end

#get_alerts(path, options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/wavefront/alerting.rb', line 55

def get_alerts(path, options={})
  options[:host] ||= DEFAULT_HOST
  options[:path] ||= DEFAULT_PATH

  query = "t=#{@token}"

  if options[:shared_tags]
    tags = options[:shared_tags].class == Array ? options[:shared_tags] : [ options[:shared_tags] ] # Force an array, even if string given
    query += "&#{tags.map{|t| "customerTag=#{t}"}.join('&')}"
  end

  if options[:private_tags]
    tags = options[:private_tags].class == Array ? options[:private_tags] : [ options[:private_tags] ] # Force an array, even if string given
    query += "&#{tags.map{|t| "userTag=#{t}"}.join('&')}"
  end

  uri = URI::HTTPS.build(
    host: options[:host],
	path: File.join(options[:path], path),
	query: query
  )
  RestClient.get(uri.to_s)
end

#invalid(options = {}) ⇒ Object



43
44
45
# File 'lib/wavefront/alerting.rb', line 43

def invalid(options={})
  get_alerts('invalid', options)
end

#snoozed(options = {}) ⇒ Object



47
48
49
# File 'lib/wavefront/alerting.rb', line 47

def snoozed(options={})
  get_alerts('snoozed', options)
end