Class: RZabbix::Host
- Inherits:
-
Base
- Object
- Base
- RZabbix::Host
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_attributes ⇒ Object
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
{
:host=>nil, :port=>10050, :status=>0, :useip=>0, :dns=>'', :ip=>'0.0.0.0', :proxy_hostid=> 0, :useipmi=> 0 , :ipmi_ip=>'', :ipmi_port=>623, :ipmi_authtype=>0, :ipmi_privilege=>0, :ipmi_username=>'', :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
|