zcollective 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/zcollective +97 -60
  3. metadata +13 -13
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 181f139c7efb1dd070e2a14be960039dbd86b1ad
4
+ data.tar.gz: 2ed58c7810a4a50851e984943052f7ef7bd20f5c
5
+ SHA512:
6
+ metadata.gz: 59c2c157fbdb4cb457a415e18e3bed14b5423d07dbf161e91167c450972f0fbbe1298da0536a60946c41e9ef7f503db6839a8d019576d2de03d6b5858cccbc1a
7
+ data.tar.gz: 0140666a8e3717506d3f82edf4e7a841b61e09295941bf2ca37bbfb20f2548177b14a88f774a04c0d8283080d4cf46c6b391fd738b2044c746f94266af1cea10
data/bin/zcollective CHANGED
@@ -75,7 +75,7 @@ optparse = OptionParser.new do |opts|
75
75
  end
76
76
 
77
77
  options[:connect_by_ip] = 0
78
- opts.on('--connect-by-ip','Configure newly added hosts to connect by IP address instead of DNS') do
78
+ opts.on('--connect-by-ip','Configure newly added hosts to connect by IP address instead of DNS. Not valid with --host.') do
79
79
  options[:connect_by_ip] = 1
80
80
  end
81
81
 
@@ -89,12 +89,34 @@ optparse = OptionParser.new do |opts|
89
89
  options[:timeout] = t.to_i
90
90
  end
91
91
 
92
+ options[:host]
93
+ opts.on('-h', '--host hostname', 'Skip mcollective host discovery, use the given host') do |h|
94
+ options[:host] = h
95
+ end
96
+
97
+ options[:template]
98
+ opts.on('-t', '--template template', 'Add the given template to the host specified with --host.') do |t|
99
+ options[:template] = t
100
+ end
101
+
92
102
  end
93
103
 
94
104
  begin
95
105
 
96
106
  optparse.parse!
97
107
 
108
+ if !options[:host] and options[:template]
109
+ $stderr.puts "Can't use --template without --host"
110
+ $stderr.puts optparse
111
+ exit 2
112
+ end
113
+
114
+ if options[:host] and options[:connect_by_ip] == 1
115
+ $stderr.puts "Can't use --connect-by-ip with --host"
116
+ $stderr.puts optparse
117
+ exit 2
118
+ end
119
+
98
120
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument
99
121
 
100
122
  $stderr.puts $!.to_s
@@ -279,91 +301,106 @@ end
279
301
 
280
302
 
281
303
  ############################################################################
282
- # Iterate through MCollective hosts
304
+ # Iterate through MCollective hosts, or
283
305
 
284
- include MCollective::RPC
306
+ if options[:host]
285
307
 
286
- mc = rpcclient("rpcutil", :debug => true)
287
- begin
288
- zt_mc = rpcclient("zabbix_template", :exit_on_failure => false)
289
- rescue Exception
290
- log.warn("No zabbix_template mcollective rpc agent found")
291
- end
292
- if (!zt_mc.nil?)
293
- zt_mc.progress = false
294
- end
295
- mc.progress = false
296
- mc.discover.sort.each do |host|
308
+ hosts[ options[:host] ][ :mcollective ][:ip] = ''
309
+ if options[:template]
310
+ hosts[ options[:host] ][ :mcollective ][:classes] = [ options[:template] ]
311
+ else
312
+ hosts[ options[:host] ][ :mcollective ][:classes] = []
313
+ end
314
+
315
+ else
316
+
317
+ include MCollective::RPC
318
+
319
+ mc = rpcclient("rpcutil", :debug => true)
320
+ begin
321
+ zt_mc = rpcclient("zabbix_template", :exit_on_failure => false)
322
+ rescue Exception
323
+ log.warn("No zabbix_template mcollective rpc agent found")
324
+ end
325
+ if (!zt_mc.nil?)
326
+ zt_mc.progress = false
327
+ end
328
+ mc.progress = false
329
+ mc.discover.sort.each do |host|
297
330
 
298
- # MCollective returns FQDN name, and we probably want to use the short
299
- # form name in zabbix.
331
+ # MCollective returns FQDN name, and we probably want to use the short
332
+ # form name in zabbix.
300
333
 
301
- short_hostname = host.split('.').first
334
+ short_hostname = host.split('.').first
302
335
 
303
- log.debug("Host: #{short_hostname} (#{host})")
336
+ log.debug("Host: #{short_hostname} (#{host})")
304
337
 
305
- # Get inventory details for each host
306
- inventory = mc.custom_request( "inventory", {}, host,
307
- { "identity" => host }
308
- ).first
338
+ # Get inventory details for each host
339
+ inventory = mc.custom_request( "inventory", {}, host,
340
+ { "identity" => host }
341
+ ).first
309
342
 
310
- # Work through network interfaces reported by Facter and find the first
311
- # which matches the CIDR passed on the commandline. Use that to talk
312
- # zabbix to.
343
+ # Work through network interfaces reported by Facter and find the first
344
+ # which matches the CIDR passed on the commandline. Use that to talk
345
+ # zabbix to.
313
346
 
314
- cidr_to_match = NetAddr::CIDR.create( options[:interface_cidr] )
315
- ip = nil
347
+ cidr_to_match = NetAddr::CIDR.create( options[:interface_cidr] )
348
+ ip = nil
316
349
 
