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.
- checksums.yaml +4 -4
- data/bin/add-hosts.rb +2 -2
- data/lib/awsbix/aws.rb +23 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9c4cefcb09641182dee5a1809a1ccaca10fa503
|
4
|
+
data.tar.gz: 81b1cc338d11654ade97d1eeee44e7af81fdae72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 537c549bc213fecddb175302d9f57fe873425557cd15c1657dca0714aa11127c2d345feecd402dd33ced9cab30339e8ecefd9089e55cb4962076ff43c1aabca0
|
7
|
+
data.tar.gz: 58003d3c27d0a08bc7408969f6b12055948bdfacbd9cc5f2b687db7d993cb60134356d2f01d06bc38324576207014883947d37eef1a73553538fbea74857f9f2
|
data/bin/add-hosts.rb
CHANGED
@@ -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'],
|
data/lib/awsbix/aws.rb
CHANGED
@@ -44,17 +44,14 @@ class Awsbix
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# retrieve non-excluded and running EC2 hosts
|
47
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@ec2_hosts.
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
81
|
+
end
|
83
82
|
end
|
84
83
|
end
|
85
84
|
end
|