deckard 0.5.5 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -49,6 +49,7 @@ Failover check document format:
49
49
  "url": "http://somecheck.com/check.html",
50
50
  "secondary_instance_id": "i-1234",
51
51
  "priority": 2,
52
+ "region": "us-east-1",
52
53
  "elastic_ip": "127.0.0.1",
53
54
  "content": "sometext",
54
55
  "failover": true,
data/lib/deckard.rb CHANGED
@@ -6,7 +6,7 @@ require 'tmail'
6
6
  require 'json'
7
7
  require 'cgi'
8
8
  require 'net/smtp'
9
- require 'right_aws'
9
+ require 'fog'
10
10
  require 'mixlib/log'
11
11
  require 'mixlib/config'
12
12
  require 'yaml'
@@ -75,7 +75,7 @@ class Deckard
75
75
  run = Thread.new {
76
76
  check = Deckard::Monitor.content_check(node["url"], node["content"], node["priority"], retry_count, node["schedule"])
77
77
  unless check
78
- Deckard::Monitor.failover(node["elastic_ip"], node["primary_instance_id"], node["secondary_instance_id"], node["priority"], node["schedule"], node["failover"])
78
+ Deckard::Monitor.failover(node["elastic_ip"], node["primary_instance_id"], node["secondary_instance_id"], node["priority"], node["schedule"], node["failover"], node["region"])
79
79
  Deckard::Util.flip_failover(node)
80
80
  end
81
81
  }
@@ -99,4 +99,4 @@ class Deckard
99
99
  }
100
100
  end
101
101
 
102
- end
102
+ end
data/lib/deckard/ec2.rb CHANGED
@@ -1,19 +1,30 @@
1
1
  class Deckard
2
2
  class Ec2
3
- aws_key = Deckard::Config.aws_key
4
- aws_secret = Deckard::Config.aws_secret
5
- Ec2 = RightAws::Ec2.new(aws_key, aws_secret)
6
-
7
- def self.get_association(elastic_ip)
8
- Ec2.describe_addresses(elastic_ip)[0][:instance_id]
3
+
4
+ def self.get_association(region, elastic_ip)
5
+ ec2 = ec2init(region)
6
+ ec2.describe_addresses(elastic_ip).body["addressesSet"][0]["instanceId"]
9
7
  end
10
8
 
11
- def self.associate_address(instance_id, elastic_ip)
12
- Ec2.associate_address(instance_id, elastic_ip)
9
+ def self.associate_address(region, instance_id, elastic_ip)
10
+ ec2 = ec2init(region)
11
+ ec2.associate_address(instance_id, elastic_ip).body["return"]
13
12
  end
14
13
 
15
- def self.disassociate_address(elastic_ip)
16
- Ec2.disassociate_address(elastic_ip)
14
+ def self.disassociate_address(region, elastic_ip)
15
+ ec2 = ec2init(region)
16
+ ec2.disassociate_address(elastic_ip).body["return"]
17
17
  end
18
+
19
+ def self.ec2init(region)
20
+ aws_key = Deckard::Config.aws_key
21
+ aws_secret = Deckard::Config.aws_secret
22
+
23
+ Fog::AWS::EC2.new(
24
+ :aws_access_key_id => aws_key,
25
+ :aws_secret_access_key => aws_secret,
26
+ :region => region)
27
+ end
28
+
18
29
  end
19
30
  end
@@ -57,7 +57,7 @@ class Deckard
57
57
  end
58
58
  end
59
59
 
60
- def self.failover(elastic_ip, primary_instance_id, secondary_instance_id, priority, schedule, failover)
60
+ def self.failover(elastic_ip, primary_instance_id, secondary_instance_id, priority, schedule, failover, region)
61
61
  if failover
62
62
  begin
63
63
  subject = "ALERT :: #{elastic_ip} attempting failover!"
@@ -65,24 +65,41 @@ class Deckard
65
65
  log = subject + " " + body
66
66
  Deckard::Util.alert(priority, subject, body, log, schedule, "http://#{elastic_ip}")
67
67
 
