circonus 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/circonus-cli +49 -10
- data/lib/circonus.rb +12 -0
- metadata +1 -1
data/bin/circonus-cli
CHANGED
@@ -5,27 +5,66 @@
|
|
5
5
|
require 'rubygems'
|
6
6
|
require 'circonus'
|
7
7
|
require 'pp'
|
8
|
+
require 'optparse'
|
8
9
|
require 'ripl'
|
9
10
|
|
10
|
-
# You
|
11
|
+
# You can optionally define these in a ~/.circonus.rb file as a shortcut
|
12
|
+
# Any arguments passed will override them...
|
11
13
|
#@agent="mytestbroker"
|
12
14
|
#@apitoken="blahblahblah"
|
13
15
|
#@appname="curl"
|
16
|
+
#@apiserver="api.circonus.com"
|
14
17
|
|
15
|
-
|
18
|
+
rbfile = "#{ENV['HOME']}/.circonus.rb"
|
19
|
+
require rbfile if File.exist? rbfile
|
16
20
|
|
17
|
-
|
21
|
+
options = {}
|
22
|
+
options[:apiserver] = "api.circonus.com" # can be something else for Circonus inside product...
|
23
|
+
options[:appname] = @appname || "curl"
|
24
|
+
options[:apitoken] = @apitoken
|
25
|
+
options[:agent] = @agent || 'Ashburn, VA, US'
|
26
|
+
OptionParser.new { |opts|
|
27
|
+
opts.banner = "Usage: #{File.basename($0)} [-h] hostname [-t tag1,tag2,...]\n"
|
28
|
+
opts.on( '-h', '--help', "This usage menu") do
|
29
|
+
puts opts
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
opts.on( '-a','--appname APPNAME',"Name of application to report to Circonus (default: curl)" ) do |t|
|
33
|
+
options[:appname] = t
|
34
|
+
end
|
35
|
+
opts.on( '-g','--agent APPNAME',"Name of agent to use" ) do |t|
|
36
|
+
options[:agent] = t
|
37
|
+
end
|
38
|
+
opts.on( '-s','--server APISERVER',"API server to use (default: api.circonus.com)" ) do |t|
|
39
|
+
options[:apiserver] = t
|
40
|
+
end
|
41
|
+
opts.on( '-t','--token APITOKEN',"API token to use (required in either .circonus.rb or in args" ) do |t|
|
42
|
+
options[:apitoken] = t
|
43
|
+
end
|
44
|
+
}.parse!
|
18
45
|
|
19
|
-
def
|
20
|
-
|
46
|
+
def usage()
|
47
|
+
print <<EOF
|
48
|
+
Usage: #{File.basename($0)} hostname [-t APITOKEN] [-a APPNAME ] [-s APISERVER] [-g AGENT]
|
49
|
+
-h,--help This usage menu
|
50
|
+
-g,--agent AGENTNAME Name of agent to use (default: 'Ashburn, VA, US')
|
51
|
+
-a,--appname APPNAME The name of the application as reported to Circonus (default: curl)
|
52
|
+
-s,--server APISERVER The hostname of the API server to use (default: api.circonus.com)
|
53
|
+
-t,--token APITOKEN The API token to use (required in either .circonus.rb or in args)
|
54
|
+
EOF
|
21
55
|
end
|
22
56
|
|
23
|
-
|
24
|
-
|
25
|
-
|
57
|
+
if options[:apitoken].to_s.empty?
|
58
|
+
usage()
|
59
|
+
exit -1
|
60
|
+
end
|
26
61
|
|
27
|
-
|
28
|
-
|
62
|
+
@c = Circonus.new(options[:apitoken],options[:appname],options[:agent])
|
63
|
+
@c.set_server(options[:apiserver])
|
29
64
|
|
65
|
+
def help()
|
66
|
+
return methods().select { |m| m.to_s.match('^(list|get|add|delete|update|search)_') }.sort.join(' ')
|
67
|
+
end
|
30
68
|
|
69
|
+
Ripl.start :binding => @c.instance_eval{ binding }
|
31
70
|
|
data/lib/circonus.rb
CHANGED
@@ -21,6 +21,18 @@ class Circonus
|
|
21
21
|
:timeout => 300,
|
22
22
|
:open_timeout => 300
|
23
23
|
}
|
24
|
+
|
25
|
+
def set_apitoken(apitoken)
|
26
|
+
@apitoken = apitoken
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_appname(appname)
|
30
|
+
@appname = appname
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_server(server)
|
34
|
+
@url_prefix = "https://#{server}/v2/"
|
35
|
+
end
|
24
36
|
|
25
37
|
def initialize(apitoken,appname,agent=nil, options={})
|
26
38
|
@apitoken = apitoken
|