Class: CirconusUtil
- Inherits:
-
Object
- Object
- CirconusUtil
- Defined in:
- lib/circonusutil.rb
Instance Attribute Summary collapse
-
#circonus ⇒ Object
Returns the value of attribute circonus.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(&addl_opts) ⇒ CirconusUtil
constructor
A new instance of CirconusUtil.
- #parse_opts ⇒ Object
Constructor Details
#initialize(&addl_opts) ⇒ CirconusUtil
Returns a new instance of CirconusUtil.
36 37 38 39 40 41 42 43 44 |
# File 'lib/circonusutil.rb', line 36 def initialize(&addl_opts) @options = {} @options[:apiserver] = ENV['CIRCONUS_APISERVER'] || "api.circonus.com" # can be something else for Circonus inside product... @options[:appname] = ENV['CIRCONUS_APPNAME'] || "curl" @options[:apitoken] = ENV['CIRCONUS_APITOKEN'] @additional_opts = addl_opts self.parse_opts self.connect end |
Instance Attribute Details
#circonus ⇒ Object
Returns the value of attribute circonus.
6 7 8 |
# File 'lib/circonusutil.rb', line 6 def circonus @circonus end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/circonusutil.rb', line 5 def @options end |
Instance Method Details
#connect ⇒ Object
32 33 34 35 |
# File 'lib/circonusutil.rb', line 32 def connect @circonus = Circonus.new(@options[:apitoken],@options[:appname]) @circonus.set_server(@options[:apiserver]) end |
#parse_opts ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/circonusutil.rb', line 7 def parse_opts() OptionParser.new { |opts| opts. = "Usage: #{File.basename($0)}\n" opts.on( '-h', '--help', "This usage menu") do puts opts exit end opts.on( '-a','--appname APPNAME',"Name of application to report to Circonus (default: curl)" ) do |t| @options[:appname] = t end opts.on( '-s','--server APISERVER',"API server to use (default: api.circonus.com)" ) do |t| @options[:apiserver] = t end opts.on( '-t','--token APITOKEN',"API token to use (required)" ) do |t| @options[:apitoken] = t end unless @additional_opts.nil? @additional_opts.call(opts,@options) end }.parse! if [:apitoken].to_s.empty? puts "Missing apitoken!" exit -1 end end |