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.
@@ -26,14 +26,14 @@ zbx.debug = true
26
26
 
27
27
  # Create new template
28
28
  p " * Creating template #{template_name}."
29
- g_id = zbx.get_group_id(group_name)
29
+ g_id = zbx.add_or_get_group(group_name)
30
30
 
31
31
  options = {
32
32
  'groups' => [ g_id.to_i ],
33
33
  'host' => template_name
34
34
  }
35
35
 
36
- t_id = zbx.add_template(options)
36
+ t_id = zbx.add_or_get_template(options)
37
37
 
38
38
  # Create application #{app_name}
39
39
  app_name = "Disk_" + disk_name.gsub(/\//, "_")
@@ -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
  # 'IOPS Read on #{disk_name} avg5'
48
48
  options = {
@@ -58,7 +58,7 @@ options = {
58
58
  }
59
59
  p " ** Add 'IOPS Read on #{disk_name} avg5' to #{template_name}."
60
60
 
61
- i_id = zbx.add_item(options)
61
+ i_id = zbx.add_or_get_item(t_id, options)
62
62
 
63
63
  # 'IOPS Write on #{disk_name} avg5'
64
64
  options = {
@@ -74,7 +74,7 @@ options = {
74
74
  }
75
75
  p " ** Add 'IOPS Write on #{disk_name} avg5' to #{template_name}."
76
76
 
77
- i_id = zbx.add_item(options)
77
+ i_id = zbx.add_or_get_item(t_id, options)
78
78
 
79
79
  # 'BPS Read on #{disk_name} avg5'
80
80
  options = {
@@ -95,7 +95,7 @@ options = {
95
95
  }
96
96
  p " ** Add 'BPS Read on #{disk_name} avg5' to #{template_name}."
97
97
 
98
- bps_r_avg5_id = zbx.add_item(options)
98
+ bps_r_avg5_id = zbx.add_or_get_item(t_id, options)
99
99
 
100
100
  # 'BPS Write on #{disk_name}'
101
101
  options = {
@@ -116,7 +116,7 @@ options = {
116
116
  }
117
117
  p " ** Add 'BPS Write on #{disk_name} avg5' to #{template_name}."
118
118
 
119
- bps_w_avg5_id = zbx.add_item(options)
119
+ bps_w_avg5_id = zbx.add_or_get_item(t_id, options)
120
120
 
121
121
  # Create graph 'Disk usage #{disk_name}'
122
122
  options = {
@@ -149,4 +149,4 @@ options = {
149
149
  "templateid" => "0"
150
150
  }
151
151
  p " ** Add 'Disk usage #{disk_name} graph'"
152
- g_id = zbx.add_graph(options)
152
+ g_id = zbx.add_or_get_graph(t_id, options)
@@ -11,7 +11,7 @@ mount_point = opt["m"]
11
11
  group_name = opt["g"]
12
12
  zabbix_env = opt["E"]
13
13
 
14
- if mount_point == "/"
14
+ if ( mount_point == "/" )
15
15
  template_name = "TMPL_Filesystem_root"
16
16
  app_name = "Filesystem_root"
17
17
  else
@@ -32,14 +32,14 @@ zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
32
32
 
33
33
  # Create new template
34
34
  p " * Creating template #{template_name}."
35
- g_id = zbx.get_group_id(group_name)
35
+ g_id = zbx.add_or_get_group(group_name)
36
36
 
37
37
  options = {
38
38
  'groups' => [ g_id.to_i ],
39
39
  'host' => template_name
40
40
  }
41
41
 
42
- t_id = zbx.add_template(options)
42
+ t_id = zbx.add_or_get_template(options)
43
43
 
44
44
  # Create application #{app_name}
45
45
  p " ** Create application #{app_name}."
@@ -48,7 +48,7 @@ application = {
48
48
  'name' => app_name
49
49
  }
50
50
 
51
- a_id = zbx.add_application(application)
51
+ a_id = zbx.add_or_get_application(t_id, application)
52
52
 
53
53
  # Total disk space on #{mount_point}
54
54
  options = {
@@ -60,11 +60,11 @@ options = {
60
60
  'history' => 7,
61
61
  'trends' => 30,
62
62
  'delay' => 600,
63
- 'value_type' => 0
63
+ 'value_type' => 3
64
64
  }
65
65
 
66
66
  p " ** Add 'Total disk space on #{mount_point}' to #{template_name}."
67
- total_in_b_item_id = zbx.add_item(options)
67
+ total_in_b_item_id = zbx.add_or_get_item(t_id, options)
68
68
 
69
69
  # Used disk space on #{mount_point}
70
70
  options = {
@@ -76,11 +76,11 @@ options = {
76
76
  'history' => 7,
77
77
  'trends' => 30,
78
78
  'delay' => 60,
79
- 'value_type' => 0
79
+ 'value_type' => 3
80
80
  }
81
81
 
82
82
  p " ** Add 'Used disk space on #{mount_point}' to #{template_name}."
83
- used_in_b_item_id = zbx.add_item(options)
83
+ used_in_b_item_id = zbx.add_or_get_item(t_id, options)
84
84
 
85
85
  # Use disk space on #{mount_point} in %
86
86
  options = {
@@ -95,7 +95,7 @@ options = {
95
95
  }
96
96
 
97
97
  p " ** Add 'Used disk space on #{mount_point} in %' to #{template_name}."
98
- i_id = zbx.add_item(options)
98
+ i_id = zbx.add_or_get_item(t_id, options)
99
99
 
100
100
  # Free disk space on #{mount_point}
101
101
  options = {
@@ -109,11 +109,11 @@ options = {
109
109
  'history' => 7,
110
110
  'trends' => 30,
111
111
  'delay' => 60,
112
- 'value_type' => 0
112
+ 'value_type' => 3
113
113
  }
114
114
 
115
115
  p " ** Add 'Free disk space on #{mount_point}' to #{template_name}."
116
- i_id = zbx.add_item(options)
116
+ i_id = zbx.add_or_get_item(t_id, options)
117
117
 
118
118
  # Free disk space on #{mount_point} in %
119
119
  options = {
@@ -130,7 +130,7 @@ options = {
130
130
  }
131
131
 
132
132
  p " ** Add 'Free disk space on #{mount_point} in %' to #{template_name}."
133
- i_id = zbx.add_item(options)
133
+ i_id = zbx.add_or_get_item(t_id, options)
134
134
 
135
135
  # Free number of inodes on #{mount_point}
136
136
  options = {
@@ -142,11 +142,11 @@ options = {
142
142
  'history' => 7,
143
143
  'trends' => 30,
144
144
  'delay' => 60,
145
- 'value_type' => 0
145
+ 'value_type' => 3
146
146
  }
147
147
 
148
148
  p " ** Add 'Free number of inodes on #{mount_point}' to #{template_name}."
149
- i_id = zbx.add_item(options)
149
+ i_id = zbx.add_or_get_item(t_id, options)
150
150
 
151
151
  # Free number of inodes on #{mount_point} in %
152
152
  options = {
@@ -161,7 +161,7 @@ options = {
161
161
  }
162
162
 
163
163
  p " ** Add 'Free number of inodes on #{mount_point} in %' to #{template_name}."
164
- i_id = zbx.add_item(options)
164
+ i_id = zbx.add_or_get_item(t_id, options)
165
165
 
166
166
  ## TRIGGERS
167
167
  options = {
@@ -175,7 +175,7 @@ options = {
175
175
  }
176
176
 
177
177
  p " ** Add 'Free disk space on #{mount_point} warning trigger'"
178
- tr_id = zbx.add_trigger(options)
178
+ tr_id = zbx.add_or_get_trigger(t_id, options)
179
179
 
180
180
  options = {
181
181
  'description' => "Free disk space on #{mount_point}",
@@ -188,7 +188,7 @@ options = {
188
188
  }
189
189
 
190
190
  p " ** Add 'Free disk space on #{mount_point} disaster trigger'"
191
- tr_id = zbx.add_trigger(options)
191
+ tr_id = zbx.add_or_get_trigger(t_id, options)
192
192
 
193
193
  options = {
194
194
  'description' => "Free inodes on #{mount_point}",
@@ -201,7 +201,7 @@ options = {
201
201
  }
202
202
 
203
203
  p " ** Add 'Free inodes on #{mount_point} warning trigger'"
204
- tr_id = zbx.add_trigger(options)
204
+ tr_id = zbx.add_or_get_trigger(t_id, options)
205
205
 
206
206
  options = {
207
207
  'description' => "Free inodes on #{mount_point}",
@@ -214,7 +214,7 @@ options = {
214
214
  }
215
215
 
216
216
  p " ** Add 'Free inodes on #{mount_point} disaster trigger'"
217
- tr_id = zbx.add_trigger(options)
217
+ tr_id = zbx.add_or_get_trigger(t_id, options)
218
218
 
219
219
  options = {
220
220
  'gitems' => [
@@ -246,4 +246,4 @@ options = {
246
246
  "templateid" => "0"
247
247
  }
248
248
  p " ** Add 'Disk space on #{mount_point} graph'"
249
- g_id = zbx.add_graph(options)
249
+ g_id = zbx.add_or_get_graph(t_id, options)
@@ -0,0 +1,25 @@
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)
@@ -0,0 +1,100 @@
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)
@@ -0,0 +1,37 @@
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)
@@ -0,0 +1,131 @@
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)