Class: ZabbixConf::Configure

Inherits:
Object
  • Object
show all
Defined in:
lib/zabbix_conf/configure.rb

Instance Method Summary collapse

Instance Method Details

#add_tempalte_to_host(client, config = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/zabbix_conf/configure.rb', line 35

def add_tempalte_to_host(client, config={})
  server = config[:server]
  agent  = config[:agent]

  template_ids = [get_template(client, config)]

  Timeout::timeout(TIMEOUT) {
    client.templates.mass_add(
      :hosts_id     => [client.hosts.get_id(:host => agent['fqdn'])],
      :templates_id => template_ids
    )
  }
end

#config_agent(options = {}, config = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/zabbix_conf/configure.rb', line 78

def config_agent(options={}, config={})
  server = config[:server]
  agent = config[:agent]

  zbx = zab_client(config)
  host = create_host(zbx, config)
  add_tempalte_to_host(zbx, config)
  
  puts 'Done configuring agent'
end

#config_server(options = {}, config = {}) ⇒ Object



72
73
74
75
76
# File 'lib/zabbix_conf/configure.rb', line 72

def config_server(options={}, config={})
  server = config[:server]
  agent  = config[:agent]

end

#create_host(client, config = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/zabbix_conf/configure.rb', line 49

def create_host(client, config={})
  server = config[:server]
  agent  = config[:agent]

  hostgroup = create_hostgroup(client, config)

  Timeout::timeout(TIMEOUT) {
    client.hosts.create_or_update(
      :host => agent['fqdn'],
      :interfaces => [{
        :type  => TYPE_AGENT,
        :main  => YES,
        :ip    => agent['ip'],
        :dns   => agent['fqdn'],
        :port  => AGENT_PORT,
        :useip => YES 
      }],
      :groups => [:groupid => hostgroup]
    )
  }
end

#create_hostgroup(client, config = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/zabbix_conf/configure.rb', line 26

def create_hostgroup(client, config={})
  server = config[:server]
  agent  = config[:agent]
  
  Timeout::timeout(TIMEOUT) {
    client.hostgroups.get_or_create(:name => agent['hostgroup'])
  }
end

#get_template(client, config = {}) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/zabbix_conf/configure.rb', line 17

def get_template(client, config={})
  server = config[:server]
  agent  = config[:agent]

  Timeout::timeout(TIMEOUT) {
    client.templates.get_id(:host => agent['template'])
  }
end

#zab_client(config = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/zabbix_conf/configure.rb', line 3

def zab_client(config={})
  server     = config[:server]
  agent      = config[:agent]
  server_url = "http://#{server['ip']}/zabbix/api_jsonrpc.php"

  Timeout::timeout(TIMEOUT) {
    ZabbixApi.connect( 
      :url      => server_url,
      :user     => server['user'],
      :password => server['pass']
    )
  }
end