zabbapi 3.0.1 → 3.0.3
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 +4 -4
- data/exe/wdp +25 -0
- data/lib/zabbapi/version.rb +1 -1
- data/lib/zabbapi.rb +235 -22
- data/zabbapi.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4488aac65f59251d11797e0122e91df49966105d
|
4
|
+
data.tar.gz: 8ca3649edf4da77a9e5bb560bc3c6144e3ccf7a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c752e5fa0ee84d3b9c8b7c57bf8cb26e712e9c158b38872d208c55fc4580ca2b12582ca24fdf0854120119fe44707961e56aaeb34889c86f8725531f561228f8
|
7
|
+
data.tar.gz: 79cb59a5d1de90a3de5ffa421b676aa253ed5dfafc9bc08ff43894e36469d254266756a63f410b606c07b603311e898ae5d413d825a6df436fad0cf408398079
|
data/exe/wdp
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'zabbapi'
|
3
|
+
$type = ARGV[0]
|
4
|
+
$host = ARGV[1]
|
5
|
+
$name = ARGV[2]
|
6
|
+
$email = ARGV[3]
|
7
|
+
$activeif = ARGV[4]
|
8
|
+
$ip = ARGV[5]
|
9
|
+
if $type == "del"
|
10
|
+
$host.nil? ? abort("miss param hostname; please use $ wda del <hostname>") : PolZabbapi::WatchDog.new.wddel($host)
|
11
|
+
elsif $type == "add"
|
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
|
+
PolZabbapi::WatchDog.new.wdadd($host, $name , $email , $activeif , $ip)
|
16
|
+
end
|
17
|
+
elsif $type == "update"
|
18
|
+
PolZabbapi::WatchDog.new.update($host)
|
19
|
+
else
|
20
|
+
puts "error input. please use:"
|
21
|
+
puts " for add:"
|
22
|
+
puts "wdp add <hostname> <name> <email> <activeif> <ip>"
|
23
|
+
puts " for del:"
|
24
|
+
puts "wdp del <hostname>"
|
25
|
+
end
|
data/lib/zabbapi/version.rb
CHANGED
data/lib/zabbapi.rb
CHANGED
@@ -15,6 +15,9 @@ credentials = JSON.parse(file)
|
|
15
15
|
$wd_host = credentials['host']
|
16
16
|
$wd_admin_login = credentials['login']
|
17
17
|
$wd_admin_pass = credentials['pass']
|
18
|
+
$wd_host_p = credentials['host1']
|
19
|
+
$wd_admin_login_p = credentials['login1']
|
20
|
+
$wd_admin_pass_p = credentials['pass1']
|
18
21
|
|
19
22
|
class WatchDog
|
20
23
|
|
@@ -118,7 +121,7 @@ end
|
|
118
121
|
)
|
119
122
|
|
120
123
|
getuserid = Hash[*getuserid]
|
121
|
-
|
124
|
+
$user_id_glob = getuserid["userid"]
|
122
125
|
zbx.query(:method => "user.addmedia",
|
123
126
|
:params => {
|
124
127
|
:users => { :userid => getuserid["userid"]},
|
@@ -233,7 +236,6 @@ end
|
|
233
236
|
abort "Its not error!!!! please wait 5 min , and update host , because new iface not discovered."
|
234
237
|
end
|
235
238
|
begin
|
236
|
-
|
237
239
|
iface = "Traffic " + @activeif
|
238
240
|
iface = "Traffic on " + @activeif unless ifaceknow.include? @activeif
|
239
241
|
$graphtoscreen1 = zbx.graphs.get_ids_by_host(:host => @hostname , :filter => iface )
|
@@ -249,7 +251,7 @@ end
|
|
249
251
|
$graphtoscreen5 = $graphtoscreen5.map(&:to_i)
|
250
252
|
$graphtoscreen6 = $graphtoscreen6.map(&:to_i)
|
251
253
|
|
252
|
-
zbx.screens.get_or_create_for_host(
|
254
|
+
temaral = zbx.screens.get_or_create_for_host(
|
253
255
|
:hosts_id => [zbx.hosts.get_id(:host => @hostname)],
|
254
256
|
:screen_name => @hostname,
|
255
257
|
:height => 180,
|
@@ -260,6 +262,7 @@ end
|
|
260
262
|
:valign => 0,
|
261
263
|
:graphids => [ $graphtoscreen1[0] , $graphtoscreen2[0] , $graphtoscreen3[0] , $graphtoscreen4[0] , $graphtoscreen5[0] , $graphtoscreen6[0] ]
|
262
264
|
)
|
265
|
+
|
263
266
|
rescue
|
264
267
|
iface = "Traffic " + @activeif
|
265
268
|
$graphtoscreen1 = zbx.graphs.get_ids_by_host(:host => @hostname , :filter => iface )
|
@@ -283,28 +286,238 @@ end
|
|
283
286
|
:graphids => [ $graphtoscreen1[0] , $graphtoscreen2[0] , $graphtoscreen3[0] , $graphtoscreen4[0] ]
|
284
287
|
)
|
285
288
|
end
|
289
|
+
|
290
|
+
getuserid = zbx.query(
|
291
|
+
:method => "user.get",
|
292
|
+
:params => {
|
293
|
+
:filter => { :alias => ["#{@name}"] },
|
294
|
+
:output => {
|
295
|
+
:filter => "userid"
|
296
|
+
}
|
297
|
+
}
|
298
|
+
|
299
|
+
)
|
300
|
+
getuserid = Hash[*getuserid]
|
301
|
+
@user_id_glob = getuserid["userid"]
|
302
|
+
triggers = zbx.query(
|
303
|
+
:method => "screen.update",
|
304
|
+
:params => {
|
305
|
+
:screenid => "#{temaral}",
|
306
|
+
:userid => @user_id_glob
|
307
|
+
}
|
308
|
+
)
|
286
309
|
puts "Done!"
|
287
310
|
end
|
288
311
|
end
|
289
312
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
313
|
+
end
|
314
|
+
|
315
|
+
module PolZabbapi
|
316
|
+
|
317
|
+
class WatchDog
|
318
|
+
|
319
|
+
def wddel(hostname)
|
320
|
+
|
321
|
+
@hostname = hostname
|
322
|
+
zbx = ZabbixApi.connect(
|
323
|
+
:url => 'https://' + $wd_host_p + '/api_jsonrpc.php',
|
324
|
+
:user => $wd_admin_login_p ,
|
325
|
+
:password => $wd_admin_pass_p
|
326
|
+
)
|
327
|
+
begin
|
328
|
+
zbx.hosts.delete zbx.hosts.get_id(:host => @hostname )
|
329
|
+
rescue
|
330
|
+
puts "unknown host with hostname " + @hostname
|
331
|
+
else
|
332
|
+
begin
|
333
|
+
$idscreenfordel_p = zbx.screens.get(
|
334
|
+
:name => @hostname
|
335
|
+
)
|
336
|
+
$idscreenfordel_p = Hash[*$idscreenfordel_p]
|
337
|
+
zbx.screens.delete(
|
338
|
+
$idscreenfordel_p["screenid"]
|
339
|
+
)
|
340
|
+
rescue
|
341
|
+
puts "host with hostname " + @hostname + " deleted"
|
342
|
+
else
|
343
|
+
puts "host with hostname " + @hostname + " deleted"
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
def wdadd(hostname , name , email , activeif , ip)
|
349
|
+
@hostname = hostname
|
350
|
+
@name = name
|
351
|
+
@email = email
|
352
|
+
@activeif = activeif
|
353
|
+
@ip = ip
|
354
|
+
passwd = [*('a'..'z'),*('0'..'9')].sample(12).join
|
355
|
+
|
356
|
+
puts "Add host to zabbix..."
|
357
|
+
zbx = ZabbixApi.connect(
|
358
|
+
:url => 'https://' + $wd_host_p + '/api_jsonrpc.php',
|
359
|
+
:user => $wd_admin_login_p ,
|
360
|
+
:password => $wd_admin_pass_p
|
361
|
+
)
|
362
|
+
begin
|
363
|
+
zbx.hostgroups.create(:name => @name)
|
364
|
+
rescue
|
365
|
+
puts "HostGroup exist!"
|
366
|
+
else
|
367
|
+
puts "HostGroup created!"
|
368
|
+
end
|
369
|
+
|
370
|
+
begin
|
371
|
+
zbx.usergroups.get_or_create(:name => @name)
|
372
|
+
rescue
|
373
|
+
puts "UserGroup exist!"
|
374
|
+
else
|
375
|
+
zbx.query(
|
376
|
+
:method => "usergroup.massadd",
|
377
|
+
:params => {
|
378
|
+
:usrgrpids => [zbx.usergroups.get_id(:name => @name)],
|
379
|
+
:rights => [{
|
380
|
+
:groupid => [zbx.usergroups.get_id(:name => @name)],
|
381
|
+
:id => zbx.hostgroups.get_id(:name => @name) ,
|
382
|
+
:permission => 2
|
383
|
+
}]
|
384
|
+
}
|
385
|
+
)
|
386
|
+
puts "UserGroup #{@name} added.."
|
387
|
+
end
|
388
|
+
|
389
|
+
begin
|
390
|
+
zbx.users.create(
|
391
|
+
:alias => @name,
|
392
|
+
:type => 1,
|
393
|
+
:passwd => passwd,
|
394
|
+
:usrgrps => [zbx.usergroups.get_id(:name => @name)],
|
395
|
+
:url => '/screens.php'
|
396
|
+
)
|
397
|
+
rescue
|
398
|
+
puts "User exist!"
|
399
|
+
else
|
400
|
+
puts "User created!"
|
401
|
+
puts " "
|
402
|
+
puts "#WDPolus"
|
403
|
+
puts 'https://' + $wd_host_p
|
404
|
+
puts "#{@name} / #{passwd}"
|
405
|
+
puts " "
|
406
|
+
|
407
|
+
begin
|
408
|
+
getuserid = zbx.query(
|
409
|
+
:method => "user.get",
|
410
|
+
:params => {
|
411
|
+
:filter => { :alias => ["#{@name}"] },
|
412
|
+
:output => {
|
413
|
+
:filter => "userid"
|
414
|
+
}
|
415
|
+
}
|
416
|
+
|
417
|
+
)
|
418
|
+
|
419
|
+
getuserid = Hash[*getuserid]
|
420
|
+
|
421
|
+
zbx.query(:method => "user.addmedia",
|
422
|
+
:params => {
|
423
|
+
:users => { :userid => getuserid["userid"]},
|
424
|
+
:medias => [
|
425
|
+
{
|
426
|
+
:mediatypeid => "1" ,
|
427
|
+
:sendto => @email,
|
428
|
+
:active => 0,
|
429
|
+
:severity => 48,
|
430
|
+
:period => "1-7,00:00-24:00"
|
431
|
+
}
|
432
|
+
]
|
433
|
+
}
|
434
|
+
)
|
435
|
+
rescue
|
436
|
+
puts "UserMedia exist!"
|
437
|
+
else
|
438
|
+
puts "UserMedia added to #{@name}"
|
439
|
+
end
|
440
|
+
|
441
|
+
end
|
442
|
+
|
443
|
+
if $host.chars.first == 'l'
|
444
|
+
$tplid_p = '10001'
|
445
|
+
elsif $host.chars.first == 'f'
|
446
|
+
$tplid_p = '10075'
|
447
|
+
else
|
448
|
+
$tplid_p = '10001'
|
449
|
+
end
|
450
|
+
|
451
|
+
begin
|
452
|
+
zbx.query(:method => "host.create" ,
|
453
|
+
:params => {
|
454
|
+
:host => @hostname ,
|
455
|
+
:interfaces => {
|
456
|
+
:type => 1,
|
457
|
+
:main => 1,
|
458
|
+
:ip => @ip ,
|
459
|
+
:dns => "",
|
460
|
+
:useip => 1,
|
461
|
+
:port => 10050
|
462
|
+
},
|
463
|
+
:groups => [{ :groupid => zbx.hostgroups.get_id(:name => @name) }],
|
464
|
+
:templates => { :templateid => $tplid_p }
|
465
|
+
}
|
466
|
+
)
|
467
|
+
rescue
|
468
|
+
puts "Host exist or got error!"
|
469
|
+
abort "please del #{@hostname} first."
|
470
|
+
else
|
471
|
+
puts "Added host #{@hostname} to #{@name} !"
|
472
|
+
end
|
473
|
+
|
474
|
+
begin
|
475
|
+
zbx.query(
|
476
|
+
:method => "action.create" ,
|
477
|
+
:params => [ {
|
478
|
+
:name => "all #{@name} triggs",
|
479
|
+
:eventsource => 0 ,
|
480
|
+
:status => 0 ,
|
481
|
+
:evaltype => 0 ,
|
482
|
+
:esc_period => 3600 ,
|
483
|
+
:def_shortdata => '{TRIGGER.NAME}: {STATUS}' ,
|
484
|
+
:def_longdata => '{TRIGGER.NAME}: {STATUS}',
|
485
|
+
:usrgrpid => zbx.usergroups.get_id(:name => @name),
|
486
|
+
:conditions => [
|
487
|
+
{
|
488
|
+
:conditiontype => 0 ,
|
489
|
+
:operator => 0 ,
|
490
|
+
:value => zbx.hostgroups.get_id(:name => @name)
|
491
|
+
}
|
492
|
+
],
|
493
|
+
:operations => [
|
494
|
+
{
|
495
|
+
:operationtype => 0 ,
|
496
|
+
:opmessage_grp => [
|
497
|
+
{
|
498
|
+
:usrgrpid => zbx.usergroups.get_id(:name => @name)
|
499
|
+
}],
|
500
|
+
:opmessage => {:default_msg => 1 }
|
501
|
+
}
|
502
|
+
]
|
503
|
+
}]
|
504
|
+
)
|
505
|
+
rescue
|
506
|
+
puts "Action exist!"
|
507
|
+
end
|
508
|
+
|
509
|
+
puts "Update host templates..."
|
510
|
+
|
511
|
+
zbx.templates.mass_add(
|
512
|
+
:hosts_id => [zbx.hosts.get_id(:host => @hostname)],
|
513
|
+
:templates_id => [10104 , 10073]
|
514
|
+
)
|
309
515
|
|
516
|
+
puts "Add host to group..."
|
517
|
+
|
518
|
+
#zbx.query(:method => "hostgroup.massadd" , :params => {:groups => {:groupid => "100100000000614"} , :hosts => {:hostid => zbx.hosts.get_id(:host => @hostname)}} )
|
519
|
+
|
520
|
+
puts "Done!"
|
521
|
+
end
|
522
|
+
end
|
310
523
|
end
|
data/zabbapi.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
26
|
spec.bindir = "exe"
|
27
27
|
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.executables = ["wda"]
|
28
|
+
spec.executables = ["wda","wdp"]
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
spec.add_dependency "zabbixapi" , "=2.4.7"
|
31
31
|
spec.add_dependency "json" , '~> 1.8', '>= 1.8.3'
|
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: 3.0.
|
4
|
+
version: 3.0.3
|
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-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zabbixapi
|
@@ -83,6 +83,7 @@ email:
|
|
83
83
|
- nikolaev.makc@gmail.com
|
84
84
|
executables:
|
85
85
|
- wda
|
86
|
+
- wdp
|
86
87
|
extensions: []
|
87
88
|
extra_rdoc_files: []
|
88
89
|
files:
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- bin/console
|
96
97
|
- bin/setup
|
97
98
|
- exe/wda
|
99
|
+
- exe/wdp
|
98
100
|
- lib/zabbapi.rb
|
99
101
|
- lib/zabbapi/version.rb
|
100
102
|
- zabbapi.gemspec
|