Class: Templates

Inherits:
Base
  • Object
show all
Defined in:
lib/zapix/proxies/templates.rb

Defined Under Namespace

Classes: NonExistingTemplate

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Base

Instance Method Details

#create(options) ⇒ Object



13
14
15
# File 'lib/zapix/proxies/templates.rb', line 13

def create(options)
  client.template_create(options) unless exists?(options['host'])
end

#exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
# File 'lib/zapix/proxies/templates.rb', line 4

def exists?(name)
  result = client.template_get({'filter' => {'name' => name}})
  if (result == nil || result.empty?)
    false
  else
    true
  end
end

#get_id(name) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/zapix/proxies/templates.rb', line 17

def get_id(name)
  if(exists?(name))
    client.template_get({'filter' => {'name' => name}}).first['templateid']
  else
    raise NonExistingTemplate, "Template #{name} does not exist !"
  end
end

#get_templates_for_host(id) ⇒ Object



25
26
27
# File 'lib/zapix/proxies/templates.rb', line 25

def get_templates_for_host(id)
  client.template_get({'hostids' => [id]}).map { |result_set| result_set['templateid'] }
end