zabbixapi 0.1.6.4 → 0.1.7
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/README.rdoc +7 -1
- data/examples/basic_auth.rb +30 -0
- data/examples/maintenance-example.rb +55 -0
- data/examples/populate_new_zabbix.sh +84 -0
- data/examples/zabbix_availability +7 -7
- data/examples/zabbix_clear_default +36 -0
- data/examples/zabbix_cpufan-sersor +114 -0
- data/examples/zabbix_cputemp-sersor +112 -0
- data/examples/zabbix_disk_io +8 -8
- data/examples/zabbix_filesystem +20 -20
- data/examples/zabbix_group +25 -0
- data/examples/zabbix_hlsp +100 -0
- data/examples/zabbix_host +37 -0
- data/examples/zabbix_iops +131 -0
- data/examples/zabbix_ipmi-cpufan-sersor +101 -0
- data/examples/zabbix_ipmi_systemp +110 -0
- data/examples/zabbix_la +42 -7
- data/examples/zabbix_mailer +125 -0
- data/examples/zabbix_mdadm +72 -0
- data/examples/zabbix_megaraid +71 -0
- data/examples/zabbix_memory +35 -21
- data/examples/zabbix_named +71 -0
- data/examples/zabbix_net +144 -8
- data/examples/zabbix_nginx +167 -0
- data/examples/zabbix_nginx_500 +112 -0
- data/examples/zabbix_ntp +71 -0
- data/examples/zabbix_nv-gputemp +111 -0
- data/examples/zabbix_pgsql +125 -0
- data/examples/zabbix_server_process +71 -0
- data/examples/zabbix_smart_blade +94 -0
- data/examples/zabbix_ssh +71 -0
- data/examples/zabbix_varnish +71 -0
- data/lib/zabbixapi.rb +1 -0
- data/lib/zabbixapi/application.rb +2 -2
- data/lib/zabbixapi/base.rb +6 -1
- data/lib/zabbixapi/host.rb +3 -3
- data/lib/zabbixapi/maintenance.rb +78 -0
- data/spec/localhost.rb +7 -1
- data/zabbixapi.gemspec +2 -2
- metadata +30 -4
- data/spec/request.rb +0 -130
@@ -0,0 +1,101 @@
|
|
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)
|
@@ -0,0 +1,110 @@
|
|
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_ipmi"
|
14
|
+
app_name = "ipmi"
|
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
|
+
store = Hash.new()
|
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
|
+
# 'System temp'
|
48
|
+
options = {
|
49
|
+
'description' => "sys-temp",
|
50
|
+
'key_' => "ipmi.sys-temp",
|
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 'System temp' to #{template_name}."
|
59
|
+
item_id = zbx.add_or_get_item(t_id, options)
|
60
|
+
|
61
|
+
store["sys-temp"] = item_id
|
62
|
+
|
63
|
+
# TRIGGERS
|
64
|
+
options = {
|
65
|
+
'description' => "System temp",
|
66
|
+
'expression' => "{#{template_name}:ipmi.sys-temp.last(0)}>55",
|
67
|
+
'priority' => 5, # disaster
|
68
|
+
'templateid' => 0,
|
69
|
+
'comments' => "System temp (disaster)",
|
70
|
+
'type' => 0,
|
71
|
+
'status' => '0'
|
72
|
+
}
|
73
|
+
|
74
|
+
p " ** Add 'System temp status' trigger"
|
75
|
+
tr_id = zbx.add_or_get_trigger(t_id, options)
|
76
|
+
|
77
|
+
options = {
|
78
|
+
'description' => "System temp",
|
79
|
+
'expression' => "{#{template_name}:ipmi.sys-temp.last(0)}>50",
|
80
|
+
'priority' => 3, # warning
|
81
|
+
'templateid' => 0,
|
82
|
+
'comments' => "System temp (warning)",
|
83
|
+
'type' => 0,
|
84
|
+
'status' => '0'
|
85
|
+
}
|
86
|
+
|
87
|
+
p " ** Add 'System temp status' trigger"
|
88
|
+
tr_id = zbx.add_or_get_trigger(t_id, options)
|
89
|
+
|
90
|
+
# GRAPHS
|
91
|
+
options = {
|
92
|
+
'gitems' => [
|
93
|
+
{
|
94
|
+
"itemid" => store["sys-temp"],
|
95
|
+
"drawtype" => "0",
|
96
|
+
"sortorder" => "0",
|
97
|
+
"color" => "009900",
|
98
|
+
"yaxisside" => "0",
|
99
|
+
"calc_fnc" => "2",
|
100
|
+
"type" => "0",
|
101
|
+
"periods_cnt" => "5"
|
102
|
+
}
|
103
|
+
],
|
104
|
+
"show_triggers" => "1",
|
105
|
+
"name" => "System temp",
|
106
|
+
"width" => "900",
|
107
|
+
"height" => "200",
|
108
|
+
"templateid" => "0"
|
109
|
+
}
|
110
|
+
g_id = zbx.add_or_get_graph(t_id, options)
|
data/examples/zabbix_la
CHANGED
@@ -24,14 +24,14 @@ zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
|
|
24
24
|
|
25
25
|
# Create new template
|
26
26
|
p " * Creating template #{template_name}."
|
27
|
-
g_id = zbx.
|
27
|
+
g_id = zbx.add_or_get_group(group_name)
|
28
28
|
|
29
29
|
options = {
|
30
30
|
'groups' => [ g_id.to_i ],
|
31
31
|
'host' => template_name
|
32
32
|
}
|
33
33
|
|
34
|
-
t_id = zbx.
|
34
|
+
t_id = zbx.add_or_get_template(options)
|
35
35
|
|
36
36
|
# Create application #{app_name}
|
37
37
|
app_name = "Load_average"
|
@@ -40,7 +40,7 @@ application = {
|
|
40
40
|
'hostid' => t_id.to_i,
|
41
41
|
'name' => app_name
|
42
42
|
}
|
43
|
-
a_id = zbx.
|
43
|
+
a_id = zbx.add_or_get_application(t_id, application)
|
44
44
|
|
45
45
|
# 'Load Average 1'
|
46
46
|
options = {
|
@@ -55,7 +55,7 @@ options = {
|
|
55
55
|
}
|
56
56
|
p " ** Add 'Load Average 1' to #{template_name}."
|
57
57
|
|
58
|
-
|
58
|
+
la_1_item_id = zbx.add_or_get_item(t_id, options)
|
59
59
|
|
60
60
|
# 'Load Average 5'
|
61
61
|
options = {
|
@@ -70,7 +70,7 @@ options = {
|
|
70
70
|
}
|
71
71
|
p " ** Add 'Load Average 5' to #{template_name}."
|
72
72
|
|
73
|
-
|
73
|
+
la_5_item_id = zbx.add_or_get_item(t_id, options)
|
74
74
|
|
75
75
|
# TRIGGERS
|
76
76
|
|
@@ -85,7 +85,7 @@ options = {
|
|
85
85
|
}
|
86
86
|
|
87
87
|
p " ** Add 'Load Average warning trigger'"
|
88
|
-
tr_id = zbx.
|
88
|
+
tr_id = zbx.add_or_get_trigger(t_id, options)
|
89
89
|
|
90
90
|
options = {
|
91
91
|
'description' => "Load Average",
|
@@ -98,4 +98,39 @@ options = {
|
|
98
98
|
}
|
99
99
|
|
100
100
|
p " ** Add 'Load Average disaster trigger'"
|
101
|
-
tr_id = zbx.
|
101
|
+
tr_id = zbx.add_or_get_trigger(t_id, options)
|
102
|
+
|
103
|
+
# GRAPHS
|
104
|
+
|
105
|
+
options = {
|
106
|
+
'gitems' => [
|
107
|
+
{
|
108
|
+
"itemid" => la_1_item_id,
|
109
|
+
"drawtype" => "0",
|
110
|
+
"sortorder" => "0",
|
111
|
+
"color" => "AA0000",
|
112
|
+
"yaxisside" => "0",
|
113
|
+
"calc_fnc" => "2",
|
114
|
+
"type" => "0",
|
115
|
+
"periods_cnt" => "5"
|
116
|
+
},
|
117
|
+
{
|
118
|
+
"itemid" => la_5_item_id,
|
119
|
+
"drawtype" => "0",
|
120
|
+
"sortorder" => "0",
|
121
|
+
"color" => "009900",
|
122
|
+
"yaxisside" => "0",
|
123
|
+
"calc_fnc" => "2",
|
124
|
+
"type" => "0",
|
125
|
+
"periods_cnt" => "5"
|
126
|
+
}
|
127
|
+
],
|
128
|
+
"show_triggers" => "1",
|
129
|
+
"name" => "Load Average",
|
130
|
+
"width" => "900",
|
131
|
+
"height" => "200",
|
132
|
+
"templateid" => "0"
|
133
|
+
}
|
134
|
+
|
135
|
+
p " ** Add 'Load Average graph'"
|
136
|
+
g_id = zbx.add_or_get_graph(t_id, options)
|
@@ -0,0 +1,125 @@
|
|
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
|
+
template_name = "TMPL_mailer"
|
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
|
+
# Create new template
|
26
|
+
p " * Creating template #{template_name}."
|
27
|
+
g_id = zbx.add_or_get_group(group_name)
|
28
|
+
|
29
|
+
options = {
|
30
|
+
'groups' => [ g_id.to_i ],
|
31
|
+
'host' => template_name
|
32
|
+
}
|
33
|
+
|
34
|
+
t_id = zbx.add_or_get_template(options)
|
35
|
+
|
36
|
+
# Create application #{app_name}
|
37
|
+
app_name = "mailer"
|
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
|
+
# 'mailq_size'
|
46
|
+
options = {
|
47
|
+
'description' => "mailq size",
|
48
|
+
'key_' => "mailer.mailq",
|
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 'mailer.mailq' to #{template_name}."
|
57
|
+
|
58
|
+
mailq = zbx.add_or_get_item(t_id, options)
|
59
|
+
|
60
|
+
# Exim
|
61
|
+
options = {
|
62
|
+
'description' => "num of exim",
|
63
|
+
'key_' => "proc.num[exim4]",
|
64
|
+
'hostid' => t_id.to_i,
|
65
|
+
'applications' => [ a_id.to_i ],
|
66
|
+
'history' => 7,
|
67
|
+
'trends' => 30,
|
68
|
+
'delay' => 120,
|
69
|
+
'value_type' => 0
|
70
|
+
}
|
71
|
+
p " ** Add 'num of exim' to #{template_name}."
|
72
|
+
item_id = zbx.add_or_get_item(t_id, options)
|
73
|
+
|
74
|
+
# TRIGGERS
|
75
|
+
|
76
|
+
options = {
|
77
|
+
'description' => "mailq size",
|
78
|
+
'expression' => "{#{template_name}:mailer.mailq.last(0)}>100",
|
79
|
+
'priority' => 2, # warning
|
80
|
+
'templateid' => 0,
|
81
|
+
'comments' => "Mailq size too big",
|
82
|
+
'type' => 0,
|
83
|
+
'status' => '0'
|
84
|
+
}
|
85
|
+
|
86
|
+
p " ** Add 'mailq warning trigger'"
|
87
|
+
tr_id = zbx.add_or_get_trigger(t_id, options)
|
88
|
+
|
89
|
+
options = {
|
90
|
+
'description' => "exim is running",
|
91
|
+
'expression' => "{#{template_name}:proc.num[exim4].last(0)}<1",
|
92
|
+
'priority' => 5, # disaster
|
93
|
+
'templateid' => 0,
|
94
|
+
'comments' => "Exim is down, call Stepan or Skipka",
|
95
|
+
'type' => 0,
|
96
|
+
'status' => '0'
|
97
|
+
}
|
98
|
+
|
99
|
+
p " ** Add 'Exim is down' trigger"
|
100
|
+
tr_id = zbx.add_or_get_trigger(t_id, options)
|
101
|
+
|
102
|
+
# GRAPHS
|
103
|
+
|
104
|
+
options = {
|
105
|
+
'gitems' => [
|
106
|
+
{
|
107
|
+
"itemid" => mailq,
|
108
|
+
"drawtype" => "0",
|
109
|
+
"sortorder" => "0",
|
110
|
+
"color" => "AA0000",
|
111
|
+
"yaxisside" => "0",
|
112
|
+
"calc_fnc" => "2",
|
113
|
+
"type" => "0",
|
114
|
+
"periods_cnt" => "5"
|
115
|
+
},
|
116
|
+
],
|
117
|
+
"show_triggers" => "1",
|
118
|
+
"name" => "mailq size",
|
119
|
+
"width" => "900",
|
120
|
+
"height" => "200",
|
121
|
+
"templateid" => "0"
|
122
|
+
}
|
123
|
+
|
124
|
+
p " ** Add 'mailq size graph'"
|
125
|
+
g_id = zbx.add_or_get_graph(t_id, options)
|
@@ -0,0 +1,72 @@
|
|
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
|
+
raid_name = opt["n"]
|
13
|
+
|
14
|
+
template_name = "TMPL_mdadm_#{raid_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
|
+
t_id = zbx.add_or_get_template(options)
|
35
|
+
|
36
|
+
# Create application #{app_name}
|
37
|
+
app_name = "mdadm_#{raid_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
|
+
# 'state of #{raid_name}'
|
46
|
+
options = {
|
47
|
+
'description' => "state of #{raid_name}",
|
48
|
+
'key_' => "mdadm.state[#{raid_name}]",
|
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 'mdadm.state[#{raid_name}]' to #{template_name}."
|
57
|
+
item_id = zbx.add_or_get_item(t_id, options)
|
58
|
+
|
59
|
+
# TRIGGERS
|
60
|
+
options = {
|
61
|
+
'description' => "#{raid_name} is faulty",
|
62
|
+
'expression' => "{#{template_name}:mdadm.state[#{raid_name}].last(0)}>0",
|
63
|
+
'priority' => 5, # disaster
|
64
|
+
'templateid' => 0,
|
65
|
+
'comments' => "#{raid_name} is faulty (disaster)",
|
66
|
+
'type' => 0,
|
67
|
+
'status' => '0'
|
68
|
+
}
|
69
|
+
|
70
|
+
p " ** Add '#{raid_name} disaster' trigger'"
|
71
|
+
zbx.debug = true
|
72
|
+
tr_id = zbx.add_or_get_trigger(t_id, options)
|