bin/metrics-curl.rb in sensu-plugins-http-0.2.1 vs bin/metrics-curl.rb in sensu-plugins-http-0.3.0
- old
+ new
@@ -27,10 +27,11 @@
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
#
require 'socket'
+require 'English'
require 'sensu-plugin/metric/cli'
#
# Curl Metrics
#
@@ -54,21 +55,26 @@
required: true,
default: "#{Socket.gethostname}.curl_timings"
def run
cmd = "curl --silent --output /dev/null #{config[:curl_args]} "
- cmd += '-w "%{time_total},%{time_namelookup},%{time_connect},%{time_pretransfer},%{time_redirect},%{time_starttransfer}" '
+ cmd += '-w "%{time_total},%{time_namelookup},%{time_connect},%{time_pretransfer},%{time_redirect},%{time_starttransfer},%{http_code}" '
cmd += config[:url]
output = `#{cmd}`
- (time_total, time_namelookup, time_connect, time_pretransfer, time_redirect, time_starttransfer) = output.split(',')
+ (time_total, time_namelookup, time_connect, time_pretransfer, time_redirect, time_starttransfer, http_code) = output.split(',')
output "#{config[:scheme]}.time_total", time_total
output "#{config[:scheme]}.time_namelookup", time_namelookup
output "#{config[:scheme]}.time_connect", time_connect
output "#{config[:scheme]}.time_pretransfer", time_pretransfer
output "#{config[:scheme]}.time_redirect", time_redirect
output "#{config[:scheme]}.time_starttransfer", time_starttransfer
+ output "#{config[:scheme]}.http_code", http_code
- ok
+ if $CHILD_STATUS.to_i == 0
+ ok
+ else
+ warning
+ end
end
end