Created
July 20, 2014 23:38
-
-
Save ftclausen/9dbfc06af685d16564de to your computer and use it in GitHub Desktop.
Find unattached nrsysmond instances.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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