zabbixapi 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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_nginx
DELETED
@@ -1,167 +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
|
-
|
13
|
-
template_name = "TMPL_nginx"
|
14
|
-
app_name = "Nginx"
|
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
|
-
p " ** Create application #{app_name}."
|
39
|
-
application = {
|
40
|
-
'hostid' => t_id.to_i,
|
41
|
-
'name' => app_name
|
42
|
-
}
|
43
|
-
a_id = zbx.add_or_get_application(t_id, application)
|
44
|
-
|
45
|
-
# 'nginx service status'
|
46
|
-
options = {
|
47
|
-
'description' => "nginx service status",
|
48
|
-
'key_' => "runit_service[nginx]",
|
49
|
-
'hostid' => t_id.to_i,
|
50
|
-
'applications' => [ a_id.to_i ],
|
51
|
-
'history' => 7,
|
52
|
-
'trends' => 30,
|
53
|
-
'delay' => 60,
|
54
|
-
'value_type' => 0
|
55
|
-
}
|
56
|
-
p " ** Add 'nginx service status' to #{template_name}."
|
57
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
58
|
-
|
59
|
-
store = Hash.new()
|
60
|
-
# 'nginx active_connections'
|
61
|
-
options = {
|
62
|
-
'description' => "nginx active_connections",
|
63
|
-
'key_' => "nginx_status[http://127.0.0.1:8010/status,active_connections]",
|
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 'nginx active_connections' to #{template_name}."
|
72
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
73
|
-
store["active_connections"] = item_id
|
74
|
-
|
75
|
-
["writing", "reading", "waiting"].each do |param|
|
76
|
-
# 'nginx #{param}'
|
77
|
-
options = {
|
78
|
-
'description' => "nginx #{param}",
|
79
|
-
'key_' => "nginx_status[http://127.0.0.1:8010/status,#{param}]",
|
80
|
-
'hostid' => t_id.to_i,
|
81
|
-
'applications' => [ a_id.to_i ],
|
82
|
-
'history' => 7,
|
83
|
-
'trends' => 30,
|
84
|
-
'delay' => 60,
|
85
|
-
'value_type' => 0
|
86
|
-
}
|
87
|
-
p " ** Add 'nginx #{param}' to #{template_name}."
|
88
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
89
|
-
|
90
|
-
store[param] = item_id
|
91
|
-
end
|
92
|
-
|
93
|
-
["handled", "accepts", "requests"].each do |param|
|
94
|
-
# 'nginx #{param}'
|
95
|
-
options = {
|
96
|
-
'description' => "nginx #{param}",
|
97
|
-
'key_' => "nginx_status[http://127.0.0.1:8010/status,#{param}]",
|
98
|
-
'hostid' => t_id.to_i,
|
99
|
-
'applications' => [ a_id.to_i ],
|
100
|
-
'history' => 7,
|
101
|
-
'trends' => 30,
|
102
|
-
'delay' => 60,
|
103
|
-
'value_type' => '3', # Numeric (unsigned)
|
104
|
-
'delta' => 1 # Store as delta (Speed per second)
|
105
|
-
}
|
106
|
-
p " ** Add 'nginx #{param}' to #{template_name}."
|
107
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
108
|
-
|
109
|
-
store[param] = item_id
|
110
|
-
end
|
111
|
-
|
112
|
-
# TRIGGERS
|
113
|
-
options = {
|
114
|
-
'description' => "nginx service status",
|
115
|
-
'expression' => "{#{template_name}:runit_service[nginx].last(0)}#0",
|
116
|
-
'priority' => 5, # disaster
|
117
|
-
'templateid' => 0,
|
118
|
-
'comments' => "nginx service status (disaster)",
|
119
|
-
'type' => 0,
|
120
|
-
'status' => '0'
|
121
|
-
}
|
122
|
-
|
123
|
-
p " ** Add 'nginx service status' trigger"
|
124
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
125
|
-
|
126
|
-
# GRAPHS
|
127
|
-
options = {
|
128
|
-
'gitems' => [
|
129
|
-
{
|
130
|
-
"itemid" => store["active_connections"],
|
131
|
-
"drawtype" => "0",
|
132
|
-
"sortorder" => "0",
|
133
|
-
"color" => "AA0000",
|
134
|
-
"yaxisside" => "0",
|
135
|
-
"calc_fnc" => "2",
|
136
|
-
"type" => "0",
|
137
|
-
"periods_cnt" => "5"
|
138
|
-
},
|
139
|
-
{
|
140
|
-
"itemid" => store["writing"],
|
141
|
-
"drawtype" => "0",
|
142
|
-
"sortorder" => "0",
|
143
|
-
"color" => "009900",
|
144
|
-
"yaxisside" => "0",
|
145
|
-
"calc_fnc" => "2",
|
146
|
-
"type" => "0",
|
147
|
-
"periods_cnt" => "5"
|
148
|
-
},
|
149
|
-
{
|
150
|
-
"itemid" => store["waiting"],
|
151
|
-
"drawtype" => "0",
|
152
|
-
"sortorder" => "0",
|
153
|
-
"color" => "0000AA",
|
154
|
-
"yaxisside" => "0",
|
155
|
-
"calc_fnc" => "2",
|
156
|
-
"type" => "0",
|
157
|
-
"periods_cnt" => "5"
|
158
|
-
}
|
159
|
-
],
|
160
|
-
"show_triggers" => "1",
|
161
|
-
"name" => "Nginx status",
|
162
|
-
"width" => "900",
|
163
|
-
"height" => "200",
|
164
|
-
"templateid" => "0"
|
165
|
-
}
|
166
|
-
|
167
|
-
g_id = zbx.add_or_get_graph(t_id, options)
|
data/examples/zabbix_nginx_500
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'getopt/std'
|
5
|
-
require 'yaml'
|
6
|
-
require 'zabbixapi'
|
7
|
-
require 'digest'
|
8
|
-
|
9
|
-
opt = Getopt::Std.getopts("g:i:E:")
|
10
|
-
|
11
|
-
group_name = opt["g"]
|
12
|
-
zabbix_env = opt["E"]
|
13
|
-
|
14
|
-
template_name = "TMPL_nginx_500"
|
15
|
-
app_name = "Nginx_500"
|
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
|
-
# Monitor all /var/log/nginx/#{access_log_files}.log
|
25
|
-
access_log_files = ["face-server-500", "api-server-500", "logger-face-500", "site-500"]
|
26
|
-
# Search in log last min
|
27
|
-
in_sec = 60 # in seconds
|
28
|
-
# Monitor delay
|
29
|
-
mon_delay_in_sec = 60 # in seconds
|
30
|
-
# Disaster value
|
31
|
-
disaster_value = 5
|
32
|
-
|
33
|
-
# Esablish new connection
|
34
|
-
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
35
|
-
|
36
|
-
# Create new template
|
37
|
-
p " * Creating template #{template_name}."
|
38
|
-
g_id = zbx.add_or_get_group(group_name)
|
39
|
-
|
40
|
-
options = {
|
41
|
-
'groups' => [ g_id.to_i ],
|
42
|
-
'host' => template_name
|
43
|
-
}
|
44
|
-
|
45
|
-
t_id = zbx.add_or_get_template(options)
|
46
|
-
|
47
|
-
# Create application #{app_name}
|
48
|
-
p " ** Create application #{app_name}."
|
49
|
-
application = {
|
50
|
-
'hostid' => t_id.to_i,
|
51
|
-
'name' => app_name
|
52
|
-
}
|
53
|
-
a_id = zbx.add_or_get_application(t_id, application)
|
54
|
-
|
55
|
-
store = Hash.new()
|
56
|
-
# 'nginx_500 error rate'
|
57
|
-
access_log_files.each do |param|
|
58
|
-
# 'nginx #{param}'
|
59
|
-
options = {
|
60
|
-
'description' => "nginx error rate #{param}.log",
|
61
|
-
'key_' => "nginx_500[/var/log/nginx/#{param}.log,#{in_sec}]",
|
62
|
-
'hostid' => t_id.to_i,
|
63
|
-
'applications' => [ a_id.to_i ],
|
64
|
-
'history' => 70,
|
65
|
-
'trends' => 30,
|
66
|
-
'delay' => "#{mon_delay_in_sec}",
|
67
|
-
'value_type' => 0
|
68
|
-
}
|
69
|
-
p " ** Add 'nginx_500 #{param}' to #{template_name}."
|
70
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
71
|
-
|
72
|
-
store["nginx_500_error_rate_log_#{param}"] = item_id
|
73
|
-
end
|
74
|
-
|
75
|
-
# TRIGGERS
|
76
|
-
access_log_files.each do |param|
|
77
|
-
# 'nginx #{param}'
|
78
|
-
options = {
|
79
|
-
'description' => "nginx error log disaster for /var/log/nginx/#{param}.log",
|
80
|
-
'expression' => "{#{template_name}:nginx_500[/var/log/nginx/#{param}.log,#{in_sec}].last(0)}>#{disaster_value}",
|
81
|
-
'priority' => 5, # disaster
|
82
|
-
'templateid' => 0,
|
83
|
-
'comments' => "nginx error rate disaster for /var/log/nginx/#{param}.log errors > #{disaster_value} in last #{in_sec} min",
|
84
|
-
'type' => 0,
|
85
|
-
'status' => '0'
|
86
|
-
}
|
87
|
-
p " ** Add 'nginx service status' trigger for #{param}"
|
88
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
# GRAPHS
|
93
|
-
gitems = access_log_files.map do |param| {
|
94
|
-
"itemid" => store["nginx_500_error_rate_log_#{param}"],
|
95
|
-
"drawtype" => "0",
|
96
|
-
"sortorder" => "0",
|
97
|
-
"color" => Digest::MD5.hexdigest("#{param}").to_s[0..6],
|
98
|
-
"yaxisside" => "0",
|
99
|
-
"calc_fnc" => "2",
|
100
|
-
"type" => "0",
|
101
|
-
"periods_cnt" => "5"
|
102
|
-
}
|
103
|
-
end
|
104
|
-
options = {
|
105
|
-
'gitems' => gitems,
|
106
|
-
"show_triggers" => "0",
|
107
|
-
"name" => "Nginx error rate",
|
108
|
-
"width" => "900",
|
109
|
-
"height" => "200"
|
110
|
-
}
|
111
|
-
|
112
|
-
g_id = zbx.add_or_get_graph(t_id, options)
|
data/examples/zabbix_ntp
DELETED
@@ -1,71 +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
|
-
|
13
|
-
template_name = "TMPL_ntp"
|
14
|
-
app_name = "NTP"
|
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
|
-
p " ** Create application #{app_name}."
|
39
|
-
application = {
|
40
|
-
'hostid' => t_id.to_i,
|
41
|
-
'name' => app_name
|
42
|
-
}
|
43
|
-
a_id = zbx.add_or_get_application(t_id, application)
|
44
|
-
|
45
|
-
# 'ntpd process exists'
|
46
|
-
options = {
|
47
|
-
'description' => "ntpd process exists",
|
48
|
-
'key_' => "proc.num[ntpd]",
|
49
|
-
'hostid' => t_id.to_i,
|
50
|
-
'applications' => [ a_id.to_i ],
|
51
|
-
'history' => 7,
|
52
|
-
'trends' => 30,
|
53
|
-
'delay' => 120,
|
54
|
-
'value_type' => 0
|
55
|
-
}
|
56
|
-
p " ** Add 'ntpd process exists' to #{template_name}."
|
57
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
58
|
-
|
59
|
-
# TRIGGERS
|
60
|
-
options = {
|
61
|
-
'description' => "ntpd process exists",
|
62
|
-
'expression' => "{#{template_name}:proc.num[ntpd].last(0)}<1",
|
63
|
-
'priority' => 5, # disaster
|
64
|
-
'templateid' => 0,
|
65
|
-
'comments' => "ntpd process exists (disaster)",
|
66
|
-
'type' => 0,
|
67
|
-
'status' => '0'
|
68
|
-
}
|
69
|
-
|
70
|
-
p " ** Add 'ntpd process exists' trigger"
|
71
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
data/examples/zabbix_nv-gputemp
DELETED
@@ -1,111 +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_nv_gputemp_sensor"
|
14
|
-
app_name = "nv_gputemp_sensor"
|
15
|
-
high_temperature = '70'
|
16
|
-
crit_temperature = '80'
|
17
|
-
|
18
|
-
# read config
|
19
|
-
config = YAML::load(open('./config.yml'))
|
20
|
-
|
21
|
-
api_url = config[zabbix_env]["api_url"]
|
22
|
-
api_login = config[zabbix_env]["api_login"]
|
23
|
-
api_password = config[zabbix_env]["api_password"]
|
24
|
-
|
25
|
-
# Esablish new connection
|
26
|
-
zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
27
|
-
|
28
|
-
# Create new template
|
29
|
-
p " * Creating template #{template_name}."
|
30
|
-
g_id = zbx.add_or_get_group(group_name)
|
31
|
-
|
32
|
-
options = {
|
33
|
-
'groups' => [ g_id.to_i ],
|
34
|
-
'host' => template_name
|
35
|
-
}
|
36
|
-
|
37
|
-
t_id = zbx.add_or_get_template(options)
|
38
|
-
|
39
|
-
# Create application #{app_name}
|
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
|
-
# 'cpu temperature sensor'
|
48
|
-
options = {
|
49
|
-
'description' => "Nvidia GPU Temperature sensor",
|
50
|
-
'key_' => "nv-gputemp",
|
51
|
-
'hostid' => t_id.to_i,
|
52
|
-
'applications' => [ a_id.to_i ],
|
53
|
-
'history' => 7,
|
54
|
-
'trends' => 30,
|
55
|
-
'delay' => 60,
|
56
|
-
'value_type' => '3',
|
57
|
-
'units' => 'C'
|
58
|
-
}
|
59
|
-
p " ** Add 'nv-gputemp' to #{template_name}."
|
60
|
-
sensor_item_id = zbx.add_or_get_item(t_id, options)
|
61
|
-
|
62
|
-
# TRIGGER
|
63
|
-
# nv-gputemp disaster (high threshold)
|
64
|
-
options = {
|
65
|
-
'description' => "Nvidia GPU Temperature sensor warning",
|
66
|
-
'expression' => "{#{template_name}:nv-gputemp.last(0)}>#{high_temperature}",
|
67
|
-
'priority' => 2, # warning
|
68
|
-
'templateid' => 0,
|
69
|
-
'comments' => "Nvidia GPU temperature sensor (Warning)",
|
70
|
-
'type' => 0,
|
71
|
-
'status' => '0'
|
72
|
-
}
|
73
|
-
p " ** Add 'nv-gputemp sensor warning' trigger"
|
74
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
75
|
-
|
76
|
-
# TRIGGER
|
77
|
-
# cputemp disaster (high threshold)
|
78
|
-
options = {
|
79
|
-
'description' => "Nvidia GPU temperature sensor disaster",
|
80
|
-
'expression' => "{#{template_name}:nv-gputemp.last(0)}>#{crit_temperature}",
|
81
|
-
'priority' => 5, # disaster
|
82
|
-
'templateid' => 0,
|
83
|
-
'comments' => "Nvidia GPU temperature sensor (Disaster)",
|
84
|
-
'type' => 0,
|
85
|
-
'status' => '0'
|
86
|
-
}
|
87
|
-
p " ** Add 'cputemp sensor disaster' trigger"
|
88
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
89
|
-
|
90
|
-
# GRAPH
|
91
|
-
options = {
|
92
|
-
'gitems' => [
|
93
|
-
{
|
94
|
-
"itemid" => sensor_item_id,
|
95
|
-
"drawtype" => "0",
|
96
|
-
"sortorder" => "0",
|
97
|
-
"color" => "AA0000",
|
98
|
-
"yaxisside" => "0",
|
99
|
-
"calc_fnc" => "2",
|
100
|
-
"type" => "0",
|
101
|
-
"periods_cnt" => "5"
|
102
|
-
}
|
103
|
-
],
|
104
|
-
"show_triggers" => "1",
|
105
|
-
"name" => "Nvidia GPU Temperature from nvidia-smi",
|
106
|
-
"width" => "900",
|
107
|
-
"height" => "200",
|
108
|
-
"templateid" => "0"
|
109
|
-
}
|
110
|
-
|
111
|
-
g_id = zbx.add_or_get_graph(t_id, options)
|
data/examples/zabbix_pgsql
DELETED
@@ -1,125 +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
|
-
|
13
|
-
template_name = "TMPL_pgsql"
|
14
|
-
app_name = "PostgreSQL"
|
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
|
-
p " ** Create application #{app_name}."
|
39
|
-
application = {
|
40
|
-
'hostid' => t_id.to_i,
|
41
|
-
'name' => app_name
|
42
|
-
}
|
43
|
-
a_id = zbx.add_or_get_application(t_id, application)
|
44
|
-
|
45
|
-
# 'postgres process exists'
|
46
|
-
options = {
|
47
|
-
'description' => "postgres process exists",
|
48
|
-
'key_' => "proc.num[postgres]",
|
49
|
-
'hostid' => t_id.to_i,
|
50
|
-
'applications' => [ a_id.to_i ],
|
51
|
-
'history' => 7,
|
52
|
-
'trends' => 30,
|
53
|
-
'delay' => 120,
|
54
|
-
'value_type' => 0
|
55
|
-
}
|
56
|
-
p " ** Add 'postgres process exists' to #{template_name}."
|
57
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
58
|
-
|
59
|
-
# 'active connections count'
|
60
|
-
options = {
|
61
|
-
'description' => "postgres active connections count",
|
62
|
-
'key_' => "pgsql.connection_count[]",
|
63
|
-
'hostid' => t_id.to_i,
|
64
|
-
'applications' => [ a_id.to_i ],
|
65
|
-
'history' => 7,
|
66
|
-
'trends' => 30,
|
67
|
-
'delay' => 120,
|
68
|
-
'value_type' => 0
|
69
|
-
}
|
70
|
-
p " ** Add 'postgres active connections count' to #{template_name}."
|
71
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
72
|
-
|
73
|
-
# 'test connect'
|
74
|
-
options = {
|
75
|
-
'description' => "postgres test connect",
|
76
|
-
'key_' => "pgsql.test_connect[]",
|
77
|
-
'hostid' => t_id.to_i,
|
78
|
-
'applications' => [ a_id.to_i ],
|
79
|
-
'history' => 7,
|
80
|
-
'trends' => 30,
|
81
|
-
'delay' => 120,
|
82
|
-
'value_type' => 0
|
83
|
-
}
|
84
|
-
p " ** Add 'postgres test connect' to #{template_name}."
|
85
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
86
|
-
|
87
|
-
# TRIGGERS
|
88
|
-
options = {
|
89
|
-
'description' => "postgres process exists",
|
90
|
-
'expression' => "{#{template_name}:proc.num[postgres].last(0)}<1",
|
91
|
-
'priority' => 5, # disaster
|
92
|
-
'templateid' => 0,
|
93
|
-
'comments' => "postgres process exists (disaster)",
|
94
|
-
'type' => 0,
|
95
|
-
'status' => '0'
|
96
|
-
}
|
97
|
-
|
98
|
-
p " ** Add 'postgres process exists' trigger"
|
99
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
100
|
-
|
101
|
-
options = {
|
102
|
-
'description' => "postgres test connect",
|
103
|
-
'expression' => "{#{template_name}:pgsql.test_connect[].last(0)}#0",
|
104
|
-
'priority' => 5, # disaster
|
105
|
-
'templateid' => 0,
|
106
|
-
'comments' => "postgres test connect (disaster)",
|
107
|
-
'type' => 0,
|
108
|
-
'status' => '0'
|
109
|
-
}
|
110
|
-
|
111
|
-
p " ** Add 'postgres test connect' trigger"
|
112
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
113
|
-
|
114
|
-
options = {
|
115
|
-
'description' => "postgres connection count",
|
116
|
-
'expression' => "{#{template_name}:pgsql.connection_count[].last(0)}>700",
|
117
|
-
'priority' => 5, # disaster
|
118
|
-
'templateid' => 0,
|
119
|
-
'comments' => "postgres connection count (disaster)",
|
120
|
-
'type' => 0,
|
121
|
-
'status' => '0'
|
122
|
-
}
|
123
|
-
|
124
|
-
p " ** Add 'postgres connection count' trigger"
|
125
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|
@@ -1,71 +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
|
-
|
13
|
-
template_name = "TMPL_zabbix_server"
|
14
|
-
app_name = "zabbix_server"
|
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
|
-
p " ** Create application #{app_name}."
|
39
|
-
application = {
|
40
|
-
'hostid' => t_id.to_i,
|
41
|
-
'name' => app_name
|
42
|
-
}
|
43
|
-
a_id = zbx.add_or_get_application(t_id, application)
|
44
|
-
|
45
|
-
# 'zabbix_server process exists'
|
46
|
-
options = {
|
47
|
-
'description' => "zabbix_server process exists",
|
48
|
-
'key_' => "proc.num[zabbix_server]",
|
49
|
-
'hostid' => t_id.to_i,
|
50
|
-
'applications' => [ a_id.to_i ],
|
51
|
-
'history' => 7,
|
52
|
-
'trends' => 30,
|
53
|
-
'delay' => 120,
|
54
|
-
'value_type' => 0
|
55
|
-
}
|
56
|
-
p " ** Add 'zabbix_server process exists' to #{template_name}."
|
57
|
-
item_id = zbx.add_or_get_item(t_id, options)
|
58
|
-
|
59
|
-
# TRIGGERS
|
60
|
-
options = {
|
61
|
-
'description' => "zabbix_server process exists",
|
62
|
-
'expression' => "{#{template_name}:proc.num[zabbix_server].last(0)}<1",
|
63
|
-
'priority' => 5, # disaster
|
64
|
-
'templateid' => 0,
|
65
|
-
'comments' => "zabbix_server process exists (disaster)",
|
66
|
-
'type' => 0,
|
67
|
-
'status' => '0'
|
68
|
-
}
|
69
|
-
|
70
|
-
p " ** Add 'zabbix_server process exists' trigger"
|
71
|
-
tr_id = zbx.add_or_get_trigger(t_id, options)
|