Class: Wavefront::Metadata
- Inherits:
-
Object
- Object
- Wavefront::Metadata
- Includes:
- Constants
- Defined in:
- lib/wavefront/metadata.rb
Constant Summary collapse
- DEFAULT_PATH =
'/api/manage/source/'
Constants included from Constants
Constants::ALERT_FORMATS, Constants::DEFAULT_ALERT_FORMAT, Constants::DEFAULT_FORMAT, Constants::DEFAULT_HOST, Constants::DEFAULT_INFILE_FORMAT, Constants::DEFAULT_OBSOLETE_METRICS, Constants::DEFAULT_PERIOD_SECONDS, Constants::DEFAULT_PREFIX_LENGTH, Constants::DEFAULT_PROXY, Constants::DEFAULT_PROXY_PORT, Constants::DEFAULT_STRICT, Constants::EVENT_LEVELS, Constants::EVENT_STATE_DIR, Constants::FORMATS, Constants::GRANULARITIES
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #add_tags(hostnames, tags) ⇒ Object
- #get_tags(hostname = '', limit = 100) ⇒ Object
-
#initialize(token, host = DEFAULT_HOST, debug = false) ⇒ Metadata
constructor
A new instance of Metadata.
- #remove_tags(hostnames, tags, options = {}) ⇒ Object
Constructor Details
#initialize(token, host = DEFAULT_HOST, debug = false) ⇒ Metadata
Returns a new instance of Metadata.
31 32 33 34 35 |
# File 'lib/wavefront/metadata.rb', line 31 def initialize(token, host=DEFAULT_HOST, debug=false) @headers = {'X-AUTH-TOKEN' => token} @base_uri = URI::HTTPS.build(:host => host, :path => DEFAULT_PATH) debug(debug) end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
29 30 31 |
# File 'lib/wavefront/metadata.rb', line 29 def base_uri @base_uri end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
29 30 31 |
# File 'lib/wavefront/metadata.rb', line 29 def headers @headers end |
Instance Method Details
#add_tags(hostnames, tags) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/wavefront/metadata.rb', line 61 def (hostnames, ) # Build and call tagging URI for each host and tag. hostnames.each do |hostname| host_uri = URI.join(@base_uri.to_s,"#{hostname}/") extended_uri = URI.join(host_uri.to_s,"tags/") .each do |tag| final_uri = URI.join(extended_uri.to_s,tag) RestClient.post(final_uri.to_s, {}, @headers) end end end |
#get_tags(hostname = '', limit = 100) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/wavefront/metadata.rb', line 37 def (hostname='', limit=100) uri = @base_uri unless hostname.empty? uri = URI.join(@base_uri.to_s, hostname) end if limit > 10000 limit = 10000 end args = {:params => {:limit => limit}}.merge(@headers) begin response = RestClient.get(uri.to_s, args) rescue RestClient::ResourceNotFound # If a 404 is returned, we return an empty JSON as this is the expected behaviour for untagged hosts response = {} end return response end |
#remove_tags(hostnames, tags, options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/wavefront/metadata.rb', line 75 def (hostnames, , ={}) hostnames.each do |hostname| host_uri = URI.join(@base_uri.to_s,"#{hostname}/") extended_uri = URI.join(host_uri.to_s,"tags/") .each do |tag| final_uri = URI.join(extended_uri.to_s,tag) RestClient.delete(final_uri.to_s, @headers) end end end |