Sha256: a60f930b80caa3ada778cffd3673124a6095a18759d2e4ed8b01dc80c499baef

Contents?: true

Size: 773 Bytes

Versions: 16

Compression:

Stored size: 773 Bytes

Contents

#!/usr/bin/env ruby

RUBIX_ROOT = File.expand_path('../../../../lib', __FILE__)
$: << RUBIX_ROOT unless $:.include?(RUBIX_ROOT)

require 'rubix'
require 'net/http'
require 'timeout'

class HttpAvailabilityMonitor < Rubix::Monitor

  include Rubix::ZabbixMonitor

  def host_group_name
    'Zabbix servers'
  end

  def measure
    hosts.each do |host|
      measure_host(host)
    end
  end

  def measure_host host
    begin
      timeout(1) do
        if Net::HTTP.get_response(URI.parse("http://#{host.ip}/")).code.to_i == 200
          write [host.name, 'webserver.available', 1]
          return
        end
      end
    rescue => e
      puts e.message
    end
    write [host.name, 'webserver.available', 0]
  end
end

HttpAvailabilityMonitor.run if $0 == __FILE__

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rubix-0.5.14 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.13 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.9 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.8 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.7 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.6 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.5 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.4 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.3 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.2 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.1 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.5.0 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.4.3 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.4.2 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.4.1 lib/rubix/examples/simple_zabbix_monitor.rb
rubix-0.4.0 lib/rubix/examples/simple_zabbix_monitor.rb