spigit_ops 0.0.2.beta

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTQyOGFmNDU2MmYwYjcwZDg0YzY4MmNmYzZlYjQyYTU5ZThkM2EwMA==
5
+ data.tar.gz: !binary |-
6
+ YTExYjJlZGMxNGE2N2Y1NzQ1OWNiZTY4ZmZmOWU5ODRjYzkxMWJmYQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MDM5MzllY2RlODZjMDcwZmRiMjNjMDRlZGMyYjczNDAyMTUxZDFlZDY1NDhh
10
+ MGI5NWY1ZGQ5NTMyMzFjOGI0MTgxY2VlZjM4MDlmOTk0Y2IyYWRhODg2ZTQ0
11
+ ZTJkNWZhYWI0ZmNiMjVlZWE5NTk2NjdiZGVlZjEzZmQ1OWUxNzM=
12
+ data.tar.gz: !binary |-
13
+ ZTY2OTI1MGNiYWM1MDRjYzc4OTcyYzdhZTExM2FjY2VlNjZlZGJkZGU0OWYy
14
+ NzdmMjM4ZTgzY2U4YTE5MzYxMGM2Y2Q3MDU2Y2NlMTI4NTJlODhhYmQ0ZjE1
15
+ YzFhYmExMGRjZDczNTdjYTRiNzZlY2I5MWNlMjlkMTcyN2ZiMmY=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/EXAMPLES ADDED
@@ -0,0 +1,17 @@
1
+ require 'spigit_ops/spigit_conf'
2
+
3
+ spigit_conf = SpigitOps::SpigitConf.new('/opt/webapps/mywa/spigit-conf.xml')
4
+
5
+ spigit_conf.update_av_settings
6
+
7
+ spigit_conf.save!
8
+
9
+ spigit_conf.av_ext?
10
+
11
+ spigit_conf.av_add_ext ".txt"
12
+
13
+
14
+
15
+ citi = SpigitOps.new("citibank")
16
+
17
+ citi.create_snapshot
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spigit_ops.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # SpigitOps
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'spigit_ops'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install spigit_ops
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ module SpigitOps
2
+ class SpigitConf
3
+ def self.test
4
+ puts "testing..."
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,149 @@
1
+ require 'nokogiri'
2
+
3
+ module SpigitOps
4
+ class Tomcat
5
+ def initialize(serverxml_filename = SpigitOps::TC_SERVER_XML, options= {})
6
+ @serverxml_filename = serverxml_filename
7
+
8
+ if ! FileTest.exist? @serverxml_filename
9
+ raise "#{@serverxml_filename} doesn't exist."
10
+ elsif ! FileTest.readable? @serverxml_filename
11
+ raise "#{@serverxml_filename} isn't readable."
12
+ end
13
+
14
+ @serverxml_xml = Nokogiri::XML(File.open(@serverxml_filename))
15
+ build_tomcat_services
16
+ end
17
+
18
+ def services
19
+ puts @tomcat_services
20
+ end
21
+
22
+ def count
23
+ puts @tomcat_services.length
24
+ end
25
+
26
+ def exist?(service)
27
+
28
+ end
29
+
30
+ def grab_service(name)
31
+ puts @tomcat_services[name]
32
+ end
33
+
34
+ def serverxml_filename
35
+ puts @serverxml_filename
36
+ end
37
+
38
+ def save!(output_filename = SpigitOps::TC_SERVICES_FILE, options = {})
39
+ format = options[:format]
40
+
41
+ if format == 'old'
42
+ File.open(output_filename, 'w') { |f| @old_tomcat_services.each { |x| f.puts x } }
43
+ else
44
+ File.open(output_filename, 'w') { |f| @tomcat_services.each { |key, value| f.puts value } }
45
+ end
46
+ end
47
+
48
+ def save_old!(output_filename = SpigitOps::TC_SERVICES_FILE)
49
+ self.save!(output_filename, format: 'old')
50
+ end
51
+
52
+ private
53
+
54
+ ## Create a table so we can lookup the line number for the </Service> for the particular service we want
55
+ def build_service_end_line_lookup
56
+ lines = File.open(@serverxml_filename).readlines.collect { |x| x.strip }
57
+ lines.unshift('placing item in array so the index reflects the actual line number')
58
+
59
+ services_start = (0 .. lines.count - 1).find_all { |x| lines[x,1].to_s.match(/<Service/) }
60
+ services_end = (0 .. lines.count - 1).find_all { |x| lines[x,1].to_s.match(/<\/Service/) }
61
+ service_line_numbers = services_start.zip(services_end)
62
+
63
+ @service_end_line_lookup = service_line_numbers.inject({}) do |result, element|
64
+ key = element.first
65
+ value = element.last
66
+ result[key] = value
67
+ result
68
+ end
69
+ end
70
+
71
+ def build_tomcat_services
72
+ build_service_end_line_lookup
73
+ @tomcat_services = {}
74
+ @old_tomcat_services = []
75
+
76
+ ## Loop to grab all information from the server.xml
77
+ @serverxml_xml.xpath('//Service').each do |service|
78
+ name = service[:name]
79
+ start_line = service.line
80
+ end_line = @service_end_line_lookup[start_line]
81
+
82
+ # Create an array with all connectors and the needed attributes in a hash
83
+ connectors = []
84
+ service.children.css('Connector').each do |connector|
85
+ connectors << {:ip => connector[:address], :port => connector[:port]}
86
+ end
87
+
88
+ # Create an array with all docBases
89
+ docBase = []
90
+ service.children.css('Context').each do |context|
91
+ docBase << context[:docBase]
92
+ end
93
+
94
+ resources = []
95
+ service.children.css('Resource').each do |resource|
96
+ db_host = resource[:url].scan(%r{mysql://(.*)/}).join.sub(/^127\.0\.0\.1$/, "localhost")
97
+ schema_name = resource[:url].scan(%r{/([^/]+)\?}).join
98
+
99
+ if resources.empty?
100
+ resources << {:db_host => db_host, :schema_name => schema_name}
101
+ resources << {:db_host => db_host, :schema_name => "#{schema_name}user"}
102
+ else
103
+ ## This checks to see if the result
104
+ duplicate=""
105
+ resources.each do |i|
106
+ if i[:db_host] == db_host and i[:schema_name] == schema_name
107
+ duplicate=true
108
+ end
109
+ end
110
+ if duplicate != true
111
+ resources << {:db_host => db_host, :schema_name => schema_name}
112
+ end
113
+ end
114
+ end
115
+
116
+ ## This finishes things up and creates a hash for all tomcat services
117
+ serviceDefintion = {:start_line => start_line, :end_line => end_line, :name => name, :connectors => connectors.uniq, :docBases => docBase.uniq, :resources => resources}
118
+ @tomcat_services[name] = serviceDefintion
119
+
120
+ ## This is all for the OLD/ORIGINAL output ##
121
+ # Create schemas array for all schema names, then add NAMEuser schema.
122
+ old_schemas = resources.inject([]) do |result, resource|
123
+ result << resource[:schema_name]
124
+ result
125
+ end
126
+
127
+ # Create dbhost variable and check some stuff out
128
+ old_db_hosts = resources.inject([]) do |result, resource|
129
+ result << resource[:db_host]
130
+ result
131
+ end.uniq
132
+ if old_db_hosts.count > 1
133
+ puts "WARNING: We found miltiple hosts for the schema's, exiting..."
134
+ exit 1
135
+ end
136
+
137
+ # Create ips array for all ip addresses
138
+ old_ips = connectors.inject([]) do |result, connector|
139
+ result << connector[:ip]
140
+ result
141
+ end
142
+ old_serviceDefintion = "#{start_line},#{end_line}:#{old_ips.uniq.join(',')}:#{docBase.uniq.join(',')}:#{old_db_hosts.join(',')}:#{old_schemas.join(',')}:#{name}"
143
+ @old_tomcat_services << old_serviceDefintion
144
+ ## This is all for the OLD/ORIGINAL output ##
145
+ end
146
+ @tomcat_services
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,3 @@
1
+ module SpigitOps
2
+ VERSION = "0.0.2.beta"
3
+ end
data/lib/spigit_ops.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "spigit_ops/version"
2
+ require "spigit_ops/tomcat"
3
+ require "spigit_ops/spigit_conf"
4
+
5
+ module SpigitOps
6
+ TCS_START = 0
7
+ TCS_END = 1
8
+
9
+ TC_SERVER_XML = '/opt/tomcat/conf/server.xml'
10
+ TC_SERVICES_FILE = '/spigit/data_warehouse/tomcat/services.txt'
11
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spigit_ops/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spigit_ops"
8
+ spec.version = SpigitOps::VERSION
9
+ spec.authors = ["Jason Barnett", "Bob Santos"]
10
+ spec.email = ["J@sonBarnett.com", "bob.santos@spigit.com"]
11
+ spec.description = %q{This gem does this and that.}
12
+ spec.summary = %q{Want to manage Spigit? Grab this gem.}
13
+ spec.homepage = "http://www.spigit.com/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'nokogiri', '>= 1.5.9'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end