class RiemannCheckHttp::Riemann
Attributes
domain[RW]
http_open_timeout[RW]
http_read_timeout[RW]
pem_file[RW]
riemann_con[RW]
riemann_ttl[RW]
use_pem[RW]
use_ssl[RW]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/riemann_check_http/riemann.rb, line 17 def initialize(opts = {}) raise "host: param is missing" if not opts[:host] raise "domain: param is missing" if not opts[:domain] opts[:port] ||= 5555 opts[:riemann_timeout] ||= 5 @domain = opts[:domain] @http_open_timeout = 10 @http_read_timeout = 30 @use_ssl = opts[:use_ssl] || false @use_pem = opts[:use_pem] || false @pem_file = opts[:pem_file] || Cacert.pem @riemann_ttl = 120 @riemann_con = ::Riemann::Client.new host: opts[:host], port: opts[:port], riemann_timeout: opts[:riemann_timeout] end
Public Instance Methods
check_app_state(code, sc)
click to toggle source
# File lib/riemann_check_http/riemann.rb, line 63 def check_app_state(code, sc) state = 'okay' sc.each do |c| if c =~ /^[0-9]{3}(\.\.[0-9]{3})?$/ if $1 if eval(c) === code.to_i state = 'critical' break end else if code.to_s == c state = 'critical' break end end else raise "#{c.inspect} status code is not in valid format" end end state end
check_http(url, *sc)
click to toggle source
# File lib/riemann_check_http/riemann.rb, line 46 def check_http(url, *sc) code = '501' msg = 'Unknown' if url =~ /^(http:\/\/|https:\/\/)?(.*?)(\.internal)?\.#{domain}\.com/ app = $2 if $2 type = $3 ? 'internal' : 'external' else raise "Improper url: #{url}" end con = RiemannCheckHttp::NetHttp.new use_pem: use_pem, use_ssl: use_ssl, read_timeout: 30, open_timeout: 5, pem_file: pem_file (code, msg) = con.get url state = check_app_state code, sc dsc = msg + ", status code #{code}" send_riemann app, state, type, dsc [code, msg] end
send_riemann(app, state, type, dsc)
click to toggle source
# File lib/riemann_check_http/riemann.rb, line 33 def send_riemann(app, state, type, dsc) metric = (state == 'critical') ? 0 : 1 tuple = { service: "#{app}.#{type}", state: state, tags: ["#{type}_url_monitoring","influxdb"], metric: metric, description: dsc, ttl: riemann_ttl } riemann_con << tuple end