Sha256: 0dc9d1edda908dc14c657358bf74270bb96f0223537d0ba54a98c8815684653c
Contents?: true
Size: 1.82 KB
Versions: 35
Compression:
Stored size: 1.82 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 StandardError => e puts "Error: exception: #{e}" critical end end
Version data entries
35 entries across 35 versions & 1 rubygems