68
- instance_id = Deckard::Ec2.get_association(elastic_ip)
69
- Deckard::Ec2.disassociate_address(elastic_ip)
70
- Deckard::Log.info("ALERT :: Disassociated #{elastic_ip}")
68
+ instance_id = Deckard::Ec2.get_association(region, elastic_ip)
69
+
70
+ if Deckard::Ec2.disassociate_address(region, elastic_ip) == "true"
71
+ Deckard::Log.info("ALERT :: Disassociated #{elastic_ip}")
72
+ else
73
+ Deckard::Log.info("ALERT :: Could not disassociate #{elastic_ip}")
74
+ Deckard::Util.alert(priority, "ALERT :: Could not disassociate #{elastic_ip}", "ALERT :: Could not disassociate #{elastic_ip}", log, schedule, "http://#{elastic_ip}")
75
+ end
71
76
 
72
77
  if instance_id == primary_instance_id
73
- Deckard::Ec2.associate_address(secondary_instance_id, elastic_ip)
78
+ if Deckard::Ec2.associate_address(region, secondary_instance_id, elastic_ip) == "true"
79
+ info = "ALERT :: associated #{elastic_ip} to #{secondary_instance_id}"
80
+ Deckard::Log.info("ALERT :: associated #{elastic_ip} to #{secondary_instance_id}")
81
+ subject = "ALERT :: Failover Complete for #{elastic_ip} #{secondary_instance_id}"
82
+ body = "VERIFY THINGS ARE WORKING! #{elastic_ip} => #{primary_instance_id} / #{secondary_instance_id}"
83
+ Deckard::Util.alert(priority, subject, body, subject, schedule, "http://#{elastic_ip}")
84
+ else
85
+ info = "ALERT :: Could not associate #{elastic_ip}"
86
+ Deckard::Log.info(info)
87
+ Deckard::Util.alert(priority, info, info, log, schedule, "http://#{elastic_ip}")
88
+ end
74
89
 
75
- Deckard::Log.info("ALERT :: associated #{elastic_ip} to #{secondary_instance_id}")
76
- subject = "ALERT :: Failover Complete for #{elastic_ip} #{secondary_instance_id}"
77
- body = "VERIFY THINGS ARE WORKING! #{elastic_ip} => #{primary_instance_id} / #{secondary_instance_id}"
78
- Deckard::Util.alert(priority, subject, body, subject, schedule, "http://#{elastic_ip}")
79
90
  elsif instance_id == secondary_instance_id
80
- Deckard::Ec2.associate_address(primary_instance_id, elastic_ip)
91
+ if Deckard::Ec2.associate_address(region, primary_instance_id, elastic_ip) == "true"
92
+ info = "ALERT :: associated #{elastic_ip} to #{secondary_instance_id}"
93
+ Deckard::Log.info("ALERT :: associated #{elastic_ip} to #{secondary_instance_id}")
94
+ subject = "ALERT :: Failover Complete for #{elastic_ip} #{secondary_instance_id}"
95
+ body = "VERIFY THINGS ARE WORKING! #{elastic_ip} => #{primary_instance_id} / #{secondary_instance_id}"
96
+ Deckard::Util.alert(priority, subject, body, subject, schedule, "http://#{elastic_ip}")
97
+ else
98
+ info = "ALERT :: Could not associate #{elastic_ip}"
99
+ Deckard::Log.info(info)
100
+ Deckard::Util.alert(priority, info, info, log, schedule, "http://#{elastic_ip}")
101
+ end
81
102
 
82
- Deckard::Log.info("ALERT :: associated #{elastic_ip} to #{primary_instance_id}")
83
- subject = "ALERT :: Failover Complete for #{elastic_ip} #{primary_instance_id}"
84
- body = "VERIFY THINGS ARE WORKING! #{elastic_ip} => #{primary_instance_id} / #{secondary_instance_id}"
85
- Deckard::Util.alert(priority, subject, body, subject, schedule, "http://#{elastic_ip}")
86
103
  else
87
104
  error = "ALERT :: Could not a failover #{elastic_ip} => #{primary_instance_id} / #{secondary_instance_id}!!"
88
105
  log = "ALERT :: Could not a failover #{elastic_ip} => #{primary_instance_id} / #{secondary_instance_id}!! Due to instance_id != primary and secondary"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 5
9
- version: 0.5.5
8
+ - 7
9
+ version: 0.5.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - joe williams
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-25 00:00:00 -07:00
17
+ date: 2010-09-05 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -66,7 +66,7 @@ dependencies:
66
66
  type: :runtime
67
67
  version_requirements: *id004
68
68
  - !ruby/object:Gem::Dependency
69
- name: right_aws
69
+ name: fog
70
70
  prerelease: false
71
71
  requirement: &id005 !ruby/object:Gem::Requirement
72
72
  requirements: