Sha256: 33196f8769c3af0c043b8bcbec06cf266931de919f36c9b76f5678184e1b511e
Contents?: true
Size: 1.81 KB
Versions: 17
Compression:
Stored size: 1.81 KB
Contents
#! /usr/bin/env ruby # # check-cloudwatch-alarms # # DESCRIPTION: # This plugin raise a critical if one of cloud watch alarms are in given state. # # OUTPUT: # plain-text # # PLATFORMS: # Linux # # DEPENDENCIES: # gem: aws-sdk # gem: sensu-plugin # # USAGE: # ./check-cloudwatch-alarms --exclude-alarms "CPUAlarmLow" # ./check-cloudwatch-alarms --region eu-west-1 --exclude-alarms "CPUAlarmLow" # # NOTES: # # LICENSE: # Copyright (c) 2017, Olivier Bazoud, olivier.bazoud@gmail.com # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. # require 'sensu-plugin/check/cli' require 'sensu-plugins-aws/common' require 'aws-sdk' class CloudWatchCheck < Sensu::Plugin::Check::CLI include Common option :aws_region, short: '-r AWS_REGION', long: '--aws-region REGION', description: 'AWS Region (defaults to us-east-1).', default: 'us-east-1' option :state, description: 'State of the alarm', short: '-s STATE', long: '--state STATE', default: 'ALARM' option :exclude_alarms, description: 'Exclude alarms', short: '-e EXCLUDE_ALARMS', long: '--exclude-alarms', proc: proc { |a| a.split(',') }, default: [] def run client = Aws::CloudWatch::Client.new options = { state_value: config[:state] } alarms = client.describe_alarms(options).metric_alarms if alarms.empty? ok "No alarms in '#{config[:state]}' state" end config[:exclude_alarms].each do |x| alarms.delete_if { |alarm| alarm.alarm_name.match(x) } end critical "#{alarms.size} in '#{config[:state]}' state: #{alarms.map(&:alarm_name).join(',')}" unless alarms.empty? ok 'everything looks good' rescue => e puts "Error: exception: #{e}" critical end end
Version data entries
17 entries across 17 versions & 1 rubygems