zabbapi 2.4.13 → 2.4.14

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 203f967100c1bf3abb427e95601090d99739d0ab
4
- data.tar.gz: 6c7a8dfd3e43355c71c3c50a7b931832a358b394
3
+ metadata.gz: f5957f96378fd50fd44ee94345e6a5f74a8a8179
4
+ data.tar.gz: 7439aef6565e08a8f7cf664257cf033845533f5c
5
5
  SHA512:
6
- metadata.gz: f7208193f2529e4392ce8ba0bb497d752445e85bdc50b7b78599ccd2ebb2f61c764a5aa1f55e43d57fa2e4c29d024b528e88424d6a093b9d940259fe40deb11d
7
- data.tar.gz: 70fa6e6e6a03fc2f759a5409799578261a5d2498d01d8bb8dea8cd68e661ad970df0bf3bcfce72d9bac7bf8789292c430207fb86bef6177724f0e5bd0aa5a6a8
6
+ metadata.gz: ed42abf624e14bbe27afaade5c76830dc182874bcdd55f59829673a5e6acf835c162e41a4061c8c4ecefb419c3a74437c59223a3d58633eddf5c503febff7d80
7
+ data.tar.gz: 240d71b0bbf01e2b61dc4e6edda140a0f20255bce62795846c363a6ed8aa3acc242a963801bc2b9b873176f0a34355dd6192297956a001b29a342e905dacb1a8
data/exe/wda CHANGED
@@ -7,9 +7,13 @@ $email = ARGV[3]
7
7
  $activeif = ARGV[4]
8
8
  $ip = ARGV[5]
9
9
  if $type == "del"
10
- Zabbapi::WatchDog.new.wddel($host)
10
+ $host.nil? ? abort("miss param hostname; please use $ wda del <hostname>") : Zabbapi::WatchDog.new.wddel($host)
11
11
  elsif $type == "add"
12
- Zabbapi::WatchDog.new.wdadd($host, $name , $email , $activeif , $ip)
12
+ if $host.nil? or $name.nil? or $email.nil? or $activeif.nil? or $ip.nil?
13
+ abort("miss params; please use wda add <hostname> <name> <email> <activeif> <ip>")
14
+ else
15
+ Zabbapi::WatchDog.new.wdadd($host, $name , $email , $activeif , $ip)
16
+ end
13
17
  elsif $type == "update"
14
18
  Zabbapi::WatchDog.new.update($host)
15
19
  else
@@ -18,6 +22,6 @@ else
18
22
  puts "wda add <hostname> <name> <email> <activeif> <ip>"
19
23
  puts " for del:"
20
24
  puts "wda del <hostname>"
21
- puts " for update:"
22
- puts "wda update <hostname>"
25
+ # puts " for update:"
26
+ # puts "wda update <hostname>"
23
27
  end
data/lib/zabbapi.rb CHANGED
@@ -3,18 +3,20 @@ require 'zabbixapi'
3
3
  require 'json'
4
4
  require 'mechanize'
5
5
  require 'hpricot'
6
- #require 'openssl'
6
+
7
7
  module Zabbapi
8
+
8
9
  if not File.exist?('/etc/config.json')
9
10
  abort("please create config file with credentials /etc/config.json")
10
11
  end
12
+
11
13
  file = File.read('/etc/config.json')
12
14
  credentials = JSON.parse(file)
13
15
  $wd_host = credentials['host']
14
16
  $wd_admin_login = credentials['login']
15
17
  $wd_admin_pass = credentials['pass']
16
18
 
17
- class WatchDog
19
+ class WatchDog
18
20
 
19
21
  def wddel(hostname)
20
22
  @hostname = hostname
@@ -37,11 +39,11 @@ $wd_admin_pass = credentials['pass']
37
39
  $idscreenfordel["screenid"]
38
40
  )
39
41
  rescue
40
- puts "host with hostname " + @hostname + " deleted"
41
- else
42
- puts "host with hostname " + @hostname + " deleted"
43
- end
44
- end
42
+ puts "host with hostname " + @hostname + " deleted"
43
+ else
44
+ puts "host with hostname " + @hostname + " deleted"
45
+ end
46
+ end
45
47
  end
46
48
 
47
49
  def wdadd(hostname , name , email , activeif , ip)
@@ -89,28 +91,28 @@ end
89
91
  zbx.users.create(
90
92
  :alias => $name,
91
93
  :type => 1,
92
- :passwd => passwd,
93
- :usrgrps => [zbx.usergroups.get_id(:name => @name)],
94
- :url => '/screens.php'
94
+ :passwd => passwd,
95
+ :usrgrps => [zbx.usergroups.get_id(:name => @name)],
96
+ :url => '/screens.php'
95
97
  )
96
98
  rescue
97
99
  puts "User exist!"
98
100
  else
99
101
  puts "User created!"
100
102
  puts " "
101
- puts "#WDAmhost"
103
+ puts "#Zabbix"
102
104
  puts 'https://' + $wd_host
103
105
  puts "#{@name} / #{passwd}"
104
106
  puts " "
105
-
107
+
106
108
  begin
