nrcmd 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 11a4683e93ae4e86688ca3124e8b03e66a4a6ac5
4
+ data.tar.gz: 38f5459e2e4575fb1cf52121724fe374a1d36abf
5
+ SHA512:
6
+ metadata.gz: 7c84664e07c5dc8ae1bb28d480c39ff4f262eba09bdabfd18371590e8ad24051d5276401b271babb28dfd6447710fe216b471f80084305944231124fc5a0142d
7
+ data.tar.gz: 4ca519b5e8c147c2b30a71c96aaf6b73763f81b796a4e2d07fabacdf8ad88f402b5f96160edcf6f457847c3c1d78a0ccbbb6928fd7fd91be14e22d02e32a82f4
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nrcmd.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yusuke Shimizu
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,33 @@
1
+ # Nrcmd
2
+
3
+ A command line tool for NewRelic.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'nrcmd'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nrcmd
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ $ nrcmd list-apps --config /path/to/config_file
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/[my-github-username]/nrcmd/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'nrcmd'
4
+
5
+ Nrcmd::CLI.start
@@ -0,0 +1,2 @@
1
+ require "nrcmd/version"
2
+ require "nrcmd/cli"
@@ -0,0 +1,90 @@
1
+ require 'thor'
2
+
3
+ module Nrcmd
4
+ class Apps < Thor
5
+ namespace :apps
6
+
7
+ Nrcmd.autoload :Metrics, 'nrcmd/apps/metrics'
8
+ Nrcmd.autoload :Hosts, 'nrcmd/apps/hosts/cli'
9
+
10
+ register(Metrics, 'metrics', 'metrics <sub-command>', 'sub-commands for Applications Metrics services')
11
+ register(Hosts, 'hosts', 'hosts <sub-command>', 'sub-commands for Applications Hosts services')
12
+
13
+ URL = 'https://api.newrelic.com/v2'
14
+
15
+ desc "list", "list your applications"
16
+ long_desc <<-LONGDESC
17
+ with --filter, -f option, filtering applications by `name`, `ids`, `language`.
18
+
19
+ https://rpm.newrelic.com/api/explore/applications/list
20
+ LONGDESC
21
+ option :filter, :type => :string, :aliases => '-f', :default => ""
22
+ def list
23
+ uri = URL + '/applications.json'
24
+ filter_param = ""
25
+ options["filter"].gsub(" ", "").split(',').each do |filter|
26
+ fkv = filter.split('=')
27
+ filter_param << "filter[#{fkv[0]}]=#{fkv[1]}&"
28
+ end
29
+ res = Nrcmd::Http.get(uri, {}, filter_param)
30
+ result = JSON.parse(res.body)
31
+ print JSON[ result["applications"] ]
32
+ end
33
+
34
+ desc "show <app_id>", "show summary data of a application."
35
+ long_desc <<-LONGDESC
36
+ https://rpm.newrelic.com/api/explore/applications/show
37
+ LONGDESC
38
+ def show(app_id)
39
+ uri = URL + "/applications/#{app_id}.json"
40
+ res = Nrcmd::Http.get(uri)
41
+ result = JSON.parse(res.body)
42
+ print JSON[ result["application"]]
43
+ end
44
+
45
+ desc "update <app_id> <json_param>", "update application setting."
46
+ long_desc <<-LONGDESC
47
+ `$ nrcmd update_app <app_id> '{"application": {"name": "rename_app_name"}}'
48
+
49
+ sample json parameter
50
+
51
+ ```
52
+ {"application": {"name": "string"}}
53
+ ```
54
+
55
+ ```
56
+ {
57
+ "application": {
58
+ "name": "string",
59
+ "settings": {
60
+ "app_apdex_threshold": "float",
61
+ "end_user_apdex_threshold": "float",
62
+ "enable_real_user_monitoring": "boolean"
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ https://rpm.newrelic.com/api/explore/applications/update
69
+ LONGDESC
70
+ def update(app_id, json_param)
71
+ uri = URL + "/applications/#{app_id}.json"
72
+ header = { 'Content-Type' => 'application/json' }
73
+ data = json_param
74
+ res = Nrcmd::Http.put(uri, header, data)
75
+ result = JSON.parse(res.body)
76
+ print JSON[ result ]
77
+ end
78
+
79
+ desc "delete_app <app_id>", "deletes a application and all of reported data."
80
+ long_desc <<-LONGDESC
81
+ https://rpm.newrelic.com/api/explore/applications/delete
82
+ LONGDESC
83
+ def __delete(id)
84
+ uri = URL + "/applications/#{id}.json"
85
+ res = Nrcmd::Http.delete(uri)
86
+ result = JSON.parse(res.body)
87
+ print JSON[ result ]
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,48 @@
1
+ require 'thor'
2
+
3
+ module Nrcmd
4
+ class Apps::Hosts < Thor
5
+ namespace 'apps hosts'
6
+
7
+ Nrcmd.autoload :Metrics, 'nrcmd/apps/hosts/metrics'
8
+ register(Metrics, 'metrics', 'metrics <sub-command>', 'sub-commands for Application Hosts Metrics services')
9
+
10
+ URL = 'https://api.newrelic.com/v2'
11
+
12
+ desc "list <app_id>", "list your hosts associated with the given app_id."
13
+ long_desc <<-LONGDESC
14
+ This API endpoint returns a paginated list of hosts associated with the given application.
15
+ Application hosts can be filtered by hostname, or the list of application host IDs.
16
+
17
+ with --filter, -f option, filtering applications by `hostname`, `ids`.
18
+
19
+ https://rpm.newrelic.com/api/explore/application_hosts/list
20
+ LONGDESC
21
+ option :filter, :type => :string, :aliases => '-f', :default => ""
22
+ def list(app_id)
23
+ uri = URL + "/applications/#{app_id}/hosts.json"
24
+ filter_param = ""
25
+ options["filter"].gsub(" ", "").split(',').each do |filter|
26
+ fkv = filter.split('=')
27
+ filter_param << "filter[#{fkv[0]}]=#{fkv[1]}&"
28
+ end
29
+ res = Nrcmd::Http.get(uri, {}, filter_param)
30
+ result = JSON.parse(res.body)
31
+ print JSON[ result["application_hosts"] ]
32
+ end
33
+
34
+ desc "show <app_id> <host_id>", "show a single application host, identified by its ID."
35
+ long_desc <<-LONGDESC
36
+ https://rpm.newrelic.com/api/explore/application_hosts/show
37
+ LONGDESC
38
+ def show(app_id, host_id)
39
+ uri = URL + "/applications/#{app_id}/hosts/#{host_id}.json"
40
+ res = Nrcmd::Http.get(uri)
41
+ result = JSON.parse(res.body)
42
+ print JSON[ result["application_host"]]
43
+ end
44
+ def self.banner(task, namespace = false, subcommand = true)
45
+ super
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,60 @@
1
+ require 'thor'
2
+
3
+ module Nrcmd
4
+ class Apps::Hosts::Metrics < Thor
5
+ namespace 'apps hosts metrics'
6
+
7
+ URL = 'https://api.newrelic.com/v2'
8
+
9
+ desc "list <app_id> <host_id>", "show a list of known metrics and their value names for the given resource."
10
+ long_desc <<-LONGDESC
11
+ Return a list of known metrics and their value names for the given resource.
12
+
13
+ https://rpm.newrelic.com/api/explore/application_hosts/names
14
+ LONGDESC
15
+ option :filter, :type => :string, :aliases => '-f', :default => ""
16
+ def list(app_id, host_id)
17
+ uri = URL + "/applications/#{app_id}/hosts/#{host_id}/metrics.json"
18
+ filter_param = ""
19
+ options["filter"].gsub(" ", "").split(',').each do |filter|
20
+ fkv = filter.split('=')
21
+ filter_param << "#{fkv[0]}=#{fkv[1]}&"
22
+ end
23
+ res = Nrcmd::Http.get(uri, {}, filter_param)
24
+ result = JSON.parse(res.body)
25
+ print JSON[ result ]
26
+ end
27
+
28
+ desc "get <app_id> <host_id>", "show a list of values for each of the requested metrics."
29
+ long_desc <<-LONGDESC
30
+ show a list of values for each of the requested metrics. The list of available metrics can be returned using the Metric Name API endpoint.
31
+ Metric data can be filtered by a number of parameters, including multiple names and values, and by time range. Metric names and values will be matched intelligently in the background.
32
+
33
+ You can also retrieve a sumarized data point across the entire time range selected by using the summarize parameter.
34
+
35
+ https://rpm.newrelic.com/api/explore/application_hosts/data
36
+ LONGDESC
37
+ option :names, :type => :string, :aliases => '-n', :default => "", :required => true
38
+ option :values, :type => :string
39
+ option :summarize, :type => :boolean, :aliases => '-s', :default => true
40
+ option :from, :type => :string, :default => nil
41
+ option :to, :type => :string, :default => nil
42
+ def get(app_id, host_id)
43
+ uri = URL + "/applications/#{app_id}/hosts/#{host_id}/metrics/data.json"
44
+ filter_param = ""
45
+ filter_param << "names[]=#{options['names']}&"
46
+ filter_param << "values[]=#{options['values']}&" if !!options['values']
47
+ filter_param << "summarize=#{options['summarize']}&"
48
+ filter_param << "from=#{options["from"]}&" if !!options["from"]
49
+ filter_param << "to=#{options["to"]}&" if !!options["to"]
50
+ res = Nrcmd::Http.get(uri, {}, filter_param)
51
+ result = JSON.parse(res.body)
52
+ print JSON[ result ]
53
+ end
54
+ def self.banner(task, namespace = false, subcommand = true)
55
+ super
56
+ end
57
+ end
58
+ end
59
+
60
+
@@ -0,0 +1,57 @@
1
+ require 'thor'
2
+
3
+ module Nrcmd
4
+ class Apps::Metrics < Thor
5
+ namespace 'apps metrics'
6
+
7
+ URL = 'https://api.newrelic.com/v2'
8
+
9
+ desc "list <app_id>", "show a list of known metrics and their value names for the given resource."
10
+ long_desc <<-LONGDESC
11
+ Return a list of known metrics and their value names for the given resource.
12
+
13
+ https://rpm.newrelic.com/api/explore/applications/names
14
+ LONGDESC
15
+ option :filter, :type => :string, :aliases => '-f', :default => ""
16
+ def list(id)
17
+ uri = URL + "/applications/#{id}/metrics.json"
18
+ filter_param = ""
19
+ options["filter"].gsub(" ", "").split(',').each do |filter|
20
+ fkv = filter.split('=')
21
+ filter_param << "#{fkv[0]}=#{fkv[1]}&"
22
+ end
23
+ res = Nrcmd::Http.get(uri, {}, filter_param)
24
+ result = JSON.parse(res.body)
25
+ print JSON[ result ]
26
+ end
27
+
28
+ desc "get <app_id>", "show a list of values for each of the requested metrics."
29
+ long_desc <<-LONGDESC
30
+ show a list of values for each of the requested metrics. The list of available metrics can be returned using the Metric Name API endpoint.
31
+ Metric data can be filtered by a number of parameters, including multiple names and values, and by time range. Metric names and values will be matched intelligently in the background.
32
+
33
+ You can also retrieve a sumarized data point across the entire time range selected by using the summarize parameter.
34
+
35
+ https://rpm.newrelic.com/api/explore/applications/data
36
+ LONGDESC
37
+ option :filter, :type => :string, :aliases => '-f', :default => ""
38
+ option :names, :type => :string, :aliases => '-n', :required => true
39
+ option :values, :type => :string
40
+ option :summarize, :type => :boolean, :aliases => '-s', :default => true
41
+ option :from, :type => :string, :default => nil
42
+ option :to, :type => :string, :default => nil
43
+ def get(id)
44
+ uri = URL + "/applications/#{id}/metrics/data.json"
45
+ filter_param = ""
46
+ filter_param << "names[]=#{options['names']}&"
47
+ filter_param << "values[]=#{options['values']}&" if !!options['values']
48
+ filter_param << "summarize=#{options['summarize']}"
49
+ filter_param << "from=#{options["from"]}&" if !!options["from"]
50
+ filter_param << "to=#{options["to"]}&" if !!options["to"]
51
+ res = Nrcmd::Http.get(uri, {}, filter_param)
52
+ result = JSON.parse(res.body)
53
+ print JSON[ result ]
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,48 @@
1
+ require 'thor'
2
+ require 'active_support/core_ext/module'
3
+
4
+ module Nrcmd
5
+
6
+ autoload :Apps, 'nrcmd/apps/cli'
7
+ autoload :Server, 'nrcmd/server/cli'
8
+ autoload :User, 'nrcmd/users_cli'
9
+ autoload :Config, 'nrcmd/util/config'
10
+ autoload :Http, 'nrcmd/util/http'
11
+ autoload :JSON, 'json'
12
+ autoload :PP, 'pp'
13
+
14
+ mattr_accessor :conf
15
+ mattr_accessor :log_level
16
+
17
+ class CLI < Thor
18
+
19
+ URL = 'https://api.newrelic.com/v2'
20
+
21
+ class_option :config, :type => :string, :aliases => "-c"
22
+ class_option :verbose, :type => :boolean, :aliases => "-v"
23
+
24
+ register(Apps, 'apps', 'apps <sub-command>', 'commands for Applications services')
25
+ register(Server, 'server', 'server <sub-command>', 'commands for Servers services')
26
+ register(User, 'user', 'user <sub-command>', 'commands for Users services')
27
+
28
+ default_command :help
29
+ def initialize(*args)
30
+ super
31
+ Nrcmd.conf = Nrcmd::Config.load(!!options["config"] ? options["config"] : "#{Dir.home}/.nrcmd_config.rb")
32
+ Nrcmd.log_level = (!!options["verbose"] ? "DEBUG" : "INFO")
33
+ end
34
+
35
+ desc "configure", "setup your config file."
36
+ def configure
37
+ your_api_key = ask("Your NewRelic Api Key: ", :echo => false)
38
+ conf = eval File.read "#{Dir.pwd}/nrcmd_config.rb"
39
+ conf.merge! Hash[ :nr_api_key => your_api_key ]
40
+ File.write("#{Dir.home}/.nrcmd_config.rb", PP.pp(conf, ''))
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+ if __FILE__ == $0
47
+ Nrcmd.start
48
+ end
@@ -0,0 +1,78 @@
1
+ require 'thor'
2
+
3
+ module Nrcmd
4
+ class Server < Thor
5
+ namespace :server
6
+
7
+ Nrcmd.autoload :Metrics, 'nrcmd/server/metrics'
8
+
9
+ register(Metrics, 'metrics', 'metrics <sub-command>', 'sub-commands for Servers Metrics services')
10
+
11
+ URL = 'https://api.newrelic.com/v2'
12
+
13
+ desc "list", "list your servers."
14
+ long_desc <<-LONGDESC
15
+ with --filter, -f option, filtering servers by `name`, `ids`, `labels`.
16
+
17
+ https://rpm.newrelic.com/api/explore/servers/list
18
+ LONGDESC
19
+ option :filter, :type => :string, :aliases => '-f', :default => ""
20
+ def list
21
+ uri = URL + '/servers.json'
22
+ filter_param = ""
23
+ options["filter"].gsub(" ", "").split(',').each do |filter|
24
+ fkv = filter.split('=')
25
+ filter_param << "filter[#{fkv[0]}]=#{fkv[1]}&"
26
+ end
27
+ res = Nrcmd::Http.get(uri, {}, filter_param)
28
+ result = JSON.parse(res.body)
29
+ print JSON[ result["servers"] ]
30
+ end
31
+
32
+ desc "show <server_id>", "show summary data of a server."
33
+ long_desc <<-LONGDESC
34
+ https://rpm.newrelic.com/api/explore/servers/show
35
+ LONGDESC
36
+ def show(server_id)
37
+ uri = URL + "/servers/#{server_id}.json"
38
+ res = Nrcmd::Http.get(uri)
39
+ result = JSON.parse(res.body)
40
+ print JSON[ result["server"]]
41
+ end
42
+
43
+ desc "update <server_id> <json_param>", "update server setting."
44
+ long_desc <<-LONGDESC
45
+ sample json parameter
46
+
47
+ ```
48
+ {
49
+ "server": {
50
+ "name": "string"
51
+ }
52
+ }
53
+ ```
54
+
55
+ https://rpm.newrelic.com/api/explore/servers/update
56
+ LONGDESC
57
+ def update(server_id, json_param)
58
+ uri = URL + "/servers/#{server_id}.json"
59
+ header = { 'Content-Type' => 'application/json' }
60
+ data = json_param
61
+ res = Nrcmd::Http.put(uri, header, data)
62
+ result = JSON.parse(res.body)
63
+ print JSON[ result ]
64
+ end
65
+
66
+ desc "delete <server_id>", "deletes a server and all of reported data."
67
+ long_desc <<-LONGDESC
68
+ https://rpm.newrelic.com/api/explore/servers/delete
69
+ LONGDESC
70
+ def __delete(id)
71
+ uri = URL + "/servers/#{id}.json"
72
+ res = Nrcmd::Http.delete(uri)
73
+ result = JSON.parse(res.body)
74
+ print JSON[ result ]
75
+ end
76
+ end
77
+ end
78
+
@@ -0,0 +1,57 @@
1
+ require 'thor'
2
+
3
+ module Nrcmd
4
+ class Server::Metrics < Thor
5
+ namespace 'server metrics'
6
+
7
+ URL = 'https://api.newrelic.com/v2'
8
+
9
+ desc "list <server_id>", "show a list of known metrics and their value names for the given resource."
10
+ long_desc <<-LONGDESC
11
+ Return a list of known metrics and their value names for the given resource.
12
+
13
+ https://rpm.newrelic.com/api/explore/servers/names
14
+ LONGDESC
15
+ option :filter, :type => :string, :aliases => '-f', :default => ""
16
+ def list(id)
17
+ uri = URL + "/servers/#{id}/metrics.json"
18
+ filter_param = ""
19
+ options["filter"].gsub(" ", "").split(',').each do |filter|
20
+ fkv = filter.split('=')
21
+ filter_param << "#{fkv[0]}=#{fkv[1]}&"
22
+ end
23
+ res = Nrcmd::Http.get(uri, {}, filter_param)
24
+ result = JSON.parse(res.body)
25
+ print JSON[ result ]
26
+ end
27
+
28
+ desc "get <app_id>", "show a list of values for each of the requested metrics."
29
+ long_desc <<-LONGDESC
30
+ show a list of values for each of the requested metrics. The list of available metrics can be returned using the Metric Name API endpoint.
31
+ Metric data can be filtered by a number of parameters, including multiple names and values, and by time range.
32
+ Metric names and values will be matched intelligently in the background.
33
+
34
+ You can also retrieve a sumarized data point across the entire time range selected by using the summarize parameter.
35
+
36
+ https://rpm.newrelic.com/api/explore/applications/data
37
+ LONGDESC
38
+ option :names, :type => :string, :aliases => '-n', :required => true
39
+ option :values, :type => :string
40
+ option :summarize, :type => :boolean, :aliases => '-s', :default => true
41
+ option :from, :type => :string, :default => nil
42
+ option :to, :type => :string, :default => nil
43
+ def get(id)
44
+ uri = URL + "/applications/#{id}/metrics/data.json"
45
+ filter_param = ""
46
+ filter_param << "names[]=#{options['names']}&"
47
+ filter_param << "values[]=#{options['values']}&" if !!options['values']
48
+ filter_param << "summarize=#{options['summarize']}"
49
+ filter_param << "from=#{options["from"]}&" if !!options["from"]
50
+ filter_param << "to=#{options["to"]}&" if !!options["to"]
51
+ res = Nrcmd::Http.get(uri, {}, filter_param)
52
+ result = JSON.parse(res.body)
53
+ print JSON[ result ]
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,40 @@
1
+ require 'thor'
2
+
3
+ module Nrcmd
4
+ class User < Thor
5
+ namespace :user
6
+
7
+ URL = 'https://api.newrelic.com/v2'
8
+
9
+
10
+ desc "list", "show a list of all users"
11
+ long_desc <<-LONGDESC
12
+ Show a list of all users.
13
+
14
+ https://rpm.newrelic.com/api/explore/users/list
15
+ LONGDESC
16
+ option :filter, :type => :string, :aliases => '-f', :default => ""
17
+ def list
18
+ uri = URL + '/users.json'
19
+ filter_param = ""
20
+ options["filter"].gsub(" ", "").split(',').each do |filter|
21
+ fkv = filter.split('=')
22
+ filter_param << "filter[#{fkv[0]}]=#{fkv[1]}&"
23
+ end
24
+ res = Nrcmd::Http.get(uri, {}, filter_param)
25
+ result = JSON.parse(res.body)
26
+ print JSON[ result ]
27
+ end
28
+
29
+ desc "show", "show a single user, identified by ID."
30
+ long_desc <<-LONGDESC
31
+ https://rpm.newrelic.com/api/explore/users/show
32
+ LONGDESC
33
+ def show(id)
34
+ uri = URL + "/users/#{id}.json"
35
+ res = Nrcmd::Http.get(uri)
36
+ result = JSON.parse(res.body)
37
+ print JSON[ result ]
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ module Nrcmd
2
+ class Config
3
+ class << self
4
+ def load(conf_path)
5
+ conf = { :nr_api_key => nil }
6
+ # TODO: handle error, 'file does not exist'
7
+ _conf = eval File.read "#{conf_path}"
8
+ conf.merge! _conf
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,69 @@
1
+ require 'active_support'
2
+
3
+ module Nrcmd
4
+ class Http
5
+
6
+ @header = { "X-Api-Key" => Nrcmd.conf[:nr_api_key] }
7
+
8
+ class << self
9
+ def get(uri_str, _header={}, param="")
10
+ uri = URI.parse(uri_str + '?' + param)
11
+ https = Net::HTTP.new(uri.host, uri.port)
12
+ https.use_ssl = true
13
+ https.set_debug_output $stderr if Nrcmd.log_level == "DEBUG"
14
+ header = @header.merge _header
15
+ req = Net::HTTP::Get.new(uri.request_uri, initheader = header)
16
+ res = https.start {
17
+ https.request(req)
18
+ }
19
+ if res.code == '200'
20
+ return res
21
+ else
22
+ error_message(res)
23
+ end
24
+ end
25
+
26
+ def put(uri_str, _header={}, param="")
27
+ uri = URI.parse(uri_str)
28
+ https = Net::HTTP.new(uri.host, uri.port)
29
+ https.use_ssl = true
30
+ https.set_debug_output $stderr if Nrcmd.log_level == "DEBUG"
31
+ header = @header.merge _header
32
+ req = Net::HTTP::Put.new(uri.request_uri, initheader = header)
33
+ req.body = param
34
+ res = https.start {
35
+ https.request(req)
36
+ }
37
+ if res.code == '200'
38
+ return res
39
+ else
40
+ error_message(res)
41
+ end
42
+ end
43
+
44
+ def delete(uri_str, _header={}, param="")
45
+ uri = URI.parse(uri_str + '?' + param)
46
+ https = Net::HTTP.new(uri.host, uri.port)
47
+ https.use_ssl = true
48
+ https.set_debug_output $stderr if Nrcmd.log_level == "DEBUG"
49
+ header = @header.merge _header
50
+ req = Net::HTTP::Delete.new(uri.request_uri, initheader = header)
51
+ res = https.start {
52
+ https.request(req)
53
+ }
54
+ if res.code == '200'
55
+ return res
56
+ else
57
+ error_message(res)
58
+ end
59
+ end
60
+
61
+
62
+ private
63
+ def error_message(res)
64
+ print "OMG!! #{res.code} #{res.message}"
65
+ exit
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module Nrcmd
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 'nrcmd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nrcmd"
8
+ spec.version = Nrcmd::VERSION
9
+ spec.authors = ["Yusuke Shimizu"]
10
+ spec.email = ["a.ryuklnm@gmail.com"]
11
+ spec.summary = %q{A command line tool for NewRelic.}
12
+ spec.description = %q{A command line tool for NewRelic. }
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency 'thor'
24
+ spec.add_dependency 'net'
25
+ spec.add_dependency 'json'
26
+ spec.add_dependency 'activesupport'
27
+ end
@@ -0,0 +1,3 @@
1
+ {
2
+ :nr_api_key => 'replace_with_your_newrelic_api_key'
3
+ }
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nrcmd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke Shimizu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
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: net
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: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: 'A command line tool for NewRelic. '
98
+ email:
99
+ - a.ryuklnm@gmail.com
100
+ executables:
101
+ - nrcmd
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/nrcmd
111
+ - lib/nrcmd.rb
112
+ - lib/nrcmd/apps/cli.rb
113
+ - lib/nrcmd/apps/hosts/cli.rb
114
+ - lib/nrcmd/apps/hosts/metrics.rb
115
+ - lib/nrcmd/apps/metrics.rb
116
+ - lib/nrcmd/cli.rb
117
+ - lib/nrcmd/server/cli.rb
118
+ - lib/nrcmd/server/metrics.rb
119
+ - lib/nrcmd/users_cli.rb
120
+ - lib/nrcmd/util/config.rb
121
+ - lib/nrcmd/util/http.rb
122
+ - lib/nrcmd/version.rb
123
+ - nrcmd.gemspec
124
+ - nrcmd_config.rb
125
+ homepage: ''
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.4.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A command line tool for NewRelic.
149
+ test_files: []