diff --git a/bin/check_splunk b/bin/check_splunk index 4571484..021c0f3 100644 --- a/bin/check_splunk +++ b/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 diff --git a/lib/nagios/splunk/cli.rb b/lib/nagios/splunk/cli.rb index cf9bfc3..c86710b 100644 --- a/lib/nagios/splunk/cli.rb +++ b/lib/nagios/splunk/cli.rb @@ -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