317
- inventory[:data][:facts].sort.each do |key,value|
350
+ inventory[:data][:facts].sort.each do |key,value|
318
351
 
319
- next unless key.match(/^ipaddress_/)
352
+ next unless key.match(/^ipaddress_/)
320
353
 
321
- log.debug("Potential IP interface #{key} with IP #{value}")
354
+ log.debug("Potential IP interface #{key} with IP #{value}")
322
355
 
323
- ip_cidr = NetAddr::CIDR.create( value )
324
- if ip_cidr.is_contained?( cidr_to_match)
356
+ ip_cidr = NetAddr::CIDR.create( value )
357
+ if ip_cidr.is_contained?( cidr_to_match)
325
358
 
326
- log.debug("IP matches CIDR #{options[:interface_cidr]}")
359
+ log.debug("IP matches CIDR #{options[:interface_cidr]}")
327
360
 
328
- ip = value
329
- break
361
+ ip = value
362
+ break
363
+
364
+ else
365
+ log.debug("IP doesn't match CIDR")
366
+ end
330
367
 
331
- else
332
- log.debug("IP doesn't match CIDR")
333
368
  end
334
369
 
335
- end
370
+ unless ip
371
+ raise "Host #{host} has no IP matching the target CIDR #{options[:interface_cidr]}"
372
+ end
336
373
 
337
- unless ip
338
- raise "Host #{host} has no IP matching the target CIDR #{options[:interface_cidr]}"
339
- end
374
+ log.debug("\tIP #{ip}")
340
375
 
341
- log.debug("\tIP #{ip}")
376
+ # Find whether we have to use different or any extra templates in Zabbix
377
+ # for any of the modules on this host. Only do this if we were
378
+ # successfully able to create the zabbix_template mcollective rpcclient.
379
+ if (!zt_mc.nil?)
380
+ host_template_info = zt_mc.custom_request( "templates", {},
381
+ host,
382
+ {"identity" => host}
383
+ ).first
384
+ end
342
385
 
343
- # Find whether we have to use different or any extra templates in Zabbix
344
- # for any of the modules on this host. Only do this if we were
345
- # successfully able to create the zabbix_template mcollective rpcclient.
346
- if (!zt_mc.nil?)
347
- host_template_info = zt_mc.custom_request( "templates", {},
348
- host,
349
- {"identity" => host}
350
- ).first
351
- end
386
+ if (!host_template_info.nil?)
387
+ hosts[ short_hostname ][:aliases] = host_template_info[:data][:aliases]
388
+ hosts[ short_hostname ][:extras] = host_template_info[:data][:extras]
389
+ end
352
390
 
353
- if (!host_template_info.nil?)
354
- hosts[ short_hostname ][:aliases] = host_template_info[:data][:aliases]
355
- hosts[ short_hostname ][:extras] = host_template_info[:data][:extras]
356
- end
391
+ hosts[ short_hostname ][:mcollective][:ip] = ip
392
+ hosts[ short_hostname ][:mcollective][:classes] = inventory[:data][:classes]
393
+ hosts[ short_hostname ][:mcollective][:collectives] = inventory[:data][:collectives]
394
+
395
+ collectives << hosts[ short_hostname ][:mcollective][:collectives]
357
396
 
358
- hosts[ short_hostname ][:mcollective][:ip] = ip
359
- hosts[ short_hostname ][:mcollective][:classes] = inventory[:data][:classes]
360
- hosts[ short_hostname ][:mcollective][:collectives] = inventory[:data][:collectives]
397
+ end
361
398
 
362
- collectives << hosts[ short_hostname ][:mcollective][:collectives]
399
+ mc.disconnect
363
400
 
364
401
  end
365
402
 
366
- mc.disconnect
403
+
367
404
 
368
405
  ###########################################################################
369
406
  # Fetch list of zabbix groups & Create hosts groups of discoverred
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zcollective
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
5
- prerelease:
4
+ version: 0.0.10
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jon Topper
@@ -13,15 +12,18 @@ date: 2013-12-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: netaddr
16
- requirement: &70263403228180 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.5.0
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70263403228180
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.0
25
27
  description: ZCollective is a tool used to configure Zabbix using data discovered
26
28
  using MCollective.
27
29
  email: jon@scalefactory.com
@@ -34,27 +36,25 @@ files:
34
36
  - bin/zcollective
35
37
  homepage: http://github.com/scalefactory/zcollective
36
38
  licenses: []
39
+ metadata: {}
37
40
  post_install_message:
38
41
  rdoc_options: []
39
42
  require_paths:
40
43
  - lib
41
44
  required_ruby_version: !ruby/object:Gem::Requirement
42
- none: false
43
45
  requirements:
44
- - - ! '>='
46
+ - - '>='
45
47
  - !ruby/object:Gem::Version
46
48
  version: '0'
47
49
  required_rubygems_version: !ruby/object:Gem::Requirement
48
- none: false
49
50
  requirements:
50
- - - ! '>='
51
+ - - '>='
51
52
  - !ruby/object:Gem::Version
52
53
  version: '0'
53
54
  requirements: []
54
55
  rubyforge_project:
55
- rubygems_version: 1.8.11
56
+ rubygems_version: 2.0.14
56
57
  signing_key:
57
- specification_version: 3
58
+ specification_version: 4
58
59
  summary: Zabbix/MCollective integration
59
60
  test_files: []
60
- has_rdoc: