Skip to content

Cookstyle Bot Auto Corrections with Cookstyle 7.13.0 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions files/default/handlers/campfire
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Sensu Handler: campfire
#
# Copyright 2012, AJ Christensen <[email protected]>
# Copyright:: 2012, AJ Christensen <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,23 +17,22 @@
# limitations under the License.
#

require "rubygems" if RUBY_VERSION < '1.9.0'
require "sensu-handler"
require "tinder"
require "echelon_chef"
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-handler'
require 'tinder'
require 'echelon_chef'

class Campfire < Sensu::Handler

def incident_key
@event['client']['name'] + '/' + @event['check']['name']
end

def campfire
Tinder::Campfire.new(settings["campfire"]["account"], :ssl => true, :token => settings["campfire"]["token"])
Tinder::Campfire.new(settings['campfire']['account'], ssl: true, token: settings['campfire']['token'])
end

def room
campfire.find_room_by_name(settings["campfire"]["room"])
campfire.find_room_by_name(settings['campfire']['room'])
end

# Pulled from "soon" to be released sensu-plugin gem changes
Expand All @@ -49,16 +48,16 @@ class Campfire < Sensu::Handler
bail 'only repeating alert every ' + n.to_s + ' occurrences' unless @event['occurrences'] % n == 0
end
end

def handle
filter_repeated
filter_repeated
echef = EchelonChef.new(settings['chef'])
bail "Campfire not currently configured" unless settings['campfire']
bail "Node not in valid environment" unless echef.correct_environment?
bail 'Campfire not currently configured' unless settings['campfire']
bail 'Node not in valid environment' unless echef.correct_environment?
description = @event['check']['notification'] || [ @event['client']['name'],
@event['check']['name'],
@event['check']['output'],
@event['client']['address']
@event['client']['address'],
].join(' : ')
description = "RESOLVED - #{description}" if @event['action'] == 'resolve'
begin
Expand All @@ -73,5 +72,4 @@ class Campfire < Sensu::Handler
puts 'campfire -- timed out while attempting to ' + @event['action'] + ' a incident -- ' + incident_key
end
end

end
8 changes: 3 additions & 5 deletions files/default/handlers/default
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require 'sensu-handler'
require 'echelon_chef'

class DefaultHandler < Sensu::Handler

def incident_key
@event['client']['name'] + '/' + @event['check']['name']
end
Expand All @@ -15,8 +14,8 @@ class DefaultHandler < Sensu::Handler
timeout(@event['check']['timeout'] || 10) do
client = @event['client']['name']
echef = EchelonChef.new(settings['chef'])
if(!echef.client_exists?(client))
puts "Client " + client + " was not found! Removing related checks from Sensu"
unless echef.client_exists?(client)
puts 'Client ' + client + ' was not found! Removing related checks from Sensu'
uri = URI("http://#{settings['chef']['api_ip_addr']}/client/" + client)
uri.port = 4567
req = Net::HTTP::Delete.new(uri.path)
Expand All @@ -27,8 +26,7 @@ class DefaultHandler < Sensu::Handler
end
end
rescue Timeout::Error
bail "Timed out while searching for " + client + " on the server (#{incident_key})"
bail 'Timed out while searching for ' + client + " on the server (#{incident_key})"
end
end

end
10 changes: 4 additions & 6 deletions files/default/handlers/librato-occurrences.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
#
# Copyright 2011 Sonian, Inc.
# Copyright:: 2011 Sonian, Inc.
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
Expand All @@ -10,25 +10,23 @@
require 'librato/metrics'

class Librato < Sensu::Handler

def handle
bail "Librato not currently configured" unless settings['librato']
bail 'Librato not currently configured' unless settings['librato']
hostname = @event['client']['name'].split('.').first
check_name = @event['check']['name'].gsub(%r|[ \.]|, '_')
check_name = @event['check']['name'].gsub(/[ \.]/, '_')
metric = "sensu.events.#{hostname}.#{check_name}.occurrences"
value = @event['action'] == 'create' ? @event['occurrences'] : 0

Librato::Metrics.authenticate settings['librato']['email'], settings['librato']['api_key']

begin
timeout(3) do
Librato::Metrics.submit metric.to_sym => {:type => :counter, :value => value, :source => 'sensu'}
Librato::Metrics.submit metric.to_sym => { type: :counter, value: value, source: 'sensu' }
end
rescue Timeout::Error
puts "librato -- timed out while sending metric #{metric}"
rescue => error
puts "librato -- failed to send metric #{metric} : #{error}"
end
end

end
24 changes: 11 additions & 13 deletions files/default/handlers/pagerduty
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This handler creates and resolves PagerDuty incidents, refreshing
# stale incident details every 30 minutes
#
# Copyright 2011 Sonian, Inc.
# Copyright:: 2011 Sonian, Inc.
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
Expand All @@ -14,31 +14,30 @@ require 'echelon_chef'
require 'redphone/pagerduty'

class Pagerduty < Sensu::Handler

def incident_key
@event['client']['name'] + '/' + @event['check']['name']
end

def handle
bail "Pagerduty not currently configured" unless settings['pagerduty']
bail 'Pagerduty not currently configured' unless settings['pagerduty']
echef = EchelonChef.new(settings['chef'])
bail "Node not in valid environment" unless echef.correct_environment?
bail 'Node not in valid environment' unless echef.correct_environment?
description = @event['check']['notification'] || [@event['client']['name'], @event['check']['name'], @event['check']['output']].join(' : ')
begin
timeout(3) do
response = case @event['action']
when 'create'
Redphone::Pagerduty.trigger_incident(
:service_key => settings['pagerduty']['api_key'],
:incident_key => incident_key,
:description => description,
:details => @event
)
service_key: settings['pagerduty']['api_key'],
incident_key: incident_key,
description: description,
details: @event
)
when 'resolve'
Redphone::Pagerduty.resolve_incident(
:service_key => settings['pagerduty']['api_key'],
:incident_key => incident_key
)
service_key: settings['pagerduty']['api_key'],
incident_key: incident_key
)
end
if response['status'] == 'success'
puts 'pagerduty -- ' + @event['action'].capitalize + 'd incident -- ' + incident_key
Expand All @@ -50,5 +49,4 @@ class Pagerduty < Sensu::Handler
puts 'pagerduty -- timed out while attempting to ' + @event['action'] + ' a incident -- ' + incident_key
end
end

end
25 changes: 12 additions & 13 deletions files/default/plugins/elasticsearch/check-es-heap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Check Elasticsearch Heap Usage
# ===
#
# Copyright 2011 Sonian, Inc.
# Copyright:: 2011 Sonian, Inc.
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
Expand All @@ -14,24 +14,23 @@ require 'rest-client'
require 'json'

class ESHeapUsage < Sensu::Plugin::Check::CLI

option :warn,
:short => '-w N',
:long => '--warn N',
:description => 'Heap used in bytes WARNING threshold',
:proc => proc {|a| a.to_i },
:default => 0
short: '-w N',
long: '--warn N',
description: 'Heap used in bytes WARNING threshold',
proc: proc { |a| a.to_i },
default: 0

option :crit,
:short => '-c N',
:long => '--crit N',
:description => 'Heap used in bytes CRITICAL threshold',
:proc => proc {|a| a.to_i },
:default => 0
short: '-c N',
long: '--crit N',
description: 'Heap used in bytes CRITICAL threshold',
proc: proc { |a| a.to_i },
default: 0

def get_es_resource(resource)
begin
r = RestClient::Resource.new("http://localhost:9200/#{resource}", :timeout => 45)
r = RestClient::Resource.new("http://localhost:9200/#{resource}", timeout: 45)
JSON.parse(r.get)
rescue Errno::ECONNREFUSED
warning 'Connection refused'
Expand Down
12 changes: 5 additions & 7 deletions files/default/plugins/elasticsearch/es-cluster-status
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ElasticSearch Cluster Health
# ===
#
# Copyright 2011 Sonian, Inc.
# Copyright:: 2011 Sonian, Inc.
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
Expand All @@ -14,10 +14,9 @@ require 'rest-client'
require 'json'

class ESClusterHealth < Sensu::Plugin::Check::CLI

def get_es_resource(resource)
begin
r = RestClient::Resource.new("http://localhost:9200/#{resource}", :timeout => 45)
r = RestClient::Resource.new("http://localhost:9200/#{resource}", timeout: 45)
JSON.parse(r.get)
rescue Errno::ECONNREFUSED
warning 'Connection refused'
Expand All @@ -41,15 +40,14 @@ class ESClusterHealth < Sensu::Plugin::Check::CLI
if is_master
case get_status
when 'green'
ok "Cluster is green"
ok 'Cluster is green'
when 'yellow'
warning "Cluster is yellow"
warning 'Cluster is yellow'
when 'red'
critical "Cluster is red"
critical 'Cluster is red'
end
else
ok 'Not the master'
end
end

end
8 changes: 3 additions & 5 deletions files/default/plugins/elasticsearch/es-metrics
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# document which is outputted to STDOUT. An exit status of 0 indicates
# the plugin has successfully collected and produced.
#
# Copyright 2011 Sonian, Inc.
# Copyright:: 2011 Sonian, Inc.
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
Expand All @@ -17,7 +17,6 @@ require 'sensu-plugin/metric/cli'
require 'rest-client'

class ESMetrics < Sensu::Plugin::Metric::CLI::JSON

def delete_strings(hash)
hash.each do |key, value|
case value
Expand All @@ -31,21 +30,20 @@ class ESMetrics < Sensu::Plugin::Metric::CLI::JSON

def run
begin
stats = RestClient::Resource.new 'http://localhost:9200/_cluster/nodes/_local/stats', :timeout => 30
stats = RestClient::Resource.new 'http://localhost:9200/_cluster/nodes/_local/stats', timeout: 30
stats = JSON.parse(stats.get)
node = stats['nodes'].keys.first
rescue Errno::ECONNREFUSED
critical
rescue RestClient::RequestTimeout
warning
end
metrics = delete_strings(stats["nodes"][node])
metrics = delete_strings(stats['nodes'][node])
output metrics
if metrics.empty?
warning
else
ok
end
end

end
28 changes: 13 additions & 15 deletions files/default/plugins/files/check-mtime
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@ require 'sensu-plugin/check/cli'
require 'fileutils'

class CheckMtime < Sensu::Plugin::Check::CLI

option :file,
:description => 'File to check last modified time',
:short => '-f FILE',
:long => '--file FILE'
description: 'File to check last modified time',
short: '-f FILE',
long: '--file FILE'

option :warn_age,
:description => 'Warn if mtime greater than provided age in seconds',
:short => '-w SECONDS',
:long => '--warn SECONDS'
description: 'Warn if mtime greater than provided age in seconds',
short: '-w SECONDS',
long: '--warn SECONDS'

option :critical_age,
:description => 'Critical if mtime greater than provided age in seconds',
:short => '-c SECONDS',
:long => '--critical SECONDS'
description: 'Critical if mtime greater than provided age in seconds',
short: '-c SECONDS',
long: '--critical SECONDS'

def run
unknown 'No file specified' unless config[:file]
unknown 'No warn or critical age specified' unless config[:warn_age] || config[:critical_age]
if(File.exists?(config[:file]))
age = Time.now.to_i - File.mtime(config[:file]).to_i
if File.exist?(config[:file])
age = Time.now.to_i - File.mtime(config[:file]).to_i
run_check(:critical, age) || run_check(:warning, age) || ok("file is #{age} seconds old")
else
critical 'file not found'
Expand All @@ -39,9 +38,8 @@ class CheckMtime < Sensu::Plugin::Check::CLI

def run_check(type, age)
to_check = config["#{type}_age".to_sym].to_i
if(to_check > 0 && age >= to_check)
if to_check > 0 && age >= to_check
send(type, "file is #{age - to_check} seconds past #{type}")
end
end

end
Loading