zabbixapi 0.1.4 → 0.1.5a1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -3
- data/examples/config.yml +4 -0
- data/examples/zabbix_availability +73 -0
- data/examples/zabbix_disk_io +152 -0
- data/examples/zabbix_filesystem +249 -0
- data/examples/zabbix_la +101 -0
- data/examples/zabbix_memory +276 -0
- data/examples/zabbix_net +82 -0
- data/lib/{application.rb → zabbixapi/application.rb} +25 -4
- data/lib/zabbixapi/base.rb +133 -0
- data/lib/{graph.rb → zabbixapi/graph.rb} +8 -10
- data/lib/zabbixapi/group.rb +78 -0
- data/lib/zabbixapi/host.rb +86 -0
- data/lib/zabbixapi/item.rb +169 -0
- data/lib/zabbixapi/screen.rb +166 -0
- data/lib/{template.rb → zabbixapi/template.rb} +22 -26
- data/lib/zabbixapi/trigger.rb +95 -0
- data/lib/zabbixapi/usermacro.rb +74 -0
- data/lib/zabbixapi.rb +10 -10
- data/spec/item.rb +60 -0
- data/zabbixapi.gemspec +4 -5
- metadata +39 -49
- data/lib/base.rb +0 -126
- data/lib/group.rb +0 -78
- data/lib/host.rb +0 -98
- data/lib/item.rb +0 -128
- data/lib/screen.rb +0 -169
- data/lib/trigger.rb +0 -98
- data/lib/usermacro.rb +0 -75
data/lib/item.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
module Zabbix
|
2
|
-
class ZabbixApi
|
3
|
-
def add_item(item)
|
4
|
-
|
5
|
-
item_options = {
|
6
|
-
'description' => nil,
|
7
|
-
'key_' => nil,
|
8
|
-
'hostid' => nil,
|
9
|
-
'delay' => 60,
|
10
|
-
'history' => 60,
|
11
|
-
'status' => 0,
|
12
|
-
'type' => 7,
|
13
|
-
'snmp_community' => '',
|
14
|
-
'snmp_oid' => '',
|
15
|
-
'value_type' => 3,
|
16
|
-
'data_type' => 0,
|
17
|
-
'trapper_hosts' => 'localhost',
|
18
|
-
'snmp_port' => 161,
|
19
|
-
'units' => '',
|
20
|
-
'multiplier' => 0,
|
21
|
-
'delta' => 0,
|
22
|
-
'snmpv3_securityname' => '',
|
23
|
-
'snmpv3_securitylevel' => 0,
|
24
|
-
'snmpv3_authpassphrase' => '',
|
25
|
-
'snmpv3_privpassphrase' => '',
|
26
|
-
'formula' => 0,
|
27
|
-
'trends' => 365,
|
28
|
-
'logtimefmt' => '',
|
29
|
-
'valuemapid' => 0,
|
30
|
-
'delay_flex' => '',
|
31
|
-
'authtype' => 0,
|
32
|
-
'username' => '',
|
33
|
-
'password' => '',
|
34
|
-
'publickey' => '',
|
35
|
-
'privatekey' => '',
|
36
|
-
'params' => '',
|
37
|
-
'ipmi_sensor' => '',
|
38
|
-
'applications' => '',
|
39
|
-
'templateid' => 0
|
40
|
-
}
|
41
|
-
|
42
|
-
|
43
|
-
item_options.merge!(item)
|
44
|
-
|
45
|
-
message = {
|
46
|
-
'method' => 'item.create',
|
47
|
-
'params' => [ item_options ]
|
48
|
-
}
|
49
|
-
|
50
|
-
|
51
|
-
responce = send_request(message)
|
52
|
-
|
53
|
-
unless ( responce.empty? ) then
|
54
|
-
result = responce['itemids'][0]
|
55
|
-
else
|
56
|
-
result = nil
|
57
|
-
end
|
58
|
-
|
59
|
-
return result
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
def get_webitem_id(host_id, item_name)
|
64
|
-
message = {
|
65
|
-
'method' => 'item.get',
|
66
|
-
'params' => {
|
67
|
-
'filter' => {
|
68
|
-
'hostid' => host_id,
|
69
|
-
'type' => 9,
|
70
|
-
'key_' => "web.test.time[eva.ru,Get main page,resp]"
|
71
|
-
},
|
72
|
-
'webitems' => 1
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
responce = send_request(message)
|
77
|
-
|
78
|
-
p responce
|
79
|
-
|
80
|
-
unless ( responce.empty? ) then
|
81
|
-
result = responce[0]['itemid']
|
82
|
-
else
|
83
|
-
result = nil
|
84
|
-
end
|
85
|
-
|
86
|
-
return result
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
def get_item_id(host_id, item_name)
|
91
|
-
message = {
|
92
|
-
'method' => 'item.get',
|
93
|
-
'params' => {
|
94
|
-
'filter' => {
|
95
|
-
'hostid' => host_id,
|
96
|
-
'description' => item_name
|
97
|
-
}
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
responce = send_request(message)
|
102
|
-
|
103
|
-
unless ( responce.empty? ) then
|
104
|
-
result = responce[0]['itemid']
|
105
|
-
else
|
106
|
-
result = nil
|
107
|
-
end
|
108
|
-
|
109
|
-
return result
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
def update_item(item_id)
|
114
|
-
|
115
|
-
message = {
|
116
|
-
'method' => 'item.update',
|
117
|
-
'params' => {
|
118
|
-
'itemid' => item_id,
|
119
|
-
'status' => 0
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
responce = send_request(message)
|
124
|
-
|
125
|
-
p responce
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
data/lib/screen.rb
DELETED
@@ -1,169 +0,0 @@
|
|
1
|
-
module Zabbix
|
2
|
-
class ZabbixApi
|
3
|
-
|
4
|
-
def get_screen_id(screen_name)
|
5
|
-
|
6
|
-
message = {
|
7
|
-
'method' => 'screen.get',
|
8
|
-
'params' => {
|
9
|
-
'filter' => {
|
10
|
-
'name' => screen_name
|
11
|
-
}
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
responce = send_request(message)
|
16
|
-
|
17
|
-
if not ( responce.empty? ) then
|
18
|
-
result = responce[0]['screenid']
|
19
|
-
else
|
20
|
-
result = nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_screen_parameter(screen_name, param_name)
|
25
|
-
|
26
|
-
message = {
|
27
|
-
'method' => 'screen.get',
|
28
|
-
'params' => {
|
29
|
-
'extendoutput' => '1',
|
30
|
-
'filter' => {
|
31
|
-
'name' => screen_name
|
32
|
-
}
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
|
37
|
-
responce = send_request(message)
|
38
|
-
|
39
|
-
if not ( responce.empty? ) then
|
40
|
-
result = responce[0][param_name]
|
41
|
-
else
|
42
|
-
result nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def get_screen_graph_ids(screen_id)
|
47
|
-
|
48
|
-
message = {
|
49
|
-
'method' => 'screen.get',
|
50
|
-
'params' => {
|
51
|
-
'extendoutput' => '1',
|
52
|
-
'select_screenitems' => '1',
|
53
|
-
'screenids' => [ screen_id ]
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
responce = send_request(message)
|
58
|
-
|
59
|
-
p responce
|
60
|
-
|
61
|
-
unless ( responce.empty?) then
|
62
|
-
result = []
|
63
|
-
screenitems = responce[0]['screenitems']
|
64
|
-
screenitems.each() do |item|
|
65
|
-
if ( item['resourcetype'].to_i == 0 ) then
|
66
|
-
result << item['resourceid']
|
67
|
-
end
|
68
|
-
end
|
69
|
-
else
|
70
|
-
result = nil
|
71
|
-
end
|
72
|
-
|
73
|
-
return result
|
74
|
-
end
|
75
|
-
|
76
|
-
def set_screen_parameter(screen_id, param_name, param_value)
|
77
|
-
|
78
|
-
message = {
|
79
|
-
'method' => 'screen.update',
|
80
|
-
'params' => {
|
81
|
-
param_name => param_value,
|
82
|
-
'screenid' => screen_id
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
responce = send_request(message)
|
87
|
-
|
88
|
-
if not ( responce.empty? ) then
|
89
|
-
result = true
|
90
|
-
else
|
91
|
-
result = false
|
92
|
-
end
|
93
|
-
|
94
|
-
return result
|
95
|
-
end
|
96
|
-
|
97
|
-
def del_all_graphs_from_screen(screen_id)
|
98
|
-
|
99
|
-
message = {
|
100
|
-
'method' => 'screen.deleteItems',
|
101
|
-
'params' => {
|
102
|
-
'screenids' => [ screen_id ],
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
responce = send_request(message)
|
107
|
-
|
108
|
-
if ( responce ) then
|
109
|
-
return responce
|
110
|
-
else
|
111
|
-
return nil
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def add_graph_to_screen(screen_id, graph_id, x, y)
|
116
|
-
|
117
|
-
message = {
|
118
|
-
'method' => 'screen.addItems',
|
119
|
-
'params' => {
|
120
|
-
'screenids' => [ screen_id ],
|
121
|
-
'screenitems' => [
|
122
|
-
{
|
123
|
-
'resourcetype' => 'graph',
|
124
|
-
'resourceid' => graph_id,
|
125
|
-
'width' => '800',
|
126
|
-
'height' => '200',
|
127
|
-
'x' => x,
|
128
|
-
'y' => y,
|
129
|
-
'valign' => 'Middle',
|
130
|
-
'halign' => 'Centre',
|
131
|
-
'colspan' => '0',
|
132
|
-
'rowspan' => '0',
|
133
|
-
'elements' => '0',
|
134
|
-
'dynamic' => '0',
|
135
|
-
'url' => '0',
|
136
|
-
'style' => '0'
|
137
|
-
}
|
138
|
-
]
|
139
|
-
}
|
140
|
-
}
|
141
|
-
|
142
|
-
responce = send_request(message)
|
143
|
-
|
144
|
-
return responce
|
145
|
-
end
|
146
|
-
|
147
|
-
def add_screen(screen_name, hsize, vsize)
|
148
|
-
|
149
|
-
message = {
|
150
|
-
'method' => 'screen.create',
|
151
|
-
'params' => {
|
152
|
-
'name' => screen_name,
|
153
|
-
'hsize' => hsize,
|
154
|
-
'vsize' => vsize
|
155
|
-
}
|
156
|
-
}
|
157
|
-
|
158
|
-
responce = send_request(message)
|
159
|
-
|
160
|
-
if not ( responce.empty? ) then
|
161
|
-
result = responce['screenids'][0]
|
162
|
-
else
|
163
|
-
result = nil
|
164
|
-
end
|
165
|
-
|
166
|
-
return result
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
data/lib/trigger.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
module Zabbix
|
2
|
-
class ZabbixApi
|
3
|
-
|
4
|
-
def add_trigger(trigger)
|
5
|
-
|
6
|
-
message = {
|
7
|
-
'method' => 'trigger.create',
|
8
|
-
'params' => [ trigger ]
|
9
|
-
}
|
10
|
-
|
11
|
-
|
12
|
-
responce = send_request(message)
|
13
|
-
|
14
|
-
|
15
|
-
unless ( responce.empty? ) then
|
16
|
-
result = responce['triggerids'][0]
|
17
|
-
else
|
18
|
-
result = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
return result
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def get_trigger_id(host_id, trigger_name)
|
27
|
-
|
28
|
-
message = {
|
29
|
-
'method' => 'trigger.get',
|
30
|
-
'params' => {
|
31
|
-
'filter' => {
|
32
|
-
'hostid' => host_id,
|
33
|
-
'description' => trigger_name
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
responce = send_request(message)
|
39
|
-
|
40
|
-
unless ( responce.empty? ) then
|
41
|
-
result = responce[0]['triggerid']
|
42
|
-
else
|
43
|
-
result = nil
|
44
|
-
end
|
45
|
-
|
46
|
-
return result
|
47
|
-
end
|
48
|
-
|
49
|
-
def get_triggers_by_host(host_id)
|
50
|
-
|
51
|
-
message = {
|
52
|
-
'method' => 'trigger.get',
|
53
|
-
'params' => {
|
54
|
-
'filter' => {
|
55
|
-
'hostid' => host_id,
|
56
|
-
},
|
57
|
-
'extendoutput' => '1'
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
responce = send_request(message)
|
62
|
-
|
63
|
-
unless ( responce.empty? ) then
|
64
|
-
result = {}
|
65
|
-
responce.each do |trigger|
|
66
|
-
trigger_id = trigger['triggerid']
|
67
|
-
description = trigger['description']
|
68
|
-
result[trigger_id] = description
|
69
|
-
end
|
70
|
-
else
|
71
|
-
result = {}
|
72
|
-
end
|
73
|
-
|
74
|
-
return result
|
75
|
-
end
|
76
|
-
|
77
|
-
def update_trigger_status(trigger_id, status)
|
78
|
-
|
79
|
-
message = {
|
80
|
-
'method' => 'trigger.update_status',
|
81
|
-
'params' => {
|
82
|
-
'triggerid' => trigger_id,
|
83
|
-
'status' => status
|
84
|
-
}
|
85
|
-
}
|
86
|
-
|
87
|
-
responce = send_request(message)
|
88
|
-
|
89
|
-
unless ( responce.empty? ) then
|
90
|
-
result = responce['triggerids'][0]
|
91
|
-
else
|
92
|
-
result = nil
|
93
|
-
end
|
94
|
-
|
95
|
-
return result
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
data/lib/usermacro.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
module Zabbix
|
2
|
-
|
3
|
-
class ZabbixApi
|
4
|
-
def add_macro(host_id, macro_name, macro_value)
|
5
|
-
|
6
|
-
message = {
|
7
|
-
'method' => 'Usermacro.create',
|
8
|
-
'params' => {
|
9
|
-
'hostid' => host_id,
|
10
|
-
'macro' => macro_name,
|
11
|
-
'value'=> macro_value
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
responce = send_request(message)
|
16
|
-
|
17
|
-
if ( hostmacroids = responce['hostmacroids'] ) then
|
18
|
-
result = hostmacroids
|
19
|
-
else
|
20
|
-
result = nil
|
21
|
-
end
|
22
|
-
|
23
|
-
return result
|
24
|
-
end
|
25
|
-
|
26
|
-
def get_macro(host_id, macro_name)
|
27
|
-
|
28
|
-
message = {
|
29
|
-
'method' => 'Usermacro.get',
|
30
|
-
'params' => {
|
31
|
-
'hostids' => host_id,
|
32
|
-
'macros' => macro_name,
|
33
|
-
'extendoutput' => '1'
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
responce = send_request(message)
|
38
|
-
|
39
|
-
if not ( responce.empty?) then
|
40
|
-
if ( hostmacroid = responce[0]['hostmacroid'] ) then
|
41
|
-
macro_id = hostmacroid
|
42
|
-
macro_value = responce[0]['value']
|
43
|
-
|
44
|
-
result = {
|
45
|
-
'id' => macro_id,
|
46
|
-
'value'=> macro_value
|
47
|
-
}
|
48
|
-
else
|
49
|
-
result = nil
|
50
|
-
end
|
51
|
-
else
|
52
|
-
result = nil
|
53
|
-
end
|
54
|
-
|
55
|
-
return result
|
56
|
-
end
|
57
|
-
|
58
|
-
def set_macro_value(host_id, macro_name, macro_value)
|
59
|
-
|
60
|
-
message = {
|
61
|
-
'method' => 'usermacro.updateValue',
|
62
|
-
'params' => {
|
63
|
-
'hostid' => host_id,
|
64
|
-
'macro' => macro_name,
|
65
|
-
'value' => macro_value
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
responce = send_request(message)
|
70
|
-
|
71
|
-
# Проверять ответ бесполезно. В ответ всегда возвращается запрос.
|
72
|
-
return true
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|