class Wavefront::Metadata
Because of the way the 'manage' API is laid out, this class doesn't reflect it as clearly as, say the 'alerts' class. There is a small amount of duplication in method names too, as it merges a new class and an old one.
Note that the following methods do not do any exception handling. It is up to your client code to decide how to deal with, for example, a RestClient::ResourceNotFound exception.
Constants
- DEFAULT_PATH
Attributes
endpoint[R]
headers[R]
host[R]
noop[R]
verbose[R]
Public Class Methods
new(token, host=DEFAULT_HOST, debug=false, options = {})
click to toggle source
# File lib/wavefront/metadata.rb, line 45 def initialize(token, host=DEFAULT_HOST, debug=false, options = {}) # # 'host' is the Wavefront API endpoint # @headers = {'X-AUTH-TOKEN' => token} @base_uri = URI::HTTPS.build(:host => host, :path => DEFAULT_PATH) @endpoint = host @verbose = options[:verbose] || false @noop = options[:noop] || false debug(debug) end
Public Instance Methods
delete_tag(source, tag)
click to toggle source
# File lib/wavefront/metadata.rb, line 114 def delete_tag(source, tag) # # Delete a given tag from a source. Maps to # DELETE /api/manage/source/{source}/tags/{tag} # fail Wavefront::Exception::InvalidSource unless valid_source?(source) fail Wavefront::Exception::InvalidString unless valid_string?(tag) call_delete(build_uri(uri_concat(source, 'tags', tag))) end
set_description(source, desc)
click to toggle source
# File lib/wavefront/metadata.rb, line 179 def set_description(source, desc) # # set the description field for a source. Maps to # POST /api/manage/source/{source}/description # fail Wavefront::Exception::InvalidSource unless valid_source?(source) fail Wavefront::Exception::InvalidString unless valid_string?(desc) call_post(build_uri(uri_concat(source, 'description')), desc) end
set_tag(source, tag)
click to toggle source
# File lib/wavefront/metadata.rb, line 189 def set_tag(source, tag) # # set a tag on a source. Maps to # POST /api/manage/source/{source}/tags/{tag} # fail Wavefront::Exception::InvalidSource unless valid_source?(source) fail Wavefront::Exception::InvalidString unless valid_string?(tag) call_post(build_uri(uri_concat(source, 'tags', tag))) end
show_source(source)
click to toggle source
# File lib/wavefront/metadata.rb, line 166 def show_source(source) # # return information about a single source as a Ruby object. Maps to # GET /api/manage/source/{source}. # # See the Wavefront API docs for the structure of the object. # fail Wavefront::Exception::InvalidSource unless valid_source?(source) resp = call_get(build_uri(source)) || '{}' JSON.parse(resp) end
show_sources(params = {})
click to toggle source
# File lib/wavefront/metadata.rb, line 124 def show_sources(params = {}) # # Return a list of sources as a Ruby object. Maps to # GET /api/manage/source # call it with a hash as described in the Wavefront API docs. # # See the Wavefront API docs for the format of the returned # object. # # At the time of writing, supported paramaters are: # lastEntityId (string) # desc (bool) # limit (int) # pattern (string) # # Hash keys should be symbols. # if params.key?(:lastEntityId) && !params[:lastEntityId].is_a?(String) fail TypeError end if params.key?(:pattern) && !params[:pattern].is_a?(String) fail TypeError end if params.key?(:desc) && ! (params[:desc] == !!params[:desc]) fail TypeError end if params.key?(:limit) fail TypeError unless params[:limit].is_a?(Numeric) if params[:limit] < 0 || params[:limit] >= 10000 fail Wavefront::Exception::ValueOutOfRange end end resp = call_get(build_uri(nil, query: hash_to_qs(params))) || '{}' JSON.parse(resp) end
Private Instance Methods
build_uri(path_ext = '', options = {})
click to toggle source
# File lib/wavefront/metadata.rb, line 201 def build_uri(path_ext = '', options = {}) options[:host] ||= endpoint options[:path] ||= DEFAULT_PATH URI::HTTPS.build( host: options[:host], path: uri_concat(options[:path], path_ext), query: options[:query] ) end
debug(enabled)
click to toggle source
# File lib/wavefront/metadata.rb, line 212 def debug(enabled) RestClient.log = 'stdout' if enabled end