Class: RZabbix::Host

Inherits:
Base
  • Object
show all
Defined in:
lib/rzabbix/host.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #initialize, perform_request, #to_json

Constructor Details

This class inherits a constructor from RZabbix::Base

Class Method Details

.create(attributes) ⇒ Object



20
21
22
23
24
# File 'lib/rzabbix/host.rb', line 20

def self.create(attributes)
  host = self.new(attributes)
  result = perform_request(:host, :create, host)
  result && result[:hostids] ? self.find(result[:hostids].first) : nil
end

.default_attributesObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rzabbix/host.rb', line 26

def self.default_attributes
  {
    #:hostid=>nil,             #int	    Host ID	
    :host=>nil,               #string	  Host name.
    :port=>10050,             #int	    Port number.	
    :status=>0,               #int	    Host Status.	
    :useip=>0,                #int	    Use IP.	
    :dns=>'',                 #string	  DNS.	
    :ip=>'0.0.0.0',           #string	  IP.	
    :proxy_hostid=> 0,        #int	    Proxy Host ID.	
    :useipmi=> 0 ,            #int	    Use IPMI.	
    :ipmi_ip=>'',             #string	  IPMAI IP.	
    :ipmi_port=>623,          #int	    IPMI port.	
    :ipmi_authtype=>0,        #int	    IPMI authentication type.	
    :ipmi_privilege=>0,       #int	    IPMI privilege.	
    :ipmi_username=>'',      #string	  IPMI username.	
    :ipmi_password=>''       #string	  IPMI password.
  }
end

.find(host_id) ⇒ Object



5
6
7
8
# File 'lib/rzabbix/host.rb', line 5

def self.find(host_id)
  hosts = perform_request(:host, :get, :hostids=>[host_id], :output=>"extend")
  self.new(hosts.first.rzbx_recursively_symbolize_keys) unless hosts.empty?
end

.find_by_hostname(hostname) ⇒ Object



15
16
17
18
# File 'lib/rzabbix/host.rb', line 15

def self.find_by_hostname(hostname)
  hosts = perform_request(:host, :get, :filter => {:host=>hostname}, :output=>"extend")
  self.new(hosts.first) unless hosts.empty?
end

.find_host_id_by_hostname(hostname) ⇒ Object



10
11
12
13
# File 'lib/rzabbix/host.rb', line 10

def self.find_host_id_by_hostname(hostname)
  hosts = perform_request(:host, :get, :filter => {:host=>hostname})
  hosts.first[:hostid]
end

Instance Method Details

#to_hash(*args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rzabbix/host.rb', line 46

def to_hash(*args)
  host_hash = self.attributes.inject({}) do |hash, (attr, v)|
    case attr.to_sym
      when :groups
        hash[:groups] = v.map {|g| { :groupid=>g.attributes[:groupid]}}
      when :templates
        hash[:templates] = v.map {|t| {:templateid=>t.attributes[:templateid]}}
      else
        hash[attr] = v
    end
    hash
  end
  host_hash
end