lib/cfnguardian.rb in cfn-guardian-0.7.16 vs lib/cfnguardian.rb in cfn-guardian-0.8.0
- old
+ new
@@ -9,10 +9,11 @@
require "cfnguardian/cloudwatch"
require "cfnguardian/display_formatter"
require "cfnguardian/drift"
require "cfnguardian/codecommit"
require "cfnguardian/codepipeline"
+require "cfnguardian/tagger"
module CfnGuardian
class Cli < Thor
include Logging
@@ -83,10 +84,13 @@
method_option :sns_critical, type: :string, desc: "sns topic arn for the critical alarms"
method_option :sns_warning, type: :string, desc: "sns topic arn for the warning alarms"
method_option :sns_task, type: :string, desc: "sns topic arn for the task alarms"
method_option :sns_informational, type: :string, desc: "sns topic arn for the informational alarms"
method_option :sns_events, type: :string, desc: "sns topic arn for the informational alarms"
+ method_option :tags, type: :hash, desc: "additional tags on the cloudformation stack"
+ method_option :tag_yaml, type: :string, desc: "additional tags on the cloudformation stack in a yaml file"
+ method_option :role_arn, type: :string, desc: "IAM role arn that CloudFormation assumes when executing the change set"
def deploy
set_log_level(options[:debug])
set_region(options[:region],true)
@@ -112,17 +116,40 @@
change_set, change_set_type = deployer.create_change_set()
deployer.wait_for_changeset(change_set.id)
deployer.execute_change_set(change_set.id)
deployer.wait_for_execute(change_set_type)
end
-
+
+ desc "tag-alarms", "apply tags to the cloudwatch alarms deployed"
+ long_desc <<-LONG
+ Because Cloudformation desn't support tagging cloudwatch alarms this command
+ applies tags to each cloudwatch alarm created by guardian.
+ Guardian defines default tags and this can be added to through the alarms.yaml config.
+ LONG
+ method_option :config, aliases: :c, type: :string, desc: "yaml config file", required: true
+ method_option :region, aliases: :r, type: :string, desc: "set the AWS region"
+
+ def tag_alarms
+ set_log_level(options[:debug])
+ set_region(options[:region],true)
+
+ compiler = CfnGuardian::Compile.new(options[:config])
+ compiler.get_resources
+ alarms = compiler.alarms
+
+ tagger = CfnGuardian::Tagger.new()
+ alarms.each do |alarm|
+ tagger.tag_alarm(alarm, compiler.global_tags)
+ end
+ end
+
desc "show-drift", "Cloudformation drift detection"
long_desc <<-LONG
Displays any cloudformation drift detection in the cloudwatch alarms from the deployed stacks
LONG
method_option :stack_name, aliases: :s, type: :string, default: 'guardian', desc: "set the Cloudformation stack name"
method_option :region, aliases: :r, type: :string, desc: "set the AWS region"
-
+
def show_drift
set_region(options[:region],true)
rows = []
drift = CfnGuardian::Drift.new(options[:stack_name])