Skip to content

Commit

Permalink
move logic inside CLI class and make executable cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Horbul committed Apr 12, 2012
1 parent 2fd59be commit 2baa98b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
12 changes: 1 addition & 11 deletions bin/check_splunk
@@ -1,14 +1,4 @@
#!/usr/bin/env ruby

require 'nagios/splunk'

cli = Nagios::Splunk::CLI.new
cli.parse_options

client = Nagios::Splunk::RestClient.new(cli.config[:server_url])
splunk = Nagios::Splunk::Check.new(client)

status, message = splunk.license_usage(cli.config[:warn], cli.config[:crit])

puts message
exit status
exit Nagios::Splunk::CLI.new.run
21 changes: 17 additions & 4 deletions lib/nagios/splunk/cli.rb
Expand Up @@ -9,20 +9,33 @@ class CLI
option(:server_url,
:short => "-s URL",
:long => "--server URL",
:default => 'https://admin:changeme@localhost:8089/',
:description => "Splunk server url")
:required => true,
:description => "Splunk server url",
:on => :head)

option(:warn,
:short => "-w WARN",
:long => "--warn WARN",
:default => '80',
:description => "Warn % of license capacity usage")
:description => "Warn % of license capacity usage (default: 80)")

option(:crit,
:short => "-c CRIT",
:long => "--crit CRIT",
:default => '90',
:description => "Critical % of license capacity usage")
:description => "Critical % of license capacity usage (default: 90)")

def run(argv = ARGV)
parse_options(argv)

client = RestClient.new(config[:server_url])
splunk = Check.new(client)

status, message = splunk.license_usage(config[:warn], config[:crit])

puts message
status
end
end

end
Expand Down

0 comments on commit 2baa98b

Please sign in to comment.