relic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e8ef8d2ba86b286ec77ed0a947d18b3fb178257
4
+ data.tar.gz: 6dfe3009e36cf93473e6f95b8d5ea0294cce73c0
5
+ SHA512:
6
+ metadata.gz: 7f15d71cad02b88f42fa4c50ff2f06b2cd1adbf95f6430359ea7098cfa9ff638b4f3fd513d492fad15affe7bad89ec43d2f01f251a23d54b07a6be6fd1547c66
7
+ data.tar.gz: d9eb49ba2f0fafa87dcc5d0968f6ef008861e4ae9a9a0b950f89476232d536378f3edb71590e130912d9906a2115bd7baf0608e45b144eb2a0fab1289e641dbf
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in relic.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Colby Aley
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ # Relic
2
+
3
+ Relic makes it super easy to bring data from the New Relic API to your console.
4
+
5
+ ## Installation
6
+
7
+ $ gem install relic
8
+
9
+ ## Usage
10
+
11
+ After installing Relic, execute `relic --help` to get a list of the commands.
12
+
13
+ ## Contributing
14
+
15
+ 1. Fork it ( http://github.com/ColbyAley/relic/fork )
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
18
+ 4. Push to the branch (`git push origin my-new-feature`)
19
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'relic'
3
+
4
+ Relic::CLI.start
@@ -0,0 +1,109 @@
1
+ require 'relic/version'
2
+ require 'terminal-table'
3
+ require 'httparty'
4
+ require 'netrc'
5
+ require 'thor'
6
+
7
+ module Relic
8
+ class CLI < Thor
9
+
10
+ desc 'servers', 'provide a list of your servers'
11
+ method_option :app, type: :string, aliases: '-a'
12
+ def servers
13
+ id = credentials[0]
14
+ api_key = credentials[1]
15
+
16
+ if options[:app]
17
+ response = HTTParty.get("https://api.newrelic.com/api/v1/accounts/#{id}/applications/#{options[:app]}/servers.json", headers: {'x-api-key' => api_key})
18
+ else
19
+ response = HTTParty.get("https://api.newrelic.com/api/v1/accounts/#{id}/servers.json", headers: {'x-api-key' => api_key})
20
+ end
21
+
22
+ rows = Array.new
23
+ response.each do |server|
24
+ rows << [server['id'], server['hostname']]
25
+ end
26
+
27
+ title = (options[:app].nil? ? 'All servers' : "Servers for application ##{options[:app]}")
28
+
29
+ puts Terminal::Table.new(title: title, headings: ['ID', 'Hostname'], rows: rows)
30
+ end
31
+
32
+ desc 'apps', 'provide a list of your applications'
33
+ def apps
34
+ rows = Array.new
35
+ all_apps.each do |app|
36
+ rows << [app['id'], app['name']]
37
+ end
38
+
39
+ puts Terminal::Table.new(headings: ['ID', 'Name'], rows: rows)
40
+ end
41
+
42
+ desc 'metrics', 'gather metrics for an application'
43
+ method_option :app, type: :string, required: true, aliases: '-a'
44
+ def metrics
45
+ abort 'You must provide an app ID with the --app (-a) option.' if options[:app].nil?
46
+ app_id = options[:app]
47
+ metrics = HTTParty.get("https://api.newrelic.com/api/v1/accounts/#{credentials[0]}/applications/#{app_id}/threshold_values.json", headers: {'x-api-key' => credentials[1]})
48
+ rows = Array.new
49
+
50
+ metrics['threshold_values'].each do |metric|
51
+ rows << [metric['name'], metric['formatted_metric_value']]
52
+ end
53
+
54
+ puts Terminal::Table.new(title: "App ##{app_id}", headings: ['Metric', 'Value'], rows: rows)
55
+ end
56
+
57
+ desc 'auth', 'authenticate with the New Relic API'
58
+ def auth
59
+ puts 'Please enter your New Relic API key and hit enter.'
60
+ api_key = STDIN.gets.chomp
61
+ puts 'Retrieving your account ID...'
62
+ id = account_id(api_key)
63
+ n = Netrc.read
64
+ n.new_item_prefix = "# Added by the Relic CLI.\n"
65
+ n["api.newrelic.com"] = id, api_key
66
+ n.save
67
+ puts "You have been authenticated!"
68
+ end
69
+
70
+ private
71
+
72
+ # Get all of the user's apps.
73
+ def all_apps
74
+ HTTParty.get("https://api.newrelic.com/api/v1/accounts/#{credentials[0]}/applications.json", headers: {'x-api-key' => credentials[1]})
75
+ end
76
+
77
+ # Given an API key, reach out to the New Relic API to grab the account ID.
78
+ #
79
+ # @see http://newrelic.github.io/newrelic_api/#label-Account+ID
80
+ #
81
+ # @param [String] New Relic API key.
82
+ # @return [Integer] account ID.
83
+ # @abort if New Relic doesn't return a 200.
84
+ def account_id(key)
85
+ response = HTTParty.get('https://api.newrelic.com/api/v1/accounts.xml', headers: {'x-api-key' => key})
86
+
87
+ if response.code == 200
88
+ response['accounts'].first['id'] # There may be a case where a user has more than one account?
89
+ else
90
+ abort "There was an error. Was your API key correct?"
91
+ end
92
+ end
93
+
94
+ # Retrieves New Relic credentials from ~/.netrc.
95
+ #
96
+ # @return [Array] array of two elements: account ID and API key.
97
+ # @abort if user hasn't authenticated.
98
+ def credentials
99
+ n = Netrc.read
100
+ auth = n["api.newrelic.com"]
101
+
102
+ if auth.nil?
103
+ abort "Plese authenticate first."
104
+ else
105
+ auth
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,3 @@
1
+ module Relic
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'relic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "relic"
8
+ spec.version = Relic::VERSION
9
+ spec.authors = ["Colby Aley"]
10
+ spec.email = ["colby@aley.me"]
11
+ spec.summary = %q{Simple CLI for the New Relic HTTP API.}
12
+ spec.homepage = "https://github.com/ColbyAley/relic"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "thor"
21
+ spec.add_runtime_dependency "netrc"
22
+ spec.add_runtime_dependency "httparty"
23
+ spec.add_runtime_dependency "terminal-table"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "rake"
27
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Colby Aley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: netrc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: terminal-table
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - colby@aley.me
100
+ executables:
101
+ - relic
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/relic
111
+ - lib/relic.rb
112
+ - lib/relic/version.rb
113
+ - relic.gemspec
114
+ homepage: https://github.com/ColbyAley/relic
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.2.0.rc.1
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Simple CLI for the New Relic HTTP API.
138
+ test_files: []