zabbixapi 0.5.0 → 0.5.1a

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,72 +0,0 @@
1
- class ZabbixApi
2
- class HostGroups
3
-
4
- def initialize(client)
5
- @client = client
6
- end
7
-
8
- def create(data)
9
- result = @client.api_request(:method => "hostgroup.create", :params => [data])
10
- result.empty? ? nil : result['groupids'][0].to_i
11
- end
12
-
13
- def add(data)
14
- create(data)
15
- end
16
-
17
- def delete(data)
18
- result = @client.api_request(:method => "hostgroup.delete", :params => [:groupid => data])
19
- result.empty? ? nil : result['groupids'][0].to_i
20
- end
21
-
22
- def destroy(data)
23
- delete(data)
24
- end
25
-
26
- def create_or_update(data)
27
- userid = get_id(:name => data[:name])
28
- userid ? update(data.merge(:groupid => userid)) : create(data)
29
- end
30
-
31
- def update(data)
32
- result = @client.api_request(:method => "hostgroup.update", :params => data)
33
- result ? result['groupids'][0].to_i : nil
34
- end
35
-
36
- def get_or_create(data)
37
- unless hostgroupid = get_id(data)
38
- hostgroupid = create(data)
39
- end
40
- hostgroupid
41
- end
42
-
43
- def get_full_data(data)
44
- case @client.api_version
45
- when "1.2"
46
- @client.api_request(:method => "hostgroup.get", :params => {:filter => data, :output => "extend"})
47
- else
48
- @client.api_request(:method => "hostgroup.get", :params => {:filter => data, :output => "extend"})
49
- end
50
- end
51
-
52
- # Return all hostgroups
53
- #
54
- # * *Returns* :
55
- # - Hash with {"Hostgroup1" => "id1", "Hostgroup2" => "id2"}
56
- def all
57
- result = {}
58
- @client.api_request(:method => "hostgroup.get", :params => {:output => "extend"}).each do |hostgrp|
59
- result[hostgrp['name']] = hostgrp['groupid']
60
- end
61
- result
62
- end
63
-
64
- def get_id(data)
65
- result = get_full_data(data)
66
- hostgroupid = nil
67
- result.each { |hgroup| hostgroupid = hgroup['groupid'].to_i if hgroup['name'] == data[:name] }
68
- hostgroupid
69
- end
70
-
71
- end
72
- end
@@ -1,86 +0,0 @@
1
- class ZabbixApi
2
- class Hosts
3
-
4
- def initialize(client)
5
- @client = client
6
- @host_default_options = {
7
- :host => nil,
8
- :port => 10050,
9
- :status => 1,
10
- :useip => 1,
11
- :dns => '',
12
- :ip => '0.0.0.0',
13
- :proxy_hostid => 0,
14
- :groups => [],
15
- :useipmi => 0,
16
- :ipmi_ip => '',
17
- :ipmi_port => 623,
18
- :ipmi_authtype => 0,
19
- :ipmi_privilege => 0,
20
- :ipmi_username => '',
21
- :ipmi_password => ''
22
- }
23
- end
24
-
25
- def merge_params(params)
26
- result = JSON.generate(@host_default_options).to_s + "," + JSON.generate(params).to_s
27
- JSON.parse(result.gsub('},{', ','))
28
- end
29
-
30
- def create(data)
31
- result = @client.api_request(:method => "host.create", :params => [merge_params(data)])
32
- result.empty? ? nil : result['hostids'][0].to_i
33
- end
34
-
35
- def add(data)
36
- create(data)
37
- end
38
-
39
- def unlink_templates(data)
40
- result = @client.api_request(
41
- :method => "host.massRemove",
42
- :params => {
43
- :hostids => data[:hosts_id],
44
- :templates => data[:templates_id]
45
- }
46
- )
47
- case @client.api_version
48
- when "1.2"
49
- result ? true : false
50
- else
51
- result.empty? ? false : true
52
- end
53
- end
54
-
55
- def delete(data)
56
- result = @client.api_request(:method => "host.delete", :params => [:hostid => data])
57
- result.empty? ? nil : result['hostids'][0].to_i
58
- end
59
-
60
- def destroy(data)
61
- delete(data)
62
- end
63
-
64
- def update(data)
65
- result = @client.api_request(:method => "host.update", :params => data)
66
- result.empty? ? nil : result['hostids'][0].to_i
67
- end
68
-
69
- def get_full_data(data)
70
- @client.api_request(:method => "host.get", :params => {:filter => data, :output => "extend"})
71
- end
72
-
73
- def create_or_update(data)
74
- hostid = get_id(:host => data[:host])
75
- hostid ? update(data.merge(:hostid => hostid)) : create(data)
76
- end
77
-
78
- def get_id(data)
79
- result = get_full_data(data)
80
- hostid = nil
81
- result.each { |host| hostid = host['hostid'].to_i if host['host'] == data[:host] }
82
- hostid
83
- end
84
-
85
- end
86
- end
@@ -1,87 +0,0 @@
1
- class ZabbixApi
2
- class Items
3
-
4
- def initialize(client)
5
- @client = client
6
- @item_default_options = {
7
- :description => nil,
8
- :key_ => nil,
9
- :hostid => nil,
10
- :delay => 60,
11
- :history => 60,
12
- :status => 0,
13
- :type => 7,
14
- :snmp_community => '',
15
- :snmp_oid => '',
16
- :value_type => 3,
17
- :data_type => 0,
18
- :trapper_hosts => 'localhost',
19
- :snmp_port => 161,
20
- :units => '',
21
- :multiplier => 0,
22
- :delta => 0,
23
- :snmpv3_securityname => '',
24
- :snmpv3_securitylevel => 0,
25
- :snmpv3_authpassphrase => '',
26
- :snmpv3_privpassphrase => '',
27
- :formula => 0,
28
- :trends => 365,
29
- :logtimefmt => '',
30
- :valuemapid => 0,
31
- :delay_flex => '',
32
- :authtype => 0,
33
- :username => '',
34
- :password => '',
35
- :publickey => '',
36
- :privatekey => '',
37
- :params => '',
38
- :ipmi_sensor => ''
39
- }
40
- end
41
-
42
- def merge_params(params)
43
- result = JSON.generate(@item_default_options).to_s + "," + JSON.generate(params).to_s
44
- JSON.parse(result.gsub('},{', ','))
45
- end
46
-
47
- def create(data)
48
- result = @client.api_request(:method => "item.create", :params => [merge_params(data)] )
49
- result.empty? ? nil : result['itemids'][0].to_i
50
- end
51
-
52
- def add(data)
53
- create(data)
54
- end
55
-
56
- def get_full_data(data)
57
- @client.api_request(:method => "item.get", :params => {:filter => data, :output => "extend"})
58
- end
59
-
60
- def get_id(data)
61
- result = get_full_data(data)
62
- itemid = nil
63
- result.each { |item| itemid = item['itemid'].to_i if item['name'] == data[:name] }
64
- itemid
65
- end
66
-
67
- def create_or_update(data)
68
- itemid = get_id(:description => data[:description], :hostid => data[:hostid])
69
- itemid ? update(data.merge(:itemid => itemid)) : create(data)
70
- end
71
-
72
- def update(data)
73
- result = @client.api_request(:method => "item.update", :params => data)
74
- result.empty? ? nil : result['itemids'][0].to_i
75
- end
76
-
77
- def delete(data)
78
- result = @client.api_request(:method => "item.delete", :params => [data])
79
- result.empty? ? nil : result['itemids'][0].to_i
80
- end
81
-
82
- def destroy(data)
83
- delete(data)
84
- end
85
-
86
- end
87
- end
@@ -1,109 +0,0 @@
1
- class ZabbixApi
2
- class Mediatypes
3
-
4
- def initialize(client)
5
- @client = client
6
- @default_mediatype_options = {
7
- :description => "", #Name
8
- :type => 0, #0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
9
- :smtp_server => "",
10
- :smtp_helo => "",
11
- :smtp_email => "", #Email address of Zabbix server
12
- :exec_path => "", #Name of external script
13
- :gsm_modem => "", #Serial device name of GSM modem
14
- :username => "", #Jabber user name used by Zabbix server
15
- :passwd => "" #Jabber password used by Zabbix server
16
- }
17
- end
18
-
19
- # Create MediaType
20
- #
21
- # * *Args* :
22
- # - +data+ -> Hash with :description => "MediaGroup" and mediatype options
23
- # * *Returns* :
24
- # - Nil or Integer
25
- def create(data)
26
- result = @client.api_request(:method => "mediatype.create", :params => data)
27
- result ? result['mediatypeids'][0].to_i : nil
28
- end
29
-
30
- # Add MediaType
31
- # Synonym create
32
- def add(data)
33
- create(data)
34
- end
35
-
36
- # Delete MediaType
37
- #
38
- # * *Args* :
39
- # - +data+ -> Array with mediatypeids
40
- # * *Returns* :
41
- # - Nil or Integer
42
- def delete(data)
43
- result = @client.api_request(:method => "mediatype.delete", :params => [data])
44
- result ? result['mediatypeids'][0].to_i : nil
45
- end
46
-
47
- # Destroy MediaType
48
- # Synonym delete
49
- def destroy(data)
50
- delete(data)
51
- end
52
-
53
- # Get MediaType info
54
- #
55
- # * *Args* :
56
- # - +data+ -> Hash with :description => "MediaType"
57
- # * *Returns* :
58
- # - Nil or Integer
59
- def get_full_data(data)
60
- @client.api_request(
61
- :method => "mediatype.get",
62
- :params => {
63
- :search => {:description => data[:description]},
64
- :output => "extend"
65
- }
66
- )
67
- end
68
-
69
- def get(data)
70
- get_full_data(data)
71
- end
72
-
73
- # Return MediaTypeid
74
- #
75
- # * *Args* :
76
- # - +data+ -> Hash with :description => "MediaType"
77
- # * *Returns* :
78
- # - Nil or Integer
79
- def get_id(data)
80
- result = get_full_data(data)
81
- mediatypeid = nil
82
- result.each { |mt| mediatypeid = mt['mediatypeid'].to_i if mt['description'] == data[:description] }
83
- mediatypeid
84
- end
85
-
86
- # Return MediaTypeid
87
- #
88
- # * *Args* :
89
- # - +data+ -> Hash with :description => "MediaType"
90
- # * *Returns* :
91
- # - Nil or Integer
92
- def update(data)
93
- result = @client.api_request(:method => "mediatype.update", :params => data)
94
- result.empty? ? nil : result['mediatypeids'][0].to_i
95
- end
96
-
97
- # Return MediaTypeid
98
- #
99
- # * *Args* :
100
- # - +data+ -> Hash with :name => "UserGroup"
101
- # * *Returns* :
102
- # - Integer
103
- def create_or_update(data)
104
- mediatypeid = get_id(:description => data[:description], :mediatypeid => data[:mediatypeid])
105
- mediatypeid ? update(data.merge(:mediatypeid => mediatypeid)) : create(data)
106
- end
107
-
108
- end
109
- end
@@ -1,132 +0,0 @@
1
- class ZabbixApi
2
- class Screens
3
-
4
- # extracted from frontends/php/include/defines.inc.php
5
- #SCREEN_RESOURCE_GRAPH => 0,
6
- #SCREEN_RESOURCE_SIMPLE_GRAPH => 1,
7
- #SCREEN_RESOURCE_MAP => 2,
8
- #SCREEN_RESOURCE_PLAIN_TEXT => 3,
9
- #SCREEN_RESOURCE_HOSTS_INFO => 4,
10
- #SCREEN_RESOURCE_TRIGGERS_INFO => 5,
11
- #SCREEN_RESOURCE_SERVER_INFO => 6,
12
- #SCREEN_RESOURCE_CLOCK => 7,
13
- #SCREEN_RESOURCE_SCREEN => 8,
14
- #SCREEN_RESOURCE_TRIGGERS_OVERVIEW => 9,
15
- #SCREEN_RESOURCE_DATA_OVERVIEW => 10,
16
- #SCREEN_RESOURCE_URL => 11,
17
- #SCREEN_RESOURCE_ACTIONS => 12,
18
- #SCREEN_RESOURCE_EVENTS => 13,
19
- #SCREEN_RESOURCE_HOSTGROUP_TRIGGERS => 14,
20
- #SCREEN_RESOURCE_SYSTEM_STATUS => 15,
21
- #SCREEN_RESOURCE_HOST_TRIGGERS => 16
22
-
23
- def initialize(client)
24
- @client = client
25
- @screen_default_options = {
26
- :vsize => 3
27
- }
28
- end
29
-
30
- # Create screen
31
- #
32
- # * *Args* :
33
- # - +data+ -> Hash with :name => "Screen name", hsize (rows) and vsize (columns) and array :screenitems => []
34
- # screenitems contains :resourcetype (0 - graph), :resourcetypeid (id item) and :x and :y position
35
- # * *Returns* :
36
- # - Nil or Integer
37
- def create(data)
38
- result = @client.api_request(:method => "screen.create", :params => data)
39
- result ? result['screenids'][0].to_i : nil
40
- end
41
-
42
- # Create screen
43
- # Synonym create
44
- def add(data)
45
- create(data)
46
- end
47
-
48
- # Update screen
49
- #
50
- # * *Args* :
51
- # - +data+ -> Hash with :screenid => [ "screenid" ]
52
- # * *Returns* :
53
- # - Nil or Integer
54
- def update(data)
55
- result = @client.api_request(:method => "screen.update", :params => data)
56
- result ? result['screenids'][0].to_i : nil
57
- end
58
-
59
- # Return info about screen
60
- #
61
- # * *Args* :
62
- # - +data+ -> Hash with :name => "Screen name"
63
- # * *Returns* :
64
- # - Hash with screen info
65
- def get_full_data(data)
66
- result = @client.api_request(:method => "screen.get", :params => {:search => data, :output => "extend"})
67
- result.empty? ? [] : result
68
- end
69
-
70
- # Return screenid
71
- #
72
- # * *Args* :
73
- # - +data+ -> Hash with :name => "Screen name"
74
- # * *Returns* :
75
- # - Nil or Integer
76
- def get_id(data)
77
- result = get_full_data(data)
78
- screenid = nil
79
- result.each { |screen| screenid = screen['screenid'].to_i if screen['name'] == data[:name] }
80
- screenid
81
- end
82
-
83
- # Delete screen
84
- #
85
- # * *Args* :
86
- # - +data+ -> Hash with :params => [screenid]
87
- # * *Returns* :
88
- # - Nil or Integer
89
- def delete(data)
90
- result = @client.api_request(:method => "screen.delete", :params => data)
91
- result.empty? ? nil : result['screenids'][0].to_i
92
- end
93
-
94
- # Create screen all graphs for host
95
- #
96
- # * *Args* :
97
- # - +data+ -> Hash with :host=> "hostname", :graphsid => [], [:hsize, :vsize, :valign, :halign]
98
- # * *Returns* :
99
- # - Nil or Integer
100
- def get_or_create_for_host(data)
101
- screen_name = data[:host].to_s + "_graphs"
102
- graphids = data[:graphids]
103
- screenitems = []
104
- hsize = data[:hsize] || 3
105
- valign = data[:valign] || 2
106
- halign = data[:halign] || 2
107
- vsize = data[:vsize] || ((graphids.size/hsize) + 1).to_i
108
- screenid = get_id(:name => screen_name)
109
- unless screenid
110
- # Create screen
111
- graphids.each_with_index do |graphid, index|
112
- screenitems << {
113
- :resourcetype => 0,
114
- :resourceid => graphid,
115
- :x => (index % hsize).to_i,
116
- :y => (index % graphids.size/hsize).to_i,
117
- :valign =>valign,
118
- :halign =>halign
119
- }
120
- end
121
- screenid = create(
122
- :name => screen_name,
123
- :hsize => hsize,
124
- :vsize => vsize,
125
- :screenitems => screenitems
126
- )
127
- end
128
- screenid
129
- end
130
-
131
- end
132
- end