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__

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#host_groupObject

Returns the value of attribute host_group.



36
37
38
# File 'lib/rubix/monitors/zabbix_monitor.rb', line 36

def host_group
  @host_group
end

#hostsObject

Returns the value of attribute hosts.



36
37
38
# File 'lib/rubix/monitors/zabbix_monitor.rb', line 36

def hosts
  @hosts
end

#templateObject

Returns the value of attribute template.



36
37
38
# File 'lib/rubix/monitors/zabbix_monitor.rb', line 36

def template
  @template
end

Class Method Details

.included(klass) ⇒ Object



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

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

#find_hostsObject



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rubix/monitors/zabbix_monitor.rb', line 58

def find_hosts
  case
  when template_name
    self.template = Rubix::Template.find(:name => template_name)
    self.hosts    = Rubix::Host.list(self.template.host_ids).find_all(&:monitored)
  when host_group_name
    self.host_group = Rubix::HostGroup.find(:name => host_group_name)
    self.hosts      = Rubix::Host.list(self.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

#host_group_nameObject



55
56
# File 'lib/rubix/monitors/zabbix_monitor.rb', line 55

def host_group_name
end

#initialize(settings) ⇒ Object



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

def initialize settings
  super(settings)
  Rubix.connect(settings[:zabbix_api_url], settings[:username], settings[:password])
  find_hosts
end

#template_nameObject



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

def template_name
end