-
-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from astral303/enable_monitoring
Add ability to enable detailed CloudWatch monitoring for current instance
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
include Opscode::Aws::Ec2 | ||
|
||
def whyrun_supported? | ||
true | ||
end | ||
|
||
action :enable do | ||
if is_monitoring_enabled | ||
Chef::Log.debug("Monitoring is already enabled for this instance") | ||
else | ||
converge_by("enable monitoring for this instance") do | ||
Chef::Log.info("Enabling monitoring for this instance") | ||
ec2.monitor_instances(instance_id) | ||
end | ||
end | ||
end | ||
|
||
action :disable do | ||
if is_monitoring_enabled | ||
converge_by("disable monitoring for this instance") do | ||
Chef::Log.info("Disabling monitoring for this instance") | ||
ec2.unmonitor_instances(instance_id) | ||
end | ||
else | ||
Chef::Log.debug("Monitoring is already disabled for this instance") | ||
end | ||
end | ||
|
||
private | ||
|
||
def is_monitoring_enabled() | ||
monitoring_state = ec2.describe_instances(instance_id)[0][:monitoring_state] | ||
Chef::Log.info("Current monitoring state for this instance is #{monitoring_state}") | ||
return monitoring_state == "enabled" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def initialize(*args) | ||
super | ||
@action = :enable | ||
end | ||
|
||
actions :enable, :disable | ||
|
||
state_attrs :aws_access_key | ||
|
||
attribute :aws_access_key, :kind_of => String | ||
attribute :aws_secret_access_key, :kind_of => String |