module NewRelicManagement::Client
> NewRelic Manager
Client
¶ ↑
Public Instance Methods
alert_add_entity(entity_id, condition_id, entity_type = 'Server')
click to toggle source
> Add an Entitity to an Existing Alert Policy¶ ↑
# File lib/newrelic-management/client.rb, line 62 def alert_add_entity(entity_id, condition_id, entity_type = 'Server') nr_api.put do |req| req.url url('alerts_entity_conditions', entity_id) req.params['entity_type'] = entity_type req.params['condition_id'] = condition_id end end
alert_conditions(policy)
click to toggle source
alert_delete_entity(entity_id, condition_id, entity_type = 'Server')
click to toggle source
> Delete an Entitity from an Existing Alert Policy¶ ↑
# File lib/newrelic-management/client.rb, line 71 def alert_delete_entity(entity_id, condition_id, entity_type = 'Server') nr_api.delete do |req| req.url url('alerts_entity_conditions', entity_id) req.params['entity_type'] = entity_type req.params['condition_id'] = condition_id end end
alert_policies()
click to toggle source
conn_opts()
click to toggle source
# File lib/newrelic-management/client.rb, line 34 def conn_opts { headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'X-api-key' => Config.nr_api_key }, # => ssl: ssl_options } end
delete_server(server_id)
click to toggle source
get_server(server)
click to toggle source
get_server_id(server_id)
click to toggle source
get_server_name(server, exact = true)
click to toggle source
> Get a Server based on Name¶ ↑
# File lib/newrelic-management/client.rb, line 113 def get_server_name(server, exact = true) ret = nr_api.get(url('servers'), 'filter[name]' => server).body return ret['servers'] unless exact ret['servers'].find { |x| x['name'].casecmp(server).zero? } rescue NoMethodError nil end
get_servers_labeled(labels)
click to toggle source
labels()
click to toggle source
nr_api()
click to toggle source
> Build the HTTP Connection¶ ↑
# File lib/newrelic-management/client.rb, line 23 def nr_api # => Build the Faraday Connection @conn ||= Faraday::Connection.new('https://api.newrelic.com', conn_opts) do |client| client.use Faraday::Response::RaiseError client.use FaradayMiddleware::EncodeJson client.use FaradayMiddleware::ParseJson, content_type: /\bjson$/ client.response :logger if Config.environment.to_s.casecmp('development').zero? # => Log Requests to STDOUT client.adapter Faraday.default_adapter #:net_http_persistent end end
Private Instance Methods
url(*args)
click to toggle source
# File lib/newrelic-management/client.rb, line 133 def url(*args) '/v2/' + args.map { |a| URI.encode_www_form_component a.to_s }.join('/') + '.json' end