107
109
  getuserid = zbx.query(
108
110
  :method => "user.get",
109
111
  :params => {
110
- :filter => { :alias => ["#{@name}"] },
111
- :output => {
112
- :filter => "userid"
113
- }
112
+ :filter => { :alias => ["#{@name}"] },
113
+ :output => {
114
+ :filter => "userid"
115
+ }
114
116
  }
115
117
 
116
118
  )
@@ -119,15 +121,15 @@ end
119
121
 
120
122
  zbx.query(:method => "user.addmedia",
121
123
  :params => {
122
- :users => { :userid => getuserid["userid"]},
123
- :medias => [
124
- {
125
- :mediatypeid => "100100000000001" ,
126
- :sendto => @email,
127
- :active => 0,
128
- :severity => 48,
129
- :period => "1-7,00:00-24:00"
130
- }
124
+ :users => { :userid => getuserid["userid"]},
125
+ :medias => [
126
+ {
127
+ :mediatypeid => "100100000000001" ,
128
+ :sendto => @email,
129
+ :active => 0,
130
+ :severity => 48,
131
+ :period => "1-7,00:00-24:00"
132
+ }
131
133
  ]
132
134
  }
133
135
  )
@@ -137,7 +139,7 @@ end
137
139
  puts "UserMedia added to #{@name}"
138
140
  end
139
141
 
140
-
142
+
141
143
  end
142
144
 
143
145
  if $host.chars.first == 'l'
@@ -151,17 +153,17 @@ end
151
153
  begin
152
154
  zbx.query(:method => "host.create" ,
153
155
  :params => {
154
- :host => @hostname ,
155
- :interfaces => {
156
- :type => 1,
157
- :main => 1,
158
- :ip => $ip ,
159
- :dns => "",
160
- :useip => 1,
161
- :port => 10050
162
- },
163
- :groups => [{ :groupid => zbx.hostgroups.get_id(:name => @name) }],
164
- :templates => { :templateid => $tplid }
156
+ :host => @hostname ,
157
+ :interfaces => {
158
+ :type => 1,
159
+ :main => 1,
160
+ :ip => $ip ,
161
+ :dns => "",
162
+ :useip => 1,
163
+ :port => 10050
164
+ },
165
+ :groups => [{ :groupid => zbx.hostgroups.get_id(:name => @name) }],
166
+ :templates => { :templateid => $tplid }
165
167
  }
166
168
  )
167
169
  rescue
@@ -175,7 +177,7 @@ end
175
177
  zbx.query(
176
178
  :method => "action.create" ,
177
179
  :params => [ {
178
- :name => "all #{@name} triggs",
180
+ :name => "all #{@name} triggs",
179
181
  :eventsource => 0 ,
180
182
  :status => 0 ,
181
183
  :evaltype => 0 ,
@@ -184,22 +186,22 @@ end
184
186
  :def_longdata => '{TRIGGER.NAME}: {STATUS}',
185
187
  :usrgrpid => zbx.usergroups.get_id(:name => @name),
186
188
  :conditions => [
187
- {
189
+ {
188
190
  :conditiontype => 0 ,
189
191
  :operator => 0 ,
190
192
  :value => zbx.hostgroups.get_id(:name => $name)
191
193
  }
192
194
  ],
193
195
  :operations => [
194
- {
196
+ {
195
197
  :operationtype => 0 ,
196
- :opmessage_grp => [
197
- {
198
- :usrgrpid => zbx.usergroups.get_id(:name => @name)
199
- }],
200
- :opmessage => {:default_msg => 1 }
201
- }
202
- ]
198
+ :opmessage_grp => [
199
+ {
200
+ :usrgrpid => zbx.usergroups.get_id(:name => @name)
201
+ }],
202
+ :opmessage => {:default_msg => 1 }
203
+ }
204
+ ]
203
205
  }]
204
206
  )
205
207
  rescue
@@ -214,7 +216,7 @@ end
214
216
  )
215
217
 
216
218
  puts "Add host to group..."
217
-
219
+
218
220
  zbx.query(:method => "hostgroup.massadd" , :params => {:groups => {:groupid => "100100000000614"} , :hosts => {:hostid => zbx.hosts.get_id(:host => @hostname)}} )
219
221
  begin
220
222
  puts "Update screen graphs..."
@@ -225,8 +227,8 @@ end
225
227
  abort "Its not error!!!! please wait 5 min , and update host , because new iface not discovered."
226
228
  end
227
229
  begin
228
-
229
- iface = "Traffic " + @activeif
230
+
231
+ iface = "Traffic " + @activeif
230
232
  iface = "Traffic on " + @activeif unless ifaceknow.include? @activeif
231
233
  $graphtoscreen1 = zbx.graphs.get_ids_by_host(:host => @hostname , :filter => iface )
232
234
  $graphtoscreen2 = zbx.graphs.get_ids_by_host(:host => @hostname , :filter => "CPU\ Utilization")
@@ -243,14 +245,14 @@ end
243
245
 
