Class: Zabby::ZObject

Inherits:
Object
  • Object
show all
Defined in:
lib/zabby/zobject.rb

Overview

Definition of the Zabbix Objects as provided by the Zabbix API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zname, zmethods) ⇒ ZObject

Define the Zabbix object name and associated methods

Parameters:

  • zname (String)

    Zabbix Object name

  • zmethods (Array)

    List of associated methods



15
16
17
18
# File 'lib/zabby/zobject.rb', line 15

def initialize(zname, zmethods)
  @zname = zname
  @zmethods = zmethods.map { |f| f.to_sym }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(zmethod, *args, &block) ⇒ Object

Simulate methods on the object. For example: “host.get”, “item.create”.. The instance variable @zmethods is the list of valid methods.



23
24
25
26
27
28
29
# File 'lib/zabby/zobject.rb', line 23

def method_missing(zmethod, *args, &block)
  if @zmethods.include? zmethod
    Zabby::Runner.instance.connection.perform_request(@zname, zmethod, args.first)
  else
    super
  end
end

Instance Attribute Details

#zmethodsObject (readonly)

Returns the value of attribute zmethods.



9
10
11
# File 'lib/zabby/zobject.rb', line 9

def zmethods
  @zmethods
end

#znameObject (readonly)

Returns the value of attribute zname.



9
10
11
# File 'lib/zabby/zobject.rb', line 9

def zname
  @zname
end