microbosh_hacker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bec2df0cc57545226dd5545ff30d35ab1c55aaa
4
+ data.tar.gz: e7967313316408c7cced30ad4e8195eb9f5243e9
5
+ SHA512:
6
+ metadata.gz: b5ad6f732d3f91843a8e935334c28a570422eff2554aa4028f6449c3955ef6e90bf7d6681c226c6920a01cabd9d17908f9645484a97640bf01cf41be14fef620
7
+ data.tar.gz: 817a7694f46477e1a8bb29dda9faa265e9f226c63332e66986ca3edf352baef4e7cc8c1e060d3cb597b2bc3d6f6395c7137868fd59891521e58f0a615cd44e14
@@ -0,0 +1,27 @@
1
+ #!/bin/env ruby
2
+
3
+ require 'colorize'
4
+
5
+ emailer_config = ARGV[1]
6
+
7
+
8
+ now= Time.now.to_i
9
+
10
+ puts 'Brings current health monitor conf file from microbosh server'.green
11
+ `sshpass -p #{ENV['VCAP_PASS']} scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null vcap@#{ENV['MICROBOSH_IP']}:/var/vcap/jobs/health_monitor/config/health_monitor.yml /tmp/health_monitor.yml`
12
+
13
+ puts 'Modifies health monitor config file locally'.green
14
+ `#{File.dirname(__FILE__)}/microbosh_hacker health_monitor_config /tmp/health_monitor.yml $emailer_config > /tmp/new_health_monitor.yml`
15
+
16
+ puts 'Move modified health monitor config to microbosh server'.green
17
+ `sshpass -p #{ENV['VCAP_PASS']} scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null /tmp/new_health_monitor.yml vcap@#{ENV['MICROBOSH_IP']}:/tmp/new_health_monitor.yml`
18
+
19
+ puts 'Makes a backup of the health monitor config on the targeted microbosh server'.green
20
+ `sshpass -p #{ENV['VCAP_PASS']} ssh -t -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null vcap@#{ENV['MICROBOSH_IP']} "echo #{ENV['VCAP_PASS']} | sudo -S cp /var/vcap/jobs/health_monitor/config/health_monitor.yml /var/vcap/jobs/health_monitor/config/health_monitor.$now.yml"`
21
+
22
+ puts 'Replace orginal config with new config (/tmp/new_health_monitor -> /var/vcap/jobs/health_monitor/config/health_monitor.yml)'.green
23
+ `sshpass -p #{ENV['VCAP_PASS']} ssh -t -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null vcap@#{ENV['MICROBOSH_IP']} "echo #{ENV['VCAP_PASS']} | sudo -S mv /tmp/new_health_monitor.yml /var/vcap/jobs/health_monitor/config/health_monitor.yml"`
24
+
25
+ puts 'Perform monit restart for health_monitor job'.green
26
+ `sshpass -p #{ENV['VCAP_PASS']} ssh -t -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null vcap@#{ENV['MICROBOSH_IP']} "echo #{ENV['VCAP_PASS']} | sudo -S su -c '/var/vcap/bosh/bin/monit restart health_monitor'"`
27
+
@@ -0,0 +1,21 @@
1
+ #!/bin/env ruby
2
+
3
+ require_relative '../lib/microbosh_hacker'
4
+
5
+
6
+ action, config_path, microbosh_config_path= *ARGV
7
+ usage = 'Usage: ./microbosh_hacker action[hmce|health_monitor_config_edit] config_path microbosh_config_path'
8
+
9
+ if config_path.nil?
10
+ puts usage
11
+ exit 1
12
+ end
13
+
14
+ puts case action
15
+ when 'hmce'
16
+ opts = YAML.load(File.read(microbosh_config_path))
17
+ MicroboshHacker::HealthMonitorConfig.new(config_path, opts).to_yaml
18
+ else
19
+ usage
20
+ end
21
+
@@ -0,0 +1,4 @@
1
+ class MicroboshHacker
2
+ end
3
+
4
+ require_relative 'microbosh_hacker/health_monitor_config'
@@ -0,0 +1,44 @@
1
+ require 'yaml'
2
+
3
+ class MicroboshHacker::HealthMonitorConfig
4
+ attr_reader :config_path, :opts
5
+
6
+ REQUIRED_OPTS= %i{ email_recipients from host port domain}
7
+ OPTIONAL_OPTS= %i{ auth user password interval}
8
+ AVAILABLE_OPTS= REQUIRED_OPTS+ OPTIONAL_OPTS
9
+
10
+ def initialize(config_path, opts = {})
11
+ @config_path=config_path
12
+ @opts=opts
13
+
14
+ raise "Missing options: #{(REQUIRED_OPTS - @opts.keys).join(', ')}" unless (REQUIRED_OPTS - @opts.keys).empty?
15
+ opts.each_pair do |k, v|
16
+ raise "Nil or empty option: #{k}" if v.nil? || v.to_s.empty?
17
+ end
18
+ end
19
+
20
+ def to_yaml
21
+ config = ::YAML.load_file(config_path)
22
+ config['plugins'].unshift(
23
+ {
24
+ 'name' => 'email',
25
+ 'events' => [ 'alert' ],
26
+ 'options' => {
27
+ 'recipients' => opts[:email_recipients],
28
+ 'smtp' => {
29
+ 'from' => opts[:from],
30
+ 'host' => opts[:host],
31
+ 'port' => opts[:port],
32
+ 'domain' => opts[:domain]
33
+ }
34
+ }
35
+ }
36
+ )
37
+
38
+ # auth: 'plain
39
+ # user: user
40
+ # password: pass123
41
+ # interval:1
42
+ config.to_yaml
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ class MicroboshHacker
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: microbosh_hacker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - cloud-dude
8
+ - bonzofenix
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colorize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.3'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: " PCF likes to hide some features. This peice of software lets you to
71
+ enable email notification after mb gets deployed."
72
+ email:
73
+ - lukasz.rabczak@gmail.com
74
+ - bonzofenix@gmail.com
75
+ executables:
76
+ - enable_email_plugin
77
+ - microbosh_hacker
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - bin/enable_email_plugin
82
+ - bin/microbosh_hacker
83
+ - lib/microbosh_hacker.rb
84
+ - lib/microbosh_hacker/health_monitor_config.rb
85
+ - lib/microbosh_hacker/version.rb
86
+ homepage: https://github.com/compozed/microbosh_hacker
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Microbosh yaml hacker
110
+ test_files: []