Sha256: 72364f8438d7458496a5dc70f8c91d3fb4b3df29048892e67affc3148f916f5b

Contents?: true

Size: 897 Bytes

Versions: 16

Compression:

Stored size: 897 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
  include Rubix::ClusterMonitor  

  def host_group_name
    'Zabbix servers'
  end

  def measure_cluster cluster_name
    hosts_by_cluster[cluster_name].each do |host|
      measure_host(host)
    end
    write [cluster_name, 'something', 1]
  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_cluster_monitor.rb
rubix-0.5.13 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.5.9 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.5.8 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.5.7 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.5.6 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.5.5 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.5.4 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.5.3 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.5.2 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.5.1 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.5.0 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.4.3 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.4.2 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.4.1 lib/rubix/examples/simple_cluster_monitor.rb
rubix-0.4.0 lib/rubix/examples/simple_cluster_monitor.rb