244
246
  zbx.screens.get_or_create_for_host(
245
247
  :hosts_id => [zbx.hosts.get_id(:host => @hostname)],
246
- :screen_name => @hostname,
247
- :height => 180,
248
- :width => 360,
249
- :vsize => 3,
250
- :hsize => 2,
251
- :halign => 0,
252
- :valign => 0,
253
- :graphids => [ $graphtoscreen1[0] , $graphtoscreen2[0] , $graphtoscreen3[0] , $graphtoscreen4[0] , $graphtoscreen5[0] , $graphtoscreen6[0] ]
248
+ :screen_name => @hostname,
249
+ :height => 180,
250
+ :width => 360,
251
+ :vsize => 3,
252
+ :hsize => 2,
253
+ :halign => 0,
254
+ :valign => 0,
255
+ :graphids => [ $graphtoscreen1[0] , $graphtoscreen2[0] , $graphtoscreen3[0] , $graphtoscreen4[0] , $graphtoscreen5[0] , $graphtoscreen6[0] ]
254
256
  )
255
257
  rescue
256
258
  iface = "Traffic " + @activeif
@@ -265,14 +267,14 @@ end
265
267
 
266
268
  zbx.screens.get_or_create_for_host(
267
269
  :hosts_id => [zbx.hosts.get_id(:host => @hostname)],
268
- :screen_name => @hostname,
269
- :height => 180,
270
- :width => 360,
271
- :vsize => 2,
272
- :hsize => 2,
273
- :halign => 0,
274
- :valign => 0,
275
- :graphids => [ $graphtoscreen1[0] , $graphtoscreen2[0] , $graphtoscreen3[0] , $graphtoscreen4[0] ]
270
+ :screen_name => @hostname,
271
+ :height => 180,
272
+ :width => 360,
273
+ :vsize => 2,
274
+ :hsize => 2,
275
+ :halign => 0,
276
+ :valign => 0,
277
+ :graphids => [ $graphtoscreen1[0] , $graphtoscreen2[0] , $graphtoscreen3[0] , $graphtoscreen4[0] ]
276
278
  )
277
279
  end
278
280
  puts "Done!"
@@ -280,23 +282,23 @@ end
280
282
  end
281
283
 
282
284
  #class UpdateHostTemplates
283
- def update(hostname)
284
- @hostname = hostname
285
- zbx = ZabbixApi.connect(
286
- :url => 'https://' + $wd_host + '/api_jsonrpc.php',
287
- :user => $wd_admin_login ,
288
- :password => $wd_admin_pass
289
- )
290
- zbx.templates.mass_add(
291
- :hosts_id => [zbx.hosts.get_id(:host => @hostname)],
292
- :templates_id => [100100000010962 , 100100000010003 , 100100000010099]
293
- )
294
- zbx.screens.get_or_create_for_host(
295
- :hosts_id => [zbx.hosts.get_id(:host => @hostname)],
296
- :screen_name => @hostname,
297
- :graphids => zbx.graphs.get_ids_by_host(:host => @hostname )
298
- )
299
- end
285
+ # def update(hostname)
286
+ # @hostname = hostname
287
+ # zbx = ZabbixApi.connect(
288
+ # :url => 'https://' + $wd_host + '/api_jsonrpc.php',
289
+ # :user => $wd_admin_login ,
290
+ # :password => $wd_admin_pass
291
+ # )
292
+ # zbx.templates.mass_add(
293
+ # :hosts_id => [zbx.hosts.get_id(:host => @hostname)],
294
+ # :templates_id => [100100000010962 , 100100000010003 , 100100000010099]
295
+ # )
296
+ # zbx.screens.get_or_create_for_host(
297
+ # :hosts_id => [zbx.hosts.get_id(:host => @hostname)],
298
+ # :screen_name => @hostname,
299
+ # :graphids => zbx.graphs.get_ids_by_host(:host => @hostname )
300
+ # )
301
+ # end
300
302
  #end
301
303
 
302
304
  end
@@ -1,3 +1,3 @@
1
1
  module Zabbapi
2
- VERSION = "2.4.13"
2
+ VERSION = "2.4.14"
3
3
  end
data/zabbapi.gemspec CHANGED
@@ -10,10 +10,10 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["nikolaev.makc@gmail.com"]
11
11
 
12
12
  spec.summary = %q{watch dog cli}
13
- spec.description = %q{ZabbixAPI for host create / delete / update}
13
+ spec.description = %q{ZabbixAPI CLI for host create / delete / update}
14
14
  spec.homepage = "https://rubygems.org/gems/zabbapi"
15
15
  spec.license = "MIT"
16
-
16
+ spec.required_ruby_version = '>=1.9.3'
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
18
  # delete this section to allow pushing this gem to any host.
19
19
  # if spec.respond_to?(:metadata)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.13
4
+ version: 2.4.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxn maxn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2016-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zabbixapi
@@ -78,7 +78,7 @@ dependencies:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
80
  version: 0.8.6
81
- description: ZabbixAPI for host create / delete / update
81
+ description: ZabbixAPI CLI for host create / delete / update
82
82
  email:
83
83
  - nikolaev.makc@gmail.com
84
84
  executables:
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: '0'
113
+ version: 1.9.3
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="