awsbix 0.0.4 → 0.0.5

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/add-hosts.rb +2 -2
  3. data/lib/awsbix/aws.rb +23 -24
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a74ea58d610368049295db037254bdeaaf795544
4
- data.tar.gz: ecdd1b968c72526d2f040545caa4742d718b15ab
3
+ metadata.gz: d9c4cefcb09641182dee5a1809a1ccaca10fa503
4
+ data.tar.gz: 81b1cc338d11654ade97d1eeee44e7af81fdae72
5
5
  SHA512:
6
- metadata.gz: 6d03dfdf4130326b449f09476564819412a83bb0eaedcfe63f80cce3e8e1a08644ebcbf270677933bf5bfded196a2d0831143ead11a84ddb558b39d3fbbe73f3
7
- data.tar.gz: 6b7a829fcb46e66350af71751ee4aa991ef4295ad9c00b151d229ab6e29a8242ce7e8e0aa68fc17ac7fd80afa2d762f2b3c1951bd08b2e8d743605d553704115
6
+ metadata.gz: 537c549bc213fecddb175302d9f57fe873425557cd15c1657dca0714aa11127c2d345feecd402dd33ced9cab30339e8ecefd9089e55cb4962076ff43c1aabca0
7
+ data.tar.gz: 58003d3c27d0a08bc7408969f6b12055948bdfacbd9cc5f2b687db7d993cb60134356d2f01d06bc38324576207014883947d37eef1a73553538fbea74857f9f2
@@ -34,8 +34,8 @@ awsbix = Awsbix.new(config)
34
34
  # connect to host defined in config.yaml
35
35
  awsbix.zbx_connect()
36
36
 
37
- # process hosts
38
- awsbix.aws_get_hosts().each do |host|
37
+ # process hosts, if no :regex or :filter mode is provided defaults to include all hosts in AWS account
38
+ awsbix.aws_get_hosts(:regex => %r{security_group_to_match},:filter => 'include').each do |host|
39
39
  host.security_groups.each do | sg |
40
40
  awsbix.zbx_process_host(
41
41
  :hostname => host.tags['Name'],
@@ -44,17 +44,14 @@ class Awsbix
44
44
  end
45
45
 
46
46
  # retrieve non-excluded and running EC2 hosts
47
- def aws_get_hosts()
47
+ # {:filter => 'exclude|include', :regex => %r{}}
48
+ def aws_get_hosts(options = {})
49
+ # if no filter mode is provided default to 'include'
50
+ options[:filter] ||= 'include'
51
+ # if no regex is provided default to '.*'
52
+ options[:regex] ||= %r{.*}
48
53
  @ec2_hosts = Array.new
49
54
 
50
- # get sg to ignore or process based on zbx_filter_model
51
- case self.get_conf('zbx_filter_model')
52
- when 'exclude'
53
- excluded_security_groups = self.get_conf('zbx_exclude_security_group')
54
- when 'include'
55
- included_security_groups = self.get_conf('zbx_include_security_group')
56
- end
57
-
58
55
  self.ec2_connect()
59
56
  # loop through all hosts, across all regions in config
60
57
  self.aws_get_regions().each do |region|
@@ -63,23 +60,25 @@ class Awsbix
63
60
  @ec2.regions[region].instances.each do | inst |
64
61
  if inst.status.match(/running/) then
65
62
  inst.security_groups.each do | sg |
66
- case self.get_conf('zbx_filter_model')
67
- when 'exclude'
68
- # do not process if sg is excluded
69
- unless excluded_security_groups.include?(sg.name) then
70
- # do not push if already present
71
- unless @ec2_hosts.include?(inst) then
72
- @ec2_hosts.push(inst)
63
+ if options[:regex].is_a?(Regexp) then
64
+ case options[:filter]
65
+ when 'exclude'
66
+ # do not process if sg is excluded
67
+ unless sg.name.match(options[:regex]) then
68
+ # do not push if already present
69
+ unless @ec2_hosts.include?(inst) then
70
+ @ec2_hosts.push(inst)
71
+ end
73
72
  end
74
- end
75
- when 'include'
76
- # process if sg is included
77
- if included_security_groups.include?(sg.name) then
78
- # do not push if already present
79
- unless @ec2_hosts.include?(inst) then
80
- @ec2_hosts.push(inst)
73
+ when 'include'
74
+ # process if sg is included
75
+ if sg.name.match(options[:regex]) then
76
+ # do not push if already present
77
+ unless @ec2_hosts.include?(inst) then
78
+ @ec2_hosts.push(inst)
79
+ end
81
80
  end
82
- end
81
+ end
83
82
  end
84
83
  end
85
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsbix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Llewellyn-Smith