This repository has been archived by the owner on Jul 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
e8b36ac
commit 0953bf3
Showing
11 changed files
with
108 additions
and
16 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,51 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# This handler creates and resolves PagerDuty incidents, refreshing | ||
# stale incident details every 30 minutes | ||
# | ||
# Copyright 2011 Sonian, Inc <chefs@sonian.net> | ||
# | ||
# Released under the same terms as Sensu (the MIT license); see LICENSE | ||
# for details. | ||
|
||
require 'rubygems' if RUBY_VERSION < '1.9.0' | ||
require 'sensu-handler' | ||
require 'redphone/pagerduty' | ||
|
||
class Pagerduty < Sensu::Handler | ||
|
||
def incident_key | ||
@event['client']['name'] + '/' + @event['check']['name'] | ||
end | ||
|
||
def handle | ||
description = @event['check']['notification'] | ||
description ||= [@event['client']['name'], @event['check']['name'], @event['check']['output']].join(' : ') | ||
begin | ||
timeout(10) 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 | ||
) | ||
when 'resolve' | ||
Redphone::Pagerduty.resolve_incident( | ||
:service_key => settings['pagerduty']['api_key'], | ||
:incident_key => incident_key | ||
) | ||
end | ||
if response['status'] == 'success' | ||
puts 'pagerduty -- ' + @event['action'].capitalize + 'd incident -- ' + incident_key | ||
else | ||
puts 'pagerduty -- failed to ' + @event['action'] + ' incident -- ' + incident_key | ||
end | ||
end | ||
rescue Timeout::Error | ||
puts 'pagerduty -- timed out while attempting to ' + @event['action'] + ' a incident -- ' + incident_key | ||
end | ||
end | ||
|
||
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
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
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
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,34 @@ | ||
# | ||
# Cookbook Name:: rubygems-sensu | ||
# Recipe:: pagerduty | ||
# | ||
|
||
include_recipe 'chef-vault' | ||
|
||
pagerduty_creds = chef_vault_item('sensu', 'credentials')['pagerduty'] | ||
|
||
template '/etc/sensu/conf.d/pagerduty.json' do | ||
source 'pagerduty.json.erb' | ||
owner 'sensu' | ||
group 'sensu' | ||
variables( | ||
api_key: pagerduty_creds['api_key'], | ||
) | ||
end | ||
|
||
gem_package 'redphone' do | ||
gem_binary '/opt/sensu/embedded/bin/gem' | ||
end | ||
|
||
cookbook_file '/etc/sensu/handlers/pagerduty.rb' do | ||
path '/etc/sensu/handlers/pagerduty.rb' | ||
source 'pagerduty.rb' | ||
mode "0755" | ||
action :create | ||
end | ||
|
||
sensu_handler 'pagerduty' do | ||
type 'pipe' | ||
command 'pagerduty.rb' | ||
severities ['ok', 'critical'] | ||
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
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
5 changes: 5 additions & 0 deletions
5
cookbooks/rubygems-sensu/templates/default/pagerduty.json.erb
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,5 @@ | ||
{ | ||
"pagerduty": { | ||
"api_key": "<%= @api_key %>" | ||
} | ||
} |