Module: Rubix::ZabbixMonitor

Included in:
HttpAvailabilityMonitor
Defined in:
lib/rubix/monitors/zabbix_monitor.rb

Overview

A module for finding hosts for a monitor from Zabbix templates or host groups.

Here's an example of a monitor which makes a measurement of all hosts with Template_Foo by making a web request to the physical host.

#!/usr/bin/env ruby
# in cluster_uptime_monitor

class FooMonitor < Rubix::Monitor

  include Rubix::ZabbixMonitor

  # Define either 'template' or 'host_group' to select hosts (or
  # define 'hosts').
  def template
    'Template_Foo'
  end

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

  def measure_host host
    ...
  end

FooMonitor.run if $0 == __FILE__

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/rubix/monitors/zabbix_monitor.rb', line 36

def self.included klass
  klass.default_settings.tap do |s|
    s.define :zabbix_api_url, :description => "Zabbix API URL" ,         :required => true, :default => 'http://localhost/api_jsonrpc.php'
    s.define :username,       :description => "Username for Zabbix API", :required => true, :default => 'admin'
    s.define :password,       :description => "Password for Zabbix API", :required => true, :default => 'zabbix'
  end
end

Instance Method Details

#connect_to_zabbixObject


44
45
46
# File 'lib/rubix/monitors/zabbix_monitor.rb', line 44

def connect_to_zabbix
  Rubix.connect(settings[:zabbix_api_url], settings[:username], settings[:password])
end

#host_group_nameObject


51
52
# File 'lib/rubix/monitors/zabbix_monitor.rb', line 51

def host_group_name
end

#hostsObject


54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubix/monitors/zabbix_monitor.rb', line 54

def hosts
  connect_to_zabbix
  case
  when template_name
    template = Rubix::Template.find(:name => template_name)
    Rubix::Host.list(template.host_ids).find_all(&:monitored)
  when host_group_name
    host_group = Rubix::HostGroup.find(:name => host_group_name)
    Rubix::Host.list(host_group.host_ids).find_all(&:monitored)
  else
    raise Rubix::Error.new("Must define either a 'template_name' or a 'host_group_name' property for a Zabbix monitor.")
  end
end

#template_nameObject


48
49
# File 'lib/rubix/monitors/zabbix_monitor.rb', line 48

def template_name
end