Class: Wavefront::Alerting
- Inherits:
-
Object
- Object
- Wavefront::Alerting
- Includes:
- Constants, Mixins, Validators
- Defined in:
- lib/wavefront/alerting.rb
Constant Summary collapse
- DEFAULT_PATH =
'/api/alert/'
Constants included from Constants
Constants::ALERT_FORMATS, Constants::DASH_FORMATS, Constants::DEFAULT_ALERT_FORMAT, Constants::DEFAULT_DASH_FORMAT, Constants::DEFAULT_FORMAT, Constants::DEFAULT_HOST, Constants::DEFAULT_INFILE_FORMAT, Constants::DEFAULT_OBSOLETE_METRICS, Constants::DEFAULT_OPTS, Constants::DEFAULT_PERIOD_SECONDS, Constants::DEFAULT_PREFIX_LENGTH, Constants::DEFAULT_PROXY, Constants::DEFAULT_PROXY_PORT, Constants::DEFAULT_SOURCE_FORMAT, Constants::DEFAULT_STRICT, Constants::EVENT_LEVELS, Constants::EVENT_STATE_DIR, Constants::FORMATS, Constants::GRANULARITIES, Constants::SOURCE_FORMATS
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#noop ⇒ Object
readonly
Returns the value of attribute noop.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #active(options = {}) ⇒ Object
- #affected_by_maintenance(options = {}) ⇒ Object
- #all(options = {}) ⇒ Object
- #create_alert(alert = {}) ⇒ Object
- #get_alert(id, options = {}) ⇒ Object
- #import_to_create(raw) ⇒ Object
-
#initialize(token, host = DEFAULT_HOST, debug = false, options = {}) ⇒ Alerting
constructor
A new instance of Alerting.
- #invalid(options = {}) ⇒ Object
- #snoozed(options = {}) ⇒ Object
Methods included from Mixins
#call_delete, #call_get, #call_post, #hash_to_qs, #interpolate_schema, #load_file, #parse_time, #time_to_ms, #uri_concat
Methods included from Validators
#valid_path?, #valid_source?, #valid_string?, #valid_tags?, #valid_ts?, #valid_value?
Constructor Details
#initialize(token, host = DEFAULT_HOST, debug = false, options = {}) ⇒ Alerting
Returns a new instance of Alerting.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wavefront/alerting.rb', line 34 def initialize(token, host = DEFAULT_HOST, debug=false, = {}) # # Following existing convention, 'host' is the Wavefront API endpoint. # @headers = { :'X-AUTH-TOKEN' => token } @endpoint = host @token = token debug(debug) @noop = [:noop] @verbose = [:verbose] @options = end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
32 33 34 |
# File 'lib/wavefront/alerting.rb', line 32 def endpoint @endpoint end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
32 33 34 |
# File 'lib/wavefront/alerting.rb', line 32 def headers @headers end |
#noop ⇒ Object (readonly)
Returns the value of attribute noop.
32 33 34 |
# File 'lib/wavefront/alerting.rb', line 32 def noop @noop end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
32 33 34 |
# File 'lib/wavefront/alerting.rb', line 32 def @options end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
32 33 34 |
# File 'lib/wavefront/alerting.rb', line 32 def token @token end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
32 33 34 |
# File 'lib/wavefront/alerting.rb', line 32 def verbose @verbose end |
Instance Method Details
#active(options = {}) ⇒ Object
127 128 129 130 |
# File 'lib/wavefront/alerting.rb', line 127 def active(={}) call_get(create_uri(.merge(path: 'active', qs: mk_qs()))) end |
#affected_by_maintenance(options = {}) ⇒ Object
146 147 148 149 |
# File 'lib/wavefront/alerting.rb', line 146 def affected_by_maintenance(={}) call_get(create_uri(.merge(path: 'affected_by_maintenance', qs: mk_qs()))) end |
#all(options = {}) ⇒ Object
132 133 134 |
# File 'lib/wavefront/alerting.rb', line 132 def all(={}) call_get(create_uri(.merge(path: 'all', qs: mk_qs()))) end |
#create_alert(alert = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 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 |
# File 'lib/wavefront/alerting.rb', line 79 def create_alert(alert={}) # # Create an alert. Expects you to provide it with a hash of # the form: # # { # name: string # condition: string # displayExpression: string (optional) # minutes: int # resolveMinutes: int (optional) # notifications: array # severity: INFO | SMOKE | WARN | SEVERE # privateTags: array (optional) # sharedTags: array (optional) # additionalInformation string (optional) # id string (optional - will trigger update behaviour) # } # %w(name condition minutes notifications severity).each do |f| raise "missing field: #{f}" unless alert.key?(f.to_sym) end unless %w(INFO SMOKE WARN SEVERE).include?(alert[:severity]) raise 'invalid severity' end %w(notifications privateTags sharedTags).each do |f| f = f.to_sym alert[f] = alert[f].join(',') if alert[f] && alert[f].is_a?(Array) end path = alert.has_key?(:id) ? alert[:id] : 'create' call_post(create_uri(path: path), hash_to_qs(alert), 'application/x-www-form-urlencoded') end |
#get_alert(id, options = {}) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/wavefront/alerting.rb', line 117 def get_alert(id, = {}) # # Alerts are identified by the timestamp at which they were # created. Returns a hash. Exceptions are just passed on # through. You get a 500 if the alert doesn't exist. # resp = call_get(create_uri(path: id)) || '{}' return JSON.parse(resp) end |
#import_to_create(raw) ⇒ Object
47 48 49 50 51 52 53 54 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 47 def import_to_create(raw) # # Take a previously exported alert, and construct a hash which # create_alert() can use to re-create it. # ret = { name: raw['name'], condition: raw['condition'], minutes: raw['minutes'], notifications: raw['target'].split(','), severity: raw['severity'], } if raw.key?('displayExpression') ret[:displayExpression] = raw['displayExpression'] end if raw.key?('resolveAfterMinutes') ret[:resolveMinutes] = raw['resolveAfterMinutes'] end if raw.key?('customerTagsWithCounts') ret[:sharedTags] = raw['customerTagsWithCounts'].keys end if raw.key?('additionalInformation') ret[:additionalInformation] = raw['additionalInformation'] end ret end |
#invalid(options = {}) ⇒ Object
136 137 138 139 |
# File 'lib/wavefront/alerting.rb', line 136 def invalid(={}) call_get(create_uri(.merge(path: 'invalid', qs: mk_qs()))) end |
#snoozed(options = {}) ⇒ Object
141 142 143 144 |
# File 'lib/wavefront/alerting.rb', line 141 def snoozed(={}) call_get(create_uri(.merge(path: 'snoozed', qs: mk_qs()))) end |