Skip to content

Instantly share code, notes, and snippets.

@ftclausen
Created July 20, 2014 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftclausen/9dbfc06af685d16564de to your computer and use it in GitHub Desktop.
Save ftclausen/9dbfc06af685d16564de to your computer and use it in GitHub Desktop.
Find unattached nrsysmond instances.
#!/usr/bin/env ruby
require 'rubygems'
require 'rest_client'
require 'json'
banner = <<-EOS
Report all New Relic applications that do not have the system monitor
daemon reporting into the given application environment.
Usage:
find_unattached_nrsysmond.rb <API-KEY>
Example:
find_unattached_nrsysmond.rb 1234567890abcdef
EOS
endpoint = 'https://api.newrelic.com'
if ARGV.length != 1
puts banner
exit 1
else
api_key = ARGV[0]
end
response = nil
begin
response = RestClient.get "#{endpoint}/v2/applications.json", 'X-Api-Key' => api_key
rescue => e
puts "ERROR: Cannot connect to #{endpoint} : #{e.response}"
exit 1
end
nr_data = JSON.parse(response)
nr_data['applications'].each do |app|
app_data = JSON.parse(RestClient.get "#{endpoint}/v2/applications/#{app['id']}/instances.json", 'X-Api-Key' => api_key)
app_instances = app_data['application_instances'].first
# Some app instances have no applications at all. Empty environments
# so check for that before trying to find a linked server
if app_instances && !app_instances['links']['server']
puts "#{app_instances['application_name']} has no linked nrsysmond"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment