zabbixapi 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +20 -0
- data/README.md +123 -0
- data/Rakefile +1 -0
- data/lib/zabbixapi/applications.rb +37 -0
- data/lib/zabbixapi/client.rb +65 -0
- data/lib/zabbixapi/errors.rb +12 -0
- data/lib/zabbixapi/graphs.rb +47 -0
- data/lib/zabbixapi/hostgroups.rb +42 -0
- data/lib/zabbixapi/hosts.rb +80 -0
- data/lib/zabbixapi/items.rb +81 -0
- data/lib/zabbixapi/server.rb +12 -0
- data/lib/zabbixapi/templates.rb +78 -0
- data/lib/zabbixapi/triggers.rb +42 -0
- data/lib/zabbixapi/users.rb +59 -0
- data/lib/zabbixapi/version.rb +3 -0
- data/lib/zabbixapi.rb +51 -12
- data/spec/localhost.rb +227 -75
- data/spec/run.rb +265 -0
- data/zabbixapi.gemspec +15 -15
- metadata +35 -57
- data/README.rdoc +0 -65
- data/examples/basic_auth.rb +0 -30
- data/examples/config.yml +0 -4
- data/examples/maintenance-example.rb +0 -55
- data/examples/populate_new_zabbix.sh +0 -84
- data/examples/zabbix_availability +0 -73
- data/examples/zabbix_clear_default +0 -36
- data/examples/zabbix_cpufan-sersor +0 -114
- data/examples/zabbix_cputemp-sersor +0 -112
- data/examples/zabbix_disk_io +0 -152
- data/examples/zabbix_filesystem +0 -249
- data/examples/zabbix_group +0 -25
- data/examples/zabbix_hlsp +0 -100
- data/examples/zabbix_host +0 -37
- data/examples/zabbix_iops +0 -131
- data/examples/zabbix_ipmi-cpufan-sersor +0 -101
- data/examples/zabbix_ipmi_systemp +0 -110
- data/examples/zabbix_la +0 -136
- data/examples/zabbix_mailer +0 -125
- data/examples/zabbix_mdadm +0 -72
- data/examples/zabbix_megaraid +0 -71
- data/examples/zabbix_memory +0 -290
- data/examples/zabbix_named +0 -71
- data/examples/zabbix_net +0 -218
- data/examples/zabbix_nginx +0 -167
- data/examples/zabbix_nginx_500 +0 -112
- data/examples/zabbix_ntp +0 -71
- data/examples/zabbix_nv-gputemp +0 -111
- data/examples/zabbix_pgsql +0 -125
- data/examples/zabbix_server_process +0 -71
- data/examples/zabbix_smart_blade +0 -94
- data/examples/zabbix_ssh +0 -71
- data/examples/zabbix_varnish +0 -71
- data/lib/zabbixapi/application.rb +0 -40
- data/lib/zabbixapi/base.rb +0 -158
- data/lib/zabbixapi/graph.rb +0 -59
- data/lib/zabbixapi/group.rb +0 -66
- data/lib/zabbixapi/host.rb +0 -70
- data/lib/zabbixapi/item.rb +0 -130
- data/lib/zabbixapi/maintenance.rb +0 -78
- data/lib/zabbixapi/mediatype.rb +0 -53
- data/lib/zabbixapi/screen.rb +0 -119
- data/lib/zabbixapi/template.rb +0 -128
- data/lib/zabbixapi/trigger.rb +0 -71
- data/lib/zabbixapi/user.rb +0 -0
- data/lib/zabbixapi/usermacro.rb +0 -46
data/examples/zabbix_filesystem
DELETED
@@ -1,249 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'getopt/std'
|
5
|
-
require 'yaml'
|
6
|
-
require 'zabbixapi'
|
7
|
-
|
8
|
-
opt = Getopt::Std.getopts("m:g:E:")
|
9
|
-
|
10
|
-
mount_point = opt["m"]
|
11
|
-
group_name = opt["g"]
|
12
|
-
zabbix_env = opt["E"]
|
13
|
-
|
14
|
-
if ( mount_point == "/" )
|
15
|
-
template_name = "TMPL_Filesystem_root"
|
16
|
-
app_name = "Filesystem_root"
|
17
|
-
else
|
18
|
-
mount_point = mount_point.sub(/\/$/, "")
|
19
|
-
template_name = "TMPL_Filesystem" + mount_point.gsub(/\//, "_")
|
20
|
-
app_name = "Filesystem" + mount_point.gsub(/\//, "_")
|
21
|
-
end
|
22
|
-
|
23
|
-
# read config
|
24
|
-
config = YAML::load(open('./config.yml'))
|
25
|
-
|
26
|
-
api_url = config[zabbix_env]["api_url"]
|
27
|
-
api_login = config[zabbix_env]["api_login"]
|
28
|
-
api_password = config[zabbix_env]["api_password"]
|
29
|
-
|
30
|
-
# Esablish new connection
|
31
|
-
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
32
|
-
|
33
|
-
# Create new template
|
34
|
-
p " * Creating template #{template_name}."
|
35
|
-
g_id = zbx.add_or_get_group(group_name)
|
36
|
-
|
37
|
-
options = {
|
38
|
-
'groups' => [ g_id.to_i ],
|
39
|
-
'host' => template_name
|
40
|
-
}
|
41
|
-
|
42
|
-
t_id = zbx.add_or_get_template(options)
|
43
|
-
|
44
|
-
# Create application #{app_name}
|
45
|
-
p " ** Create application #{app_name}."
|
46
|
-
application = {
|
47
|
-
'hostid' => t_id.to_i,
|
48
|
-
'name' => app_name
|
49
|
-
}
|
50
|
-
|
51
|
-
a_id = zbx.add_or_get_application(t_id, application)
|
52
|
-
|
53
|
-
# Total disk space on #{mount_point}
|
54
|
-
options = {
|
55
|
-
'description' => "Total disk space on #{mount_point}",
|
56
|
-
'key_' => "vfs.fs.size[#{mount_point},total]",
|
57
|
-
'hostid' => t_id.to_i,
|
58
|
-
'applications' => [ a_id.to_i ],
|
59
|
-
'units' => 'B',
|
60
|
-
'history' => 7,
|
61
|
-
'trends' => 30,
|
62
|
-
'delay' => 600,
|
63
|
-
'value_type' => 3
|
64
|
-
}
|
65
|
-
|
66
|
-
p " ** Add 'Total disk space on #{mount_point}' to #{template_name}."
|
67
|
-
total_in_b_item_id = zbx.add_or_get_item(t_id, options)
|
68
|
-
|
69
|
-
# Used disk space on #{mount_point}
|
70
|
-
options = {
|
71
|
-
'description' => "Used disk space on #{mount_point}",
|
72
|
-
'key_' => "vfs.fs.size[#{mount_point},used]",
|
73
|
-
'hostid' => t_id.to_i,
|
74
|
-
'applications' => [ a_id.to_i ],
|
75
|
-
'units' => 'B',
|
76
|
-
'history' => 7,
|
77
|
-
'trends' => 30,
|
78
|
-
'delay' => 60,
|
79
|
-
'value_type' => 3
|
80
|
-
}
|
81
|
-
|
82
|
-
p " ** Add 'Used disk space on #{mount_point}' to #{template_name}."
|
83
|
-
used_in_b_item_id = zbx.add_or_get_item(t_id, options)
|
84
|
-
|
85
|
-
# Use disk space on #{mount_point} in %
|
86
|
-
options = {
|
87
|
-
'description' => "Used disk space on #{mount_point} in %",
|
88
|
-
'key_' => "vfs.fs.size[#{mount_point},pused]",
|
89
|
-
'hostid' => t_id.to_i,
|
90
|
-
'applications' => [ a_id.to_i ],
|
91
|
-
'history' => 7,
|
92
|
-
'trends' => 30,
|
93
|
-
'delay' => 60,
|
94
|
-
'value_type' => 0
|
95
|
-
}
|
96
|
-
|
97
|
-
p " ** Add 'Used disk space on #{mount_point} in %' to #{template_name}."
|
98
|
-
i_id = zbx.add_or_get_item(t_id, options)
|
99
|
-
|
100
|
-
# Free disk space on #{mount_point}
|
101
|
-
options = {
|
102
|
-
'description' => "Free disk space on #{mount_point}",
|
103
|
-
'type' => '15', # calculated
|
104
|
-
'key_' => "vfs.fs.size[#{mount_point},free]",
|
105
|
-
'params' => "last(\"vfs.fs.size[#{mount_point},total]\") - last(\"vfs.fs.size[#{mount_point},used]\")",
|
106
|
-
'hostid' => t_id.to_i,
|
107
|
-
'applications' => [ a_id.to_i ],
|
108
|
-
'units' => 'B',
|
109
|
-
'history' => 7,
|
110
|
-
'trends' => 30,
|
111
|
-
'delay' => 60,
|
112
|
-
'value_type' => 3
|
113
|
-
}
|
114
|
-
|
115
|
-
p " ** Add 'Free disk space on #{mount_point}' to #{template_name}."
|
116
|
-
i_id = zbx.add_or_get_item(t_id, options)
|
117
|
-
|
118
|
-
# Free disk space on #{mount_point} in %
|
119
|
-
options = {
|
120
|
-
'description' => "Free disk space on #{mount_point} in %",
|
121
|
-
'type' => '15', # calculated
|
122
|
-
'key_' => "vfs.fs.size[#{mount_point},pfree]",
|
123
|
-
'params' => "100 - last(\"vfs.fs.size[#{mount_point},pused]\")",
|
124
|
-
'hostid' => t_id.to_i,
|
125
|
-
'applications' => [ a_id.to_i ],
|
126
|
-
'history' => 7,
|
127
|
-
'trends' => 30,
|
128
|
-
'delay' => 60,
|
129
|
-
'value_type' => 0
|
130
|
-
}
|
131
|
-
|
132
|
-
p " ** Add 'Free disk space on #{mount_point} in %' to #{template_name}."
|
133
|
-
i_id = zbx.add_or_get_item(t_id, options)
|
134
|
-
|
135
|
-
# Free number of inodes on #{mount_point}
|
136
|
-
options = {
|
137
|
-
'description' => "Free number of inodes on #{mount_point}",
|
138
|
-
'key_' => "vfs.fs.inode[#{mount_point},free]",
|
139
|
-
'hostid' => t_id.to_i,
|
140
|
-
'applications' => [ a_id.to_i ],
|
141
|
-
'units' => '',
|
142
|
-
'history' => 7,
|
143
|
-
'trends' => 30,
|
144
|
-
'delay' => 60,
|
145
|
-
'value_type' => 3
|
146
|
-
}
|
147
|
-
|
148
|
-
p " ** Add 'Free number of inodes on #{mount_point}' to #{template_name}."
|
149
|
-
i_id = zbx.add_or_get_item(t_id, options)
|
150
|
-
|
151
|
-
# Free number of inodes on #{mount_point} in %
|
152
|
-
options = {
|
153
|
-
'description' => "Free number of inodes on #{mount_point} in %",
|
154
|
-
'key_' => "vfs.fs.inode[#{mount_point},pfree]",
|
155
|
-
'hostid' => t_id.to_i,
|
156
|
-
'applications' => [ a_id.to_i ],
|
157
|
-
'history' => 7,
|
158
|
-
'trends' => 30,
|
159
|
-
'delay' => 60,
|
160
|
-
'value_type' => 0
|
161
|
-
}
|
162
|
-
|
163
|
-
p " ** Add 'Free number of inodes on #{mount_point} in %' to #{template_name}."
|
164
|
-
i_id = zbx.add_or_get_item(t_id, options)
|
165
|
-
|
166
|
-
## TRIGGERS
|
167
|
-
options = {
|
168
|
-
'description' => "Free disk space on #{mount_point}",
|
169
|
-
'expression' => "{#{template_name}:vfs.fs.size[#{mount_point},pfree].last(0)}<15",
|
170
|
-
'priority' => 2, # warning
|
171
|
-
'templateid' => 0,
|
172
|
-
'comments' => "Free disk space on #{mount_point} (warning)",
|
173
|
-
'type' => 0,
|
174
|
-
'status' => '0'
|
175
|
-
}
|
176
|
-
|
177
|
-
p " ** Add 'Free disk space on #{mount_point} warning trigger'"
|
178
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
179
|
-
|
180
|
-
options = {
|
181
|
-
'description' => "Free disk space on #{mount_point}",
|
182
|
-
'expression' => "{#{template_name}:vfs.fs.size[#{mount_point},pfree].last(0)}<10",
|
183
|
-
'priority' => 5, # Disaster
|
184
|
-
'templateid' => 0,
|
185
|
-
'comments' => "Free disk space on #{mount_point} (disaster)",
|
186
|
-
'type' => 0,
|
187
|
-
'status' => 0
|
188
|
-
}
|
189
|
-
|
190
|
-
p " ** Add 'Free disk space on #{mount_point} disaster trigger'"
|
191
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
192
|
-
|
193
|
-
options = {
|
194
|
-
'description' => "Free inodes on #{mount_point}",
|
195
|
-
'expression' => "{#{template_name}:vfs.fs.inode[#{mount_point},pfree].last(0)}<15",
|
196
|
-
'priority' => 2, # warning
|
197
|
-
'templateid' => '0',
|
198
|
-
'comments' => "Free disk inodes on #{mount_point} (warning)",
|
199
|
-
'type' => 0,
|
200
|
-
'status' => '0'
|
201
|
-
}
|
202
|
-
|
203
|
-
p " ** Add 'Free inodes on #{mount_point} warning trigger'"
|
204
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
205
|
-
|
206
|
-
options = {
|
207
|
-
'description' => "Free inodes on #{mount_point}",
|
208
|
-
'expression' => "{#{template_name}:vfs.fs.inode[#{mount_point},pfree].last(0)}<10",
|
209
|
-
'priority' => 5, #disaster
|
210
|
-
'templateid' => '0',
|
211
|
-
'comments' => "Free disk inodes on #{mount_point} (disaster)",
|
212
|
-
'type' => 0,
|
213
|
-
'status' => '0'
|
214
|
-
}
|
215
|
-
|
216
|
-
p " ** Add 'Free inodes on #{mount_point} disaster trigger'"
|
217
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
218
|
-
|
219
|
-
options = {
|
220
|
-
'gitems' => [
|
221
|
-
{
|
222
|
-
"itemid" => total_in_b_item_id,
|
223
|
-
"drawtype" => "0",
|
224
|
-
"sortorder" => "0",
|
225
|
-
"color" => "AA0000",
|
226
|
-
"yaxisside" => "0",
|
227
|
-
"calc_fnc" => "2",
|
228
|
-
"type" => "0",
|
229
|
-
"periods_cnt" => "5"
|
230
|
-
},
|
231
|
-
{
|
232
|
-
"itemid" => used_in_b_item_id,
|
233
|
-
"drawtype" => "0",
|
234
|
-
"sortorder" => "0",
|
235
|
-
"color" => "009900",
|
236
|
-
"yaxisside" => "0",
|
237
|
-
"calc_fnc" => "2",
|
238
|
-
"type" => "0",
|
239
|
-
"periods_cnt" => "5"
|
240
|
-
}
|
241
|
-
],
|
242
|
-
"show_triggers" => "1",
|
243
|
-
"name" => "Disk space on #{mount_point}",
|
244
|
-
"width" => "900",
|
245
|
-
"height" => "200",
|
246
|
-
"templateid" => "0"
|
247
|
-
}
|
248
|
-
p " ** Add 'Disk space on #{mount_point} graph'"
|
249
|
-
g_id = zbx.add_or_get_graph(t_id, options)
|
data/examples/zabbix_group
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'yaml'
|
5
|
-
require 'getopt/std'
|
6
|
-
require 'zabbixapi'
|
7
|
-
|
8
|
-
opt = Getopt::Std.getopts("g:E:")
|
9
|
-
|
10
|
-
group_name = opt["g"]
|
11
|
-
zabbix_env = opt["E"]
|
12
|
-
|
13
|
-
# read config
|
14
|
-
config = YAML::load(open('./config.yml'))
|
15
|
-
|
16
|
-
api_url = config[zabbix_env]["api_url"]
|
17
|
-
api_login = config[zabbix_env]["api_login"]
|
18
|
-
api_password = config[zabbix_env]["api_password"]
|
19
|
-
|
20
|
-
# Esablish new connection
|
21
|
-
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
22
|
-
|
23
|
-
# Create new hostgroup
|
24
|
-
p " * Creating hostgroup #{group_name}."
|
25
|
-
g_id = zbx.add_or_get_group(group_name)
|
data/examples/zabbix_hlsp
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'getopt/std'
|
5
|
-
require 'yaml'
|
6
|
-
require 'zabbixapi'
|
7
|
-
|
8
|
-
opt = Getopt::Std.getopts("g:i:E:")
|
9
|
-
|
10
|
-
group_name = opt["g"]
|
11
|
-
zabbix_env = opt["E"]
|
12
|
-
hlsp_index = opt["i"]
|
13
|
-
|
14
|
-
template_name = "TMPL_hlsp-#{hlsp_index}"
|
15
|
-
app_name = "HLSPD-#{hlsp_index}"
|
16
|
-
|
17
|
-
# read config
|
18
|
-
config = YAML::load(open('./config.yml'))
|
19
|
-
|
20
|
-
api_url = config[zabbix_env]["api_url"]
|
21
|
-
api_login = config[zabbix_env]["api_login"]
|
22
|
-
api_password = config[zabbix_env]["api_password"]
|
23
|
-
|
24
|
-
# Esablish new connection
|
25
|
-
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
26
|
-
|
27
|
-
# Create new template
|
28
|
-
p " * Creating template #{template_name}."
|
29
|
-
g_id = zbx.add_or_get_group(group_name)
|
30
|
-
|
31
|
-
options = {
|
32
|
-
'groups' => [ g_id.to_i ],
|
33
|
-
'host' => template_name
|
34
|
-
}
|
35
|
-
|
36
|
-
t_id = zbx.add_or_get_template(options)
|
37
|
-
|
38
|
-
# Create application #{app_name}
|
39
|
-
p " ** Create application #{app_name}."
|
40
|
-
application = {
|
41
|
-
'hostid' => t_id.to_i,
|
42
|
-
'name' => app_name
|
43
|
-
}
|
44
|
-
a_id = zbx.add_or_get_application(t_id, application)
|
45
|
-
|
46
|
-
# 'hlsp-#{hlsp_index} service status'
|
47
|
-
options = {
|
48
|
-
'description' => "hlsp-#{hlsp_index} service status",
|
49
|
-
'key_' => "runit_service[hlspd-#{hlsp_index}]",
|
50
|
-
'hostid' => t_id.to_i,
|
51
|
-
'applications' => [ a_id.to_i ],
|
52
|
-
'history' => 7,
|
53
|
-
'trends' => 30,
|
54
|
-
'delay' => 60,
|
55
|
-
'value_type' => 0
|
56
|
-
}
|
57
|
-
p " ** Add 'hlsp-#{hlsp_index} service status' to #{template_name}."
|
58
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
59
|
-
|
60
|
-
# 'hlsp-#{hlsp_index} clients count'
|
61
|
-
hlsp_port = 8080 + hlsp_index.to_i
|
62
|
-
options = {
|
63
|
-
'description' => "hlsp-#{hlsp_index} clients count",
|
64
|
-
'key_' => "hlspd[http://127.0.0.1:#{hlsp_port}/cids.txt]",
|
65
|
-
'hostid' => t_id.to_i,
|
66
|
-
'applications' => [ a_id.to_i ],
|
67
|
-
'history' => 7,
|
68
|
-
'trends' => 30,
|
69
|
-
'delay' => 60,
|
70
|
-
'value_type' => 0
|
71
|
-
}
|
72
|
-
p " ** Add 'hlsp-#{hlsp_index} clients count' to #{template_name}."
|
73
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
74
|
-
|
75
|
-
# TRIGGERS
|
76
|
-
options = {
|
77
|
-
'description' => "hlsp-#{hlsp_index} service status",
|
78
|
-
'expression' => "{#{template_name}:runit_service[hlspd-#{hlsp_index}].last(0)}#0",
|
79
|
-
'priority' => 5, # disaster
|
80
|
-
'templateid' => 0,
|
81
|
-
'comments' => "hlsp-#{hlsp_index} service status (disaster)",
|
82
|
-
'type' => 0,
|
83
|
-
'status' => '0'
|
84
|
-
}
|
85
|
-
|
86
|
-
p " ** Add 'hlsp-#{hlsp_index} service status' trigger"
|
87
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
88
|
-
|
89
|
-
options = {
|
90
|
-
'description' => "hlsp-#{hlsp_index} clients count",
|
91
|
-
'expression' => "{#{template_name}:hlspd[http://127.0.0.1:#{hlsp_port}/cids.txt].last(0)}<0",
|
92
|
-
'priority' => 5, # disaster
|
93
|
-
'templateid' => 0,
|
94
|
-
'comments' => "hlsp-#{hlsp_index} clients count (disaster)",
|
95
|
-
'type' => 0,
|
96
|
-
'status' => '0'
|
97
|
-
}
|
98
|
-
|
99
|
-
p " ** Add 'hlsp-#{hlsp_index} clients count' trigger"
|
100
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
data/examples/zabbix_host
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'yaml'
|
5
|
-
require 'getopt/std'
|
6
|
-
require 'zabbixapi'
|
7
|
-
|
8
|
-
opt = Getopt::Std.getopts("g:E:H:i:")
|
9
|
-
|
10
|
-
group_name = opt["g"]
|
11
|
-
host = opt["H"]
|
12
|
-
ip = opt["i"]
|
13
|
-
zabbix_env = opt["E"]
|
14
|
-
|
15
|
-
# read config
|
16
|
-
config = YAML::load(open('./config.yml'))
|
17
|
-
|
18
|
-
api_url = config[zabbix_env]["api_url"]
|
19
|
-
api_login = config[zabbix_env]["api_login"]
|
20
|
-
api_password = config[zabbix_env]["api_password"]
|
21
|
-
|
22
|
-
# Esablish new connection
|
23
|
-
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
24
|
-
|
25
|
-
g_id = zbx.add_or_get_group(group_name)
|
26
|
-
|
27
|
-
# Create new host
|
28
|
-
options = {
|
29
|
-
"ip" => ip,
|
30
|
-
"dns" => host,
|
31
|
-
"host" => host,
|
32
|
-
"useip" => 1,
|
33
|
-
"groups" => [g_id]
|
34
|
-
}
|
35
|
-
|
36
|
-
p " * Creating host #{host}."
|
37
|
-
g_id = zbx.add_host(options)
|
data/examples/zabbix_iops
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'yaml'
|
5
|
-
require 'getopt/std'
|
6
|
-
require 'zabbixapi'
|
7
|
-
|
8
|
-
opt = Getopt::Std.getopts("g:E:n:")
|
9
|
-
|
10
|
-
group_name = opt["g"]
|
11
|
-
zabbix_env = opt["E"]
|
12
|
-
disk_name = opt["n"]
|
13
|
-
|
14
|
-
template_name = "TMPL_iops_#{disk_name}"
|
15
|
-
|
16
|
-
# read config
|
17
|
-
config = YAML::load(open('./config.yml'))
|
18
|
-
|
19
|
-
api_url = config[zabbix_env]["api_url"]
|
20
|
-
api_login = config[zabbix_env]["api_login"]
|
21
|
-
api_password = config[zabbix_env]["api_password"]
|
22
|
-
|
23
|
-
# Esablish new connection
|
24
|
-
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
25
|
-
|
26
|
-
# Create new template
|
27
|
-
p " * Creating template #{template_name}."
|
28
|
-
g_id = zbx.add_or_get_group(group_name)
|
29
|
-
|
30
|
-
options = {
|
31
|
-
'groups' => [ g_id.to_i ],
|
32
|
-
'host' => template_name
|
33
|
-
}
|
34
|
-
|
35
|
-
t_id = zbx.add_or_get_template(options)
|
36
|
-
|
37
|
-
# Create application #{app_name}
|
38
|
-
app_name = "iops_#{disk_name}"
|
39
|
-
p " ** Create application #{app_name}."
|
40
|
-
application = {
|
41
|
-
'hostid' => t_id.to_i,
|
42
|
-
'name' => app_name
|
43
|
-
}
|
44
|
-
a_id = zbx.add_or_get_application(t_id, application)
|
45
|
-
|
46
|
-
# 'reads for #{disk_name}'
|
47
|
-
options = {
|
48
|
-
'description' => "iops read #{disk_name}",
|
49
|
-
'key_' => "vfs.dev.read[#{disk_name}]",
|
50
|
-
'hostid' => t_id.to_i,
|
51
|
-
'applications' => [ a_id.to_i ],
|
52
|
-
'history' => 7,
|
53
|
-
'trends' => 30,
|
54
|
-
'delay' => 60,
|
55
|
-
'value_type' => 0
|
56
|
-
}
|
57
|
-
p " ** Add 'vfs.dev.read[#{disk_name}]' to #{template_name}."
|
58
|
-
reads_id = zbx.add_or_get_item(t_id, options)
|
59
|
-
|
60
|
-
# 'writes for #{disk_name}'
|
61
|
-
options = {
|
62
|
-
'description' => "iops writes #{disk_name}",
|
63
|
-
'key_' => "vfs.dev.write[#{disk_name}]",
|
64
|
-
'hostid' => t_id.to_i,
|
65
|
-
'applications' => [ a_id.to_i ],
|
66
|
-
'history' => 7,
|
67
|
-
'trends' => 30,
|
68
|
-
'delay' => 60,
|
69
|
-
'value_type' => 0
|
70
|
-
}
|
71
|
-
p " ** Add 'vfs.dev.write[#{disk_name}]' to #{template_name}."
|
72
|
-
writes_id = zbx.add_or_get_item(t_id, options)
|
73
|
-
|
74
|
-
# TRIGGERS
|
75
|
-
options = {
|
76
|
-
'description' => "read on #{disk_name} is too big",
|
77
|
-
'expression' => "{#{template_name}:vfs.dev.read[#{disk_name}].last(0)}>100",
|
78
|
-
'priority' => 2, # warning
|
79
|
-
'templateid' => 0,
|
80
|
-
'comments' => "too many reads on #{disk_name} (warning)",
|
81
|
-
'type' => 0,
|
82
|
-
'status' => '0'
|
83
|
-
}
|
84
|
-
p " ** Add '#{disk_name} reads' trigger'"
|
85
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
86
|
-
|
87
|
-
options = {
|
88
|
-
'description' => "write on #{disk_name} is too big",
|
89
|
-
'expression' => "{#{template_name}:vfs.dev.write[#{disk_name}].last(0)}>300",
|
90
|
-
'priority' => 2, # warning
|
91
|
-
'templateid' => 0,
|
92
|
-
'comments' => "too many writes on #{disk_name} (warning)",
|
93
|
-
'type' => 0,
|
94
|
-
'status' => '0'
|
95
|
-
}
|
96
|
-
p " ** Add '#{disk_name} writes' trigger'"
|
97
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
98
|
-
|
99
|
-
# GRAPHS
|
100
|
-
options = {
|
101
|
-
'gitems' => [
|
102
|
-
{
|
103
|
-
"itemid" => reads_id,
|
104
|
-
"drawtype" => "0",
|
105
|
-
"sortorder" => "0",
|
106
|
-
"color" => "AA0000",
|
107
|
-
"yaxisside" => "0",
|
108
|
-
"calc_fnc" => "2",
|
109
|
-
"type" => "0",
|
110
|
-
"periods_cnt" => "5"
|
111
|
-
},
|
112
|
-
{
|
113
|
-
"itemid" => writes_id,
|
114
|
-
"drawtype" => "0",
|
115
|
-
"sortorder" => "0",
|
116
|
-
"color" => "009900",
|
117
|
-
"yaxisside" => "0",
|
118
|
-
"calc_fnc" => "2",
|
119
|
-
"type" => "0",
|
120
|
-
"periods_cnt" => "5"
|
121
|
-
}
|
122
|
-
],
|
123
|
-
"show_triggers" => "1",
|
124
|
-
"name" => "IOPS graph",
|
125
|
-
"width" => "900",
|
126
|
-
"height" => "200",
|
127
|
-
"templateid" => "0"
|
128
|
-
}
|
129
|
-
|
130
|
-
p " ** Add 'IOPS graph'"
|
131
|
-
g_id = zbx.add_or_get_graph(t_id, options)
|
@@ -1,101 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'getopt/std'
|
5
|
-
require 'yaml'
|
6
|
-
require 'zabbixapi'
|
7
|
-
|
8
|
-
opt = Getopt::Std.getopts("g:E:")
|
9
|
-
|
10
|
-
group_name = opt["g"]
|
11
|
-
zabbix_env = opt["E"]
|
12
|
-
|
13
|
-
template_name = "TMPL_ipmi_cpufan_sensor"
|
14
|
-
app_name = "cpufan_sensor"
|
15
|
-
disaster_rpm = '5000.000'
|
16
|
-
|
17
|
-
# read config
|
18
|
-
config = YAML::load(open('./config.yml'))
|
19
|
-
|
20
|
-
api_url = config[zabbix_env]["api_url"]
|
21
|
-
api_login = config[zabbix_env]["api_login"]
|
22
|
-
api_password = config[zabbix_env]["api_password"]
|
23
|
-
|
24
|
-
# Esablish new connection
|
25
|
-
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
26
|
-
|
27
|
-
# Create new template
|
28
|
-
p " * Creating template #{template_name}."
|
29
|
-
g_id = zbx.add_or_get_group(group_name)
|
30
|
-
|
31
|
-
options = {
|
32
|
-
'groups' => [ g_id.to_i ],
|
33
|
-
'host' => template_name
|
34
|
-
}
|
35
|
-
|
36
|
-
t_id = zbx.add_or_get_template(options)
|
37
|
-
|
38
|
-
# Create application #{app_name}
|
39
|
-
app_name = "ipmi_cpufan_sensor"
|
40
|
-
p " ** Create application #{app_name}."
|
41
|
-
application = {
|
42
|
-
'hostid' => t_id.to_i,
|
43
|
-
'name' => app_name
|
44
|
-
}
|
45
|
-
a_id = zbx.add_or_get_application(t_id, application)
|
46
|
-
|
47
|
-
# 'mpeg2lander signal quality'
|
48
|
-
options = {
|
49
|
-
'description' => "Fan6/CPU sensor RPM",
|
50
|
-
'key_' => "cpufansensor",
|
51
|
-
'hostid' => t_id.to_i,
|
52
|
-
'applications' => [ a_id.to_i ],
|
53
|
-
'history' => 7,
|
54
|
-
'trends' => 30,
|
55
|
-
'delay' => 60,
|
56
|
-
'value_type' => 0
|
57
|
-
}
|
58
|
-
p " ** Add 'cpufansensor' to #{template_name}."
|
59
|
-
sensor_item_id = zbx.add_or_get_item(t_id, options)
|
60
|
-
|
61
|
-
# TRIGGER
|
62
|
-
# cpufan disaster (high threshold)
|
63
|
-
options = {
|
64
|
-
'description' => "Cpufan sensor RPM",
|
65
|
-
'expression' => "{#{template_name}:cpufansensor.last(0)}>#{disaster_rpm}",
|
66
|
-
'priority' => 5, # disaster
|
67
|
-
'templateid' => 0,
|
68
|
-
'comments' => "Cpufan sensor (Disaster)",
|
69
|
-
'type' => 0,
|
70
|
-
'status' => '0'
|
71
|
-
}
|
72
|
-
p " ** Add 'cpufan sensor disaster' trigger"
|
73
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
74
|
-
|
75
|
-
# TODO: create low_threshold trigger
|
76
|
-
# Author: something
|
77
|
-
# Today we can't create it, because on some servers incorrectly
|
78
|
-
# connected cable to the sensor
|
79
|
-
|
80
|
-
# GRAPH
|
81
|
-
options = {
|
82
|
-
'gitems' => [
|
83
|
-
{
|
84
|
-
"itemid" => sensor_item_id,
|
85
|
-
"drawtype" => "0",
|
86
|
-
"sortorder" => "0",
|
87
|
-
"color" => "AA0000",
|
88
|
-
"yaxisside" => "0",
|
89
|
-
"calc_fnc" => "2",
|
90
|
-
"type" => "0",
|
91
|
-
"periods_cnt" => "5"
|
92
|
-
}
|
93
|
-
],
|
94
|
-
"show_triggers" => "1",
|
95
|
-
"name" => "Fan6/CPU sensor RPM data from ipmitool",
|
96
|
-
"width" => "900",
|
97
|
-
"height" => "200",
|
98
|
-
"templateid" => "0"
|
99
|
-
}
|
100
|
-
|
101
|
-
g_id = zbx.add_or_get_graph(t_id, options)
|