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.
@@ -0,0 +1,71 @@
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_MegaRAID"
14
+ app_name = "MegaRAID"
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
+ # 'MegaRAID degraded count'
46
+ options = {
47
+ 'description' => "MegaRAID degraded count",
48
+ 'key_' => "megaraid.degraded[]",
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 'MegaRAID degraded count' to #{template_name}."
57
+ item_id = zbx.add_or_get_item(t_id, options)
58
+
59
+ # TRIGGERS
60
+ options = {
61
+ 'description' => "MegaRAID degraded count",
62
+ 'expression' => "{#{template_name}:megaraid.degraded[].last(0)}#0",
63
+ 'priority' => 5, # disaster
64
+ 'templateid' => 0,
65
+ 'comments' => "MegaRAID degraded count (disaster)",
66
+ 'type' => 0,
67
+ 'status' => '0'
68
+ }
69
+
70
+ p " ** Add 'MegaRAID degraded count' trigger"
71
+ tr_id = zbx.add_or_get_trigger(t_id, options)
@@ -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.get_group_id(group_name)
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.add_template(options)
34
+ t_id = zbx.add_or_get_template(options)
35
35
 
36
36
  # Create application #{app_name}
37
37
  app_name = "Memory"
@@ -40,7 +40,7 @@ application = {
40
40
  'hostid' => t_id.to_i,
41
41
  'name' => app_name
42
42
  }
43
- a_id = zbx.add_application(application)
43
+ a_id = zbx.add_or_get_application(t_id, application)
44
44
 
45
45
  # 'Buffers memory'
46
46
  options = {
@@ -55,7 +55,7 @@ options = {
55
55
  }
56
56
  p " ** Add 'Buffers memory' to #{template_name}."
57
57
 
58
- buffers_in_b_item_id = zbx.add_item(options)
58
+ buffers_in_b_item_id = zbx.add_or_get_item(t_id, options)
59
59
 
60
60
  # 'Cached memory'
61
61
  options = {
@@ -70,7 +70,7 @@ options = {
70
70
  }
71
71
  p " ** Add 'Cached memory' to #{template_name}."
72
72
 
73
- cached_in_b_item_id = zbx.add_item(options)
73
+ cached_in_b_item_id = zbx.add_or_get_item(t_id, options)
74
74
 
75
75
  # 'Total memory'
76
76
  options = {
@@ -86,15 +86,16 @@ options = {
86
86
  }
87
87
  p " ** Add 'Total memory' to #{template_name}."
88
88
 
89
- total_in_b_item_id = zbx.add_item(options)
89
+ total_in_b_item_id = zbx.add_or_get_item(t_id, options)
90
90
 
91
91
  # 'Used memory with buffers and cache'
92
92
  options = {
93
- 'description' => "Used memory",
93
+ 'description' => "Used memory (without cache and buffers)",
94
94
  'key_' => "vm.memory.size[used]",
95
+ 'params' => "last(\"vm.memory.size[total]\") - last(\"vm.memory.size[free]\") - last(\"vm.memory.size[cached]\") - last(\"vm.memory.size[buffers]\")",
95
96
  'hostid' => t_id.to_i,
97
+ 'type' => '15', # calculated
96
98
  'applications' => [ a_id.to_i ],
97
- 'delay' => '300',
98
99
  'units' => 'B',
99
100
  'history' => 7,
100
101
  'trends' => 30,
@@ -102,7 +103,7 @@ options = {
102
103
  }
103
104
  p " ** Add 'Used memory' to #{template_name}."
104
105
 
105
- used_in_b_item_id = zbx.add_item(options)
106
+ used_in_b_item_id = zbx.add_or_get_item(t_id, options)
106
107
 
107
108
  # 'Free memory'
108
109
  options = {
@@ -116,10 +117,23 @@ options = {
116
117
  'value_type' => 0
117
118
  }
118
119
  p " ** Add 'Free memory' to #{template_name}."
120
+ i_id = zbx.add_or_get_item(t_id, options)
119
121
 
120
- i_id = zbx.add_item(options)
122
+ # 'Free memory in %'
123
+ options = {
124
+ 'description' => "Free memory in %",
125
+ 'key_' => "vm.memory.size[pfree]",
126
+ 'hostid' => t_id.to_i,
127
+ 'applications' => [ a_id.to_i ],
128
+ 'units' => '%',
129
+ 'history' => 7,
130
+ 'trends' => 30,
131
+ 'value_type' => 0
132
+ }
133
+ p " ** Add 'Free memory in %' to #{template_name}."
134
+ i_id = zbx.add_or_get_item(t_id, options)
121
135
 
122
- # 'Free mmeory with buffers and cache'
136
+ # 'Free memory with buffers and cache'
123
137
  options = {
124
138
  'description' => "Free memory with buffers and cache",
125
139
  'key_' => "vm.memory.size[free_with_buffer_cache]",
@@ -134,7 +148,7 @@ options = {
134
148
  }
135
149
  p " ** Add 'Free memory with buffers and cache' to #{template_name}."
136
150
 
137
- i_id = zbx.add_item(options)
151
+ i_id = zbx.add_or_get_item(t_id, options)
138
152
 
139
153
  # 'Swap in all'
140
154
  options = {
@@ -151,7 +165,7 @@ options = {
151
165
  }
152
166
  p " ** Add 'Swap in all' to #{template_name}."
153
167
 
154
- i_id = zbx.add_item(options)
168
+ i_id = zbx.add_or_get_item(t_id, options)
155
169
 
156
170
  # 'Swap out all'
157
171
  options = {
@@ -168,12 +182,12 @@ options = {
168
182
  }
169
183
  p " ** Add 'Swap out all' to #{template_name}."
170
184
 
171
- i_id = zbx.add_item(options)
185
+ i_id = zbx.add_or_get_item(t_id, options)
172
186
 
173
187
  # TRIGGERS
174
188
  options = {
175
189
  'description' => "Free memory without cache, %",
176
- 'expression' => "{#{template_name}:vm.memory.size[free].last(0)}<15",
190
+ 'expression' => "{#{template_name}:vm.memory.size[pfree].last(0)}<15",
177
191
  'priority' => 2, # warning
178
192
  'templateid' => 0,
179
193
  'comments' => "Free memory without cache, % warning trigger",
@@ -182,11 +196,11 @@ options = {
182
196
  }
183
197
 
184
198
  p " ** Add 'Free memory without cache, %'"
185
- tr_id = zbx.add_trigger(options)
199
+ tr_id = zbx.add_or_get_trigger(t_id, options)
186
200
 
187
201
  options = {
188
202
  'description' => "Free memory without cache, %",
189
- 'expression' => "{#{template_name}:vm.memory.size[free].last(0)}<10",
203
+ 'expression' => "{#{template_name}:vm.memory.size[pfree].last(0)}<10",
190
204
  'priority' => 5, # disaster
191
205
  'templateid' => 0,
192
206
  'commenty' => "Free memory without cache, %",
@@ -195,7 +209,7 @@ options = {
195
209
  }
196
210
 
197
211
  p " ** Add 'Free memory without cache, % disaster trigger'"
198
- tr_id = zbx.add_trigger(options)
212
+ tr_id = zbx.add_or_get_trigger(t_id, options)
199
213
 
200
214
  options = {
201
215
  'description' => "Swap usage in, B",
@@ -208,7 +222,7 @@ options = {
208
222
  }
209
223
 
210
224
  p " ** Add 'Swap usage in, B warning trigger'"
211
- tr_id = zbx.add_trigger(options)
225
+ tr_id = zbx.add_or_get_trigger(t_id, options)
212
226
 
213
227
  options = {
214
228
  'description' => "Swap usage out, B",
@@ -221,7 +235,7 @@ options = {
221
235
  }
222
236
 
223
237
  p " ** Add 'Swap usage out, B warning trigger'"
224
- tr_id = zbx.add_trigger(options)
238
+ tr_id = zbx.add_or_get_trigger(t_id, options)
225
239
 
226
240
  options = {
227
241
  'gitems' => [
@@ -273,4 +287,4 @@ options = {
273
287
  "templateid" => "0"
274
288
  }
275
289
 
276
- g_id = zbx.add_graph(options)
290
+ g_id = zbx.add_or_get_graph(t_id, options)
@@ -0,0 +1,71 @@
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_named"
14
+ app_name = "named"
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
+ # 'named process exists'
46
+ options = {
47
+ 'description' => "named process exists",
48
+ 'key_' => "proc.num[named]",
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 'named process exists' to #{template_name}."
57
+ item_id = zbx.add_or_get_item(t_id, options)
58
+
59
+ # TRIGGERS
60
+ options = {
61
+ 'description' => "named process exists",
62
+ 'expression' => "{#{template_name}:proc.num[named].last(0)}<1",
63
+ 'priority' => 5, # disaster
64
+ 'templateid' => 0,
65
+ 'comments' => "named process exists (disaster)",
66
+ 'type' => 0,
67
+ 'status' => '0'
68
+ }
69
+
70
+ p " ** Add 'named process exists' trigger"
71
+ tr_id = zbx.add_or_get_trigger(t_id, options)
data/examples/zabbix_net CHANGED
@@ -27,14 +27,14 @@ zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
27
27
 
28
28
  # Create new template
29
29
  p " * Creating template #{template_name}."
30
- g_id = zbx.get_group_id(group_name)
30
+ g_id = zbx.add_or_get_group(group_name)
31
31
 
32
32
  options = {
33
33
  'groups' => [ g_id.to_i ],
34
34
  'host' => template_name
35
35
  }
36
36
 
37
- t_id = zbx.add_template(options)
37
+ t_id = zbx.add_or_get_template(options)
38
38
 
39
39
  # Create application #{app_name}
40
40
  p " ** Create application #{app_name}."
@@ -42,7 +42,7 @@ application = {
42
42
  'hostid' => t_id.to_i,
43
43
  'name' => app_name
44
44
  }
45
- a_id = zbx.add_application(application)
45
+ a_id = zbx.add_or_get_application(t_id, application)
46
46
 
47
47
  # 'Net #{interface_name} incoming traffic'
48
48
  options = {
@@ -53,14 +53,13 @@ options = {
53
53
  'history' => 7,
54
54
  'trends' => 30,
55
55
  'delay' => 60,
56
- 'value_type' => 0,
56
+ 'value_type' => 3,
57
57
  'units' => 'Bps',
58
58
  'value_type' => '3', # Numeric (unsigned)
59
59
  'delta' => 1 # Store as delta (Speed per second)
60
60
  }
61
61
  p " ** Add 'Net #{interface_name} incoming, B' to #{template_name}."
62
-
63
- i_id = zbx.add_item(options)
62
+ net_in_item_id = zbx.add_or_get_item(t_id, options)
64
63
 
65
64
  # 'Net #{interface_name} outgoing traffic'
66
65
  options = {
@@ -71,12 +70,149 @@ options = {
71
70
  'history' => 7,
72
71
  'trends' => 30,
73
72
  'delay' => 60,
74
- 'value_type' => 0,
73
+ 'value_type' => 3,
75
74
  'units' => 'Bps',
76
75
  'value_type' => '3', # Numeric (unsigned)
77
76
  'delta' => 1 # Store as delta (Speed per second)
78
77
 
79
78
  }
80
79
  p " ** Add 'Net #{interface_name} outgoing, B' to #{template_name}."
80
+ net_out_item_id = zbx.add_or_get_item(t_id, options)
81
+
82
+ # 'Net #{interface_name} incoming errors'
83
+ options = {
84
+ 'description' => "Net #{interface_name} incoming errors, pkts",
85
+ 'key_' => "net.if.in[#{interface_name}, errors]",
86
+ 'hostid' => t_id.to_i,
87
+ 'applications' => [ a_id.to_i ],
88
+ 'history' => 7,
89
+ 'trends' => 30,
90
+ 'delay' => 60,
91
+ 'value_type' => 0,
92
+ 'units' => 'pkts',
93
+ 'value_type' => '3'
94
+ }
95
+ p " ** Add 'Net #{interface_name} incoming errors, pkts' to #{template_name}."
96
+ net_in_errs_item_id = zbx.add_or_get_item(t_id, options)
97
+
98
+ # 'Net #{interface_name} incoming errors'
99
+ options = {
100
+ 'description' => "Net #{interface_name} outgoing errors, pkts",
101
+ 'key_' => "net.if.out[#{interface_name}, errors]",
102
+ 'hostid' => t_id.to_i,
103
+ 'applications' => [ a_id.to_i ],
104
+ 'history' => 7,
105
+ 'trends' => 30,
106
+ 'delay' => 60,
107
+ 'value_type' => 0,
108
+ 'units' => 'pkts',
109
+ 'value_type' => '3'
110
+ }
111
+ p " ** Add 'Net #{interface_name} outgoing errors, pkts' to #{template_name}."
112
+ net_out_errs_item_id = zbx.add_or_get_item(t_id, options)
113
+
114
+ # 'Net #{interface_name} incoming dropped pkts'
115
+ options = {
116
+ 'description' => "Net #{interface_name} incoming dropped, pkts",
117
+ 'key_' => "net.if.in[#{interface_name}, dropped]",
118
+ 'hostid' => t_id.to_i,
119
+ 'applications' => [ a_id.to_i ],
120
+ 'history' => 7,
121
+ 'trends' => 30,
122
+ 'delay' => 60,
123
+ 'value_type' => 0,
124
+ 'units' => 'pkts',
125
+ 'value_type' => '3'
126
+ }
127
+ p " ** Add 'Net #{interface_name} incoming dropped, pkts' to #{template_name}."
128
+ net_in_drop_item_id = zbx.add_or_get_item(t_id, options)
129
+
130
+ # 'Net #{interface_name} outgoing dropped pkts'
131
+ options = {
132
+ 'description' => "Net #{interface_name} outgoing dropped, pkts",
133
+ 'key_' => "net.if.out[#{interface_name}, dropped]",
134
+ 'hostid' => t_id.to_i,
135
+ 'applications' => [ a_id.to_i ],
136
+ 'history' => 7,
137
+ 'trends' => 30,
138
+ 'delay' => 60,
139
+ 'value_type' => 0,
140
+ 'units' => 'pkts',
141
+ 'value_type' => '3'
142
+ }
143
+ p " ** Add 'Net #{interface_name} outgoing dropped, pkts' to #{template_name}."
144
+ net_out_drop_item_id = zbx.add_or_get_item(t_id, options)
145
+
146
+ ## GRAPHS
147
+ options = {
148
+ "gitems" => [
149
+ {
150
+ "itemid" => net_in_item_id,
151
+ "drawtype" => "0",
152
+ "sortorder" => "0",
153
+ "color" => "AA0000",
154
+ "yaxisside" => "0",
155
+ "calc_fnc" => "2",
156
+ "type" => "0",
157
+ "periods_cnt" => "5"
158
+ },
159
+ {
160
+ "itemid" => net_out_item_id,
161
+ "drawtype" => "0",
162
+ "sortorder" => "0",
163
+ "color" => "009900",
164
+ "yaxisside" => "0",
165
+ "calc_fnc" => "2",
166
+ "type" => "0",
167
+ "periods_cnt" => "5"
168
+ },
169
+ {
170
+ "itemid" => net_in_errs_item_id,
171
+ "drawtype" => "0",
172
+ "sortorder" => "0",
173
+ "color" => "0000BB",
174
+ "yaxisside" => "0",
175
+ "calc_fnc" => "2",
176
+ "type" => "0",
177
+ "periods_cnt" => "5"
178
+ },
179
+ {
180
+ "itemid" => net_out_errs_item_id,
181
+ "drawtype" => "0",
182
+ "sortorder" => "0",
183
+ "color" => "888888",
184
+ "yaxisside" => "0",
185
+ "calc_fnc" => "2",
186
+ "type" => "0",
187
+ "periods_cnt" => "5"
188
+ },
189
+ {
190
+ "itemid" => net_in_drop_item_id,
191
+ "drawtype" => "0",
192
+ "sortorder" => "0",
193
+ "color" => "00BBBB",
194
+ "yaxisside" => "0",
195
+ "calc_fnc" => "2",
196
+ "type" => "0",
197
+ "periods_cnt" => "5"
198
+ },
199
+ {
200
+ "itemid" => net_out_drop_item_id,
201
+ "drawtype" => "0",
202
+ "sortorder" => "0",
203
+ "color" => "BB00BB",
204
+ "yaxisside" => "0",
205
+ "calc_fnc" => "2",
206
+ "type" => "0",
207
+ "periods_cnt" => "5"
208
+ }
209
+ ],
210
+ "show_triggers" => "0",
211
+ "name" => "Network on #{interface_name}",
212
+ "width" => "900",
213
+ "height" => "200",
214
+ "templateid" => "0"
215
+ }
81
216
 
82
- i_id = zbx.add_item(options)
217
+ p " ** Add 'Network on #{interface_name} graph'"
218
+ g_id = zbx.add_or_get_graph(t_id, options)