sr-scripts 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
5
+ require 'fog'
6
+ require 'sr-scripts'
7
+ require 'optparse'
8
+
9
+ options = {}
10
+
11
+ optparse = OptionParser.new do|opts|
12
+ opts.on( '-f FROM', 'From Email Address') do |o|
13
+ options[:from] = o
14
+ end
15
+ opts.on( '-t TO', 'To Email Address') do |o|
16
+ options[:to] = o
17
+ end
18
+ opts.on( '-h', '--help', 'Display this screen' ) do
19
+ puts opts
20
+ exit
21
+ end
22
+ end
23
+
24
+ optparse.parse!
25
+
26
+ connection = SrScripts::Compute.get
27
+
28
+ current_instance_id = `curl -s http://169.254.169.254/latest/meta-data/instance-id`
29
+
30
+ server = connection.servers.get(current_instance_id)
31
+
32
+ exit unless server.tags["master_status"] == "slave"
33
+
34
+ seconds_behind = `mysql -e "SHOW SLAVE STATUS\\G" | grep Seconds_Behind_Master | awk '{print $2;}'`.chomp
35
+ if seconds_behind == "NULL" || seconds_behind.to_i > 60
36
+ if options[:from] != nil && options[:to] != nil
37
+ `echo "Replication Error\nSeconds Behind Master: #{seconds_behind}" | sr-send-email -t #{options[:to]} -f #{options[:from]} -s "Replication Error On #{current_instance_id}"`
38
+ else
39
+ p "Replication Error On #{current_instance_id}"
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  module Sr
2
2
  module Scripts
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sr-scripts
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Davy Campano
@@ -24,6 +24,7 @@ email:
24
24
  - dcampano@gmail.com
25
25
  executables:
26
26
  - sr-backup-mysql
27
+ - sr-check-slave
27
28
  - sr-ec2-consistent-snapshot
28
29
  - sr-promote-to-master
29
30
  - sr-send-email
@@ -39,6 +40,7 @@ files:
39
40
  - Gemfile
40
41
  - Rakefile
41
42
  - bin/sr-backup-mysql
43
+ - bin/sr-check-slave
42
44
  - bin/sr-ec2-consistent-snapshot
43
45
  - bin/sr-promote-to-master
44
46
  - bin/sr-send-email