├── test ├── fixtures │ ├── minimal_create.json │ ├── minimal_resolve.json │ ├── create_dynamic_prefix.json │ ├── check_with_contexts.json │ ├── pagerduty_settings.json │ ├── no_override_warning.json │ ├── no_override_critical.json │ ├── recovery_no_override_warning.json │ ├── recovery_no_override_critical.json │ ├── pd_no_override.json │ ├── pd_client_override.json │ ├── baseline_override_critical_event.json │ ├── baseline_override_warning_event.json │ ├── check_override_critical_event.json │ ├── check_override_warning_event.json │ ├── pd_check_override.json │ ├── recovery_baseline_critical_event.json │ ├── recovery_baseline_warning_event.json │ ├── recovery_check_critical_event.json │ ├── recovery_check_warning_event.json │ ├── check_and_baseline_override_critical_event.json │ ├── check_and_baseline_override_warning_event.json │ └── check_and_client_override.json ├── spec_helper.rb └── bin │ ├── handler-pagerduty_spec.rb │ └── mutator-pagerduty-priority-override_spec.rb ├── lib ├── sensu-plugins-pagerduty.rb └── sensu-plugins-pagerduty │ └── version.rb ├── CONTRIBUTING.md ├── Gemfile ├── .gitignore ├── .rubocop.yml ├── .github └── PULL_REQUEST_TEMPLATE.md ├── Rakefile ├── LICENSE ├── .travis.yml ├── sensu-plugins-pagerduty.gemspec ├── .bonsai.yml ├── bin ├── mutator-pagerduty-priority-override.rb └── handler-pagerduty.rb ├── CHANGELOG.md └── README.md /test/fixtures/minimal_create.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create" 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/minimal_resolve.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "resolve" 3 | } 4 | -------------------------------------------------------------------------------- /lib/sensu-plugins-pagerduty.rb: -------------------------------------------------------------------------------- 1 | require 'sensu-plugins-pagerduty/version' 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | [Development Documentation](http://sensu-plugins.io/docs/developer_guidelines.html) 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in sensu-plugins-pagerduty.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /test/fixtures/create_dynamic_prefix.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "client": { 4 | "name": "i-424242" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /lib/sensu-plugins-pagerduty/version.rb: -------------------------------------------------------------------------------- 1 | module SensuPluginsPagerduty 2 | module Version 3 | MAJOR = 5 4 | MINOR = 0 5 | PATCH = 0 6 | 7 | VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.') 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | *.bundle 11 | *.so 12 | *.o 13 | *.a 14 | mkmf.log 15 | .vagrant/* 16 | .DS_Store 17 | .idea/* 18 | *.gem 19 | -------------------------------------------------------------------------------- /test/fixtures/check_with_contexts.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": {}, 5 | "check": { 6 | "pagerduty_contexts": [ 7 | { 8 | "type": "link", 9 | "href": "http://example.com/" 10 | } 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/pagerduty_settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "pagerduty": { 3 | "dynamic_description_prefix_key" : "name", 4 | "api_key": "BASE_KEY", 5 | "CHECK_OVERRIDE": { 6 | "api_key": "CHECK_OVERRIDE" 7 | }, 8 | "TEST_TEAM": { 9 | "api_key": "CLIENT_OVERRIDE" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # require 'codeclimate-test-reporter' 2 | # CodeClimate::TestReporter.start 3 | 4 | RSpec.configure do |c| 5 | c.formatter = :documentation 6 | c.color = true 7 | end 8 | 9 | def fixture_path 10 | File.expand_path('../fixtures', __FILE__) 11 | end 12 | 13 | def fixture(f) 14 | File.new(File.join(fixture_path, f)) 15 | end 16 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | 2 | MethodLength: 3 | Max: 200 4 | 5 | LineLength: 6 | Max: 160 7 | 8 | AbcSize: 9 | Max: 100 10 | 11 | FileName: 12 | Enabled: false 13 | 14 | PerceivedComplexity: 15 | Enabled: false 16 | 17 | CyclomaticComplexity: 18 | Enabled: false 19 | 20 | ClassLength: 21 | Enabled: false 22 | 23 | IfUnlessModifier: 24 | Enabled: false 25 | 26 | RegexpLiteral: 27 | Enabled: false 28 | 29 | Style/Documentation: 30 | Enabled: false 31 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Pull Request Checklist 2 | 3 | **Is this in reference to an existing issue?** 4 | 5 | #### General 6 | 7 | - [ ] Update Changelog following the conventions laid out [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md) 8 | 9 | - [ ] Update README with any necessary configuration snippets 10 | 11 | - [ ] Binstubs are created if needed 12 | 13 | - [ ] RuboCop passes 14 | 15 | - [ ] Existing tests pass 16 | 17 | #### New Plugins 18 | 19 | - [ ] Tests 20 | 21 | - [ ] Add the plugin to the README 22 | 23 | - [ ] Does it have a complete header as outlined [here](http://sensu-plugins.io/docs/developer_guidelines.html#coding-style) 24 | 25 | #### Purpose 26 | 27 | #### Known Compatibility Issues 28 | -------------------------------------------------------------------------------- /test/fixtures/no_override_warning.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159 14 | }, 15 | "check":{ 16 | "name": "frontend_http_check", 17 | "issued": 1326390169, 18 | "subscribers":[ 19 | "frontend" 20 | ], 21 | "interval": 60, 22 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 23 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 24 | "status": 1, 25 | "handler": "slack", 26 | "history": [ 27 | "0", 28 | "1" 29 | ] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/fixtures/no_override_critical.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159 14 | }, 15 | "check":{ 16 | "name": "frontend_http_check", 17 | "issued": 1326390169, 18 | "subscribers":[ 19 | "frontend" 20 | ], 21 | "interval": 60, 22 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 23 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 24 | "status": 2, 25 | "handler": "slack", 26 | "history": [ 27 | "0", 28 | "2" 29 | ] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/fixtures/recovery_no_override_warning.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "resolve", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159 14 | }, 15 | "check":{ 16 | "name": "frontend_http_check", 17 | "issued": 1326390169, 18 | "subscribers":[ 19 | "frontend" 20 | ], 21 | "interval": 60, 22 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 23 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 24 | "status": 0, 25 | "handler": "slack", 26 | "history": [ 27 | "1", 28 | "0" 29 | ] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/fixtures/recovery_no_override_critical.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "resolve", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159 14 | }, 15 | "check":{ 16 | "name": "frontend_http_check", 17 | "issued": 1326390169, 18 | "subscribers":[ 19 | "frontend" 20 | ], 21 | "interval": 60, 22 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 23 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 24 | "status": 0, 25 | "handler": "slack", 26 | "history": [ 27 | "2", 28 | "0" 29 | ] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/fixtures/pd_no_override.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "timestamp": 1326390159, 13 | "pd_override": { 14 | "frontend_http_check": { 15 | "warning": "CHECK_WARNING_OVERRIDE", 16 | "critical": "CHECK_CRITICAL_OVERRIDE" 17 | } 18 | } 19 | }, 20 | "check":{ 21 | "name": "frontend_http_check", 22 | "issued": 1326390169, 23 | "subscribers":[ 24 | "frontend" 25 | ], 26 | "interval": 60, 27 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 28 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 29 | "status": 2, 30 | "handler": "slack", 31 | "history": [ 32 | "0", 33 | "2" 34 | ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/fixtures/pd_client_override.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "frontend_http_check": { 16 | "warning": "CHECK_WARNING_OVERRIDE", 17 | "critical": "CHECK_CRITICAL_OVERRIDE" 18 | } 19 | } 20 | }, 21 | "check":{ 22 | "name": "frontend_http_check", 23 | "issued": 1326390169, 24 | "subscribers":[ 25 | "frontend" 26 | ], 27 | "interval": 60, 28 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 29 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 30 | "status": 2, 31 | "handler": "slack", 32 | "history": [ 33 | "0", 34 | "2" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/fixtures/baseline_override_critical_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "baseline": { 16 | "warning": "BASELINET_WARNING_OVERRIDE", 17 | "critical": "BASELINE_CRITICAL_OVERRIDE" 18 | } 19 | } 20 | }, 21 | "check":{ 22 | "name": "frontend_http_check", 23 | "issued": 1326390169, 24 | "subscribers":[ 25 | "frontend" 26 | ], 27 | "interval": 60, 28 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 29 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 30 | "status": 2, 31 | "handler": "slack", 32 | "history": [ 33 | "0", 34 | "2" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/fixtures/baseline_override_warning_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "baseline": { 16 | "warning": "BASELINET_WARNING_OVERRIDE", 17 | "critical": "BASELINE_CRITICAL_OVERRIDE" 18 | } 19 | } 20 | }, 21 | "check":{ 22 | "name": "frontend_http_check", 23 | "issued": 1326390169, 24 | "subscribers":[ 25 | "frontend" 26 | ], 27 | "interval": 60, 28 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 29 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 30 | "status": 1, 31 | "handler": "slack", 32 | "history": [ 33 | "0", 34 | "2" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/fixtures/check_override_critical_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "frontend_http_check": { 16 | "warning": "CHECK_WARNING_OVERRIDE", 17 | "critical": "CHECK_CRITICAL_OVERRIDE" 18 | } 19 | } 20 | }, 21 | "check":{ 22 | "name": "frontend_http_check", 23 | "issued": 1326390169, 24 | "subscribers":[ 25 | "frontend" 26 | ], 27 | "interval": 60, 28 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 29 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 30 | "status": 2, 31 | "handler": "slack", 32 | "history": [ 33 | "0", 34 | "2" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/fixtures/check_override_warning_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "frontend_http_check": { 16 | "warning": "CHECK_WARNING_OVERRIDE", 17 | "critical": "CHECK_CRITICAL_OVERRIDE" 18 | } 19 | } 20 | }, 21 | "check":{ 22 | "name": "frontend_http_check", 23 | "issued": 1326390169, 24 | "subscribers":[ 25 | "frontend" 26 | ], 27 | "interval": 60, 28 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 29 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 30 | "status": 1, 31 | "handler": "slack", 32 | "history": [ 33 | "0", 34 | "2" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/fixtures/pd_check_override.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "CLIENT_OVERRIDE", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "frontend_http_check": { 16 | "warning": "CHECK_WARNING_OVERRIDE", 17 | "critical": "CHECK_CRITICAL_OVERRIDE" 18 | } 19 | } 20 | }, 21 | "check":{ 22 | "name": "frontend_http_check", 23 | "issued": 1326390169, 24 | "subscribers":[ 25 | "frontend" 26 | ], 27 | "pager_team": "CHECK_OVERRIDE", 28 | "interval": 60, 29 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 30 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 31 | "status": 2, 32 | "handler": "slack", 33 | "history": [ 34 | "0", 35 | "2" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require 'github/markup' 3 | require 'redcarpet' 4 | require 'rspec/core/rake_task' 5 | require 'rubocop/rake_task' 6 | require 'yard' 7 | require 'yard/rake/yardoc_task' 8 | 9 | args = [:spec, :make_bin_executable, :yard, :rubocop, :check_binstubs] 10 | 11 | YARD::Rake::YardocTask.new do |t| 12 | OTHER_PATHS = %w().freeze 13 | t.files = ['lib/**/*.rb', 'bin/**/*.rb', OTHER_PATHS] 14 | t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md) 15 | end 16 | 17 | RuboCop::RakeTask.new 18 | 19 | RSpec::Core::RakeTask.new(:spec) do |r| 20 | r.pattern = FileList['**/**/*_spec.rb'] 21 | end 22 | 23 | desc 'Make all plugins executable' 24 | task :make_bin_executable do 25 | `chmod -R +x bin/*` 26 | end 27 | 28 | desc 'Test for binstubs' 29 | task :check_binstubs do 30 | bin_list = Gem::Specification.load('sensu-plugins-pagerduty.gemspec').executables 31 | bin_list.each do |b| 32 | `which #{ b }` 33 | unless $CHILD_STATUS.success? 34 | puts "#{b} was not a binstub" 35 | exit 36 | end 37 | end 38 | end 39 | 40 | task default: args 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Sensu-Plugins 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /test/fixtures/recovery_baseline_critical_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "baseline": { 16 | "warning": "BASELINET_WARNING_OVERRIDE", 17 | "critical": "BASELINE_CRITICAL_OVERRIDE" 18 | }, 19 | "SOME_OTHER_CHECK": { 20 | "warning": "CHECK_WARNING_OVERRIDE", 21 | "critical": "CHECK_CRITICAL_OVERRIDE" 22 | } 23 | } 24 | }, 25 | "check":{ 26 | "name": "frontend_http_check", 27 | "issued": 1326390169, 28 | "subscribers":[ 29 | "frontend" 30 | ], 31 | "interval": 60, 32 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 33 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 34 | "status": 0, 35 | "handler": "slack", 36 | "history": [ 37 | "2", 38 | "0" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/fixtures/recovery_baseline_warning_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "baseline": { 16 | "warning": "BASELINET_WARNING_OVERRIDE", 17 | "critical": "BASELINE_CRITICAL_OVERRIDE" 18 | }, 19 | "SOME_OTHER_CHECK": { 20 | "warning": "CHECK_WARNING_OVERRIDE", 21 | "critical": "CHECK_CRITICAL_OVERRIDE" 22 | } 23 | } 24 | }, 25 | "check":{ 26 | "name": "frontend_http_check", 27 | "issued": 1326390169, 28 | "subscribers":[ 29 | "frontend" 30 | ], 31 | "interval": 60, 32 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 33 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 34 | "status": 0, 35 | "handler": "slack", 36 | "history": [ 37 | "1", 38 | "0" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/fixtures/recovery_check_critical_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "baseline": { 16 | "warning": "BASELINET_WARNING_OVERRIDE", 17 | "critical": "BASELINE_CRITICAL_OVERRIDE" 18 | }, 19 | "frontend_http_check": { 20 | "warning": "CHECK_WARNING_OVERRIDE", 21 | "critical": "CHECK_CRITICAL_OVERRIDE" 22 | } 23 | } 24 | }, 25 | "check":{ 26 | "name": "frontend_http_check", 27 | "issued": 1326390169, 28 | "subscribers":[ 29 | "frontend" 30 | ], 31 | "interval": 60, 32 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 33 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 34 | "status": 0, 35 | "handler": "slack", 36 | "history": [ 37 | "2", 38 | "0" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/fixtures/recovery_check_warning_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "baseline": { 16 | "warning": "BASELINET_WARNING_OVERRIDE", 17 | "critical": "BASELINE_CRITICAL_OVERRIDE" 18 | }, 19 | "frontend_http_check": { 20 | "warning": "CHECK_WARNING_OVERRIDE", 21 | "critical": "CHECK_CRITICAL_OVERRIDE" 22 | } 23 | } 24 | }, 25 | "check":{ 26 | "name": "frontend_http_check", 27 | "issued": 1326390169, 28 | "subscribers":[ 29 | "frontend" 30 | ], 31 | "interval": 60, 32 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 33 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 34 | "status": 0, 35 | "handler": "slack", 36 | "history": [ 37 | "1", 38 | "0" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/fixtures/check_and_baseline_override_critical_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "baseline": { 16 | "warning": "BASELINET_WARNING_OVERRIDE", 17 | "critical": "BASELINE_CRITICAL_OVERRIDE" 18 | }, 19 | "frontend_http_check": { 20 | "warning": "CHECK_WARNING_OVERRIDE", 21 | "critical": "CHECK_CRITICAL_OVERRIDE" 22 | } 23 | } 24 | }, 25 | "check":{ 26 | "name": "frontend_http_check", 27 | "issued": 1326390169, 28 | "subscribers":[ 29 | "frontend" 30 | ], 31 | "interval": 60, 32 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 33 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 34 | "status": 2, 35 | "handler": "slack", 36 | "history": [ 37 | "0", 38 | "2" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/fixtures/check_and_baseline_override_warning_event.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "baseline": { 16 | "warning": "BASELINET_WARNING_OVERRIDE", 17 | "critical": "BASELINE_CRITICAL_OVERRIDE" 18 | }, 19 | "frontend_http_check": { 20 | "warning": "CHECK_WARNING_OVERRIDE", 21 | "critical": "CHECK_CRITICAL_OVERRIDE" 22 | } 23 | } 24 | }, 25 | "check":{ 26 | "name": "frontend_http_check", 27 | "issued": 1326390169, 28 | "subscribers":[ 29 | "frontend" 30 | ], 31 | "interval": 60, 32 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 33 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 34 | "status": 1, 35 | "handler": "slack", 36 | "history": [ 37 | "0", 38 | "2" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/fixtures/check_and_client_override.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "create", 3 | "occurrences": 1, 4 | "client": { 5 | "name": "i-424242", 6 | "address": "8.8.8.8", 7 | "subscriptions": [ 8 | "production", 9 | "webserver", 10 | "mysql" 11 | ], 12 | "pager_team": "TEST_TEAM", 13 | "timestamp": 1326390159, 14 | "pd_override": { 15 | "baseline": { 16 | "warning": "BASELINET_WARNING_OVERRIDE", 17 | "critical": "BASELINE_CRITICAL_OVERRIDE" 18 | }, 19 | "frontend_http_check": { 20 | "warning": "CHECK_WARNING_OVERRIDE", 21 | "critical": "CHECK_CRITICAL_OVERRIDE" 22 | } 23 | } 24 | }, 25 | "check":{ 26 | "name": "frontend_http_check", 27 | "issued": 1326390169, 28 | "subscribers":[ 29 | "frontend" 30 | ], 31 | "pager_team": "CHECK_OVERRIDE", 32 | "interval": 60, 33 | "command": "check_http -I 127.0.0.1 -u http://web.example.com/healthcheck.html -R \'pageok\'", 34 | "output": "HTTP CRITICAL: HTTP/1.1 503 Service Temporarily Unavailable", 35 | "status": 2, 36 | "handler": "slack", 37 | "history": [ 38 | "0", 39 | "2" 40 | ] 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | cache: 3 | - bundler 4 | install: 5 | - bundle install 6 | rvm: 7 | - 2.3.0 8 | - 2.4.1 9 | notifications: 10 | email: 11 | recipients: 12 | - sensu-plugin@sensu-plugins.io 13 | on_success: change 14 | on_failure: always 15 | script: 16 | - bundle exec rake default 17 | - gem build sensu-plugins-pagerduty.gemspec 18 | - gem install sensu-plugins-pagerduty-*.gem 19 | before_deploy: 20 | - bash -c "[ ! -d bonsai/ ] && git clone https://github.com/sensu/sensu-go-bonsai-asset.git bonsai || echo 'bonsai/ exists, skipping git clone'" 21 | deploy: 22 | - provider: rubygems 23 | api_key: 24 | secure: E906GFnaEQtLBxVsFt5rIinzVEb3ga8V5rPcxzOkGVWca17ag3pJ9rBXpiDd9zzkAF61zSfW7MbUu9KrddihSddMXM8I1Vt35xGw6pZTNqtzGeZA7egIdxks7XxszibXtZb0pOvBOAg2eGYQARzzJkvhgFPu/pVn5OOj8Oed9zU= 25 | gem: sensu-plugins-pagerduty 26 | on: 27 | tags: true 28 | all_branches: true 29 | rvm: 2.3.0 30 | rvm: 2.4.1 31 | repo: sensu-plugins/sensu-plugins-pagerduty 32 | - provider: script 33 | script: bonsai/ruby-runtime/travis-build-ruby-plugin-assets.sh sensu-plugins-pagerduty 34 | skip_cleanup: true 35 | on: 36 | tags: true 37 | all_branches: true 38 | rvm: 2.4.1 39 | -------------------------------------------------------------------------------- /sensu-plugins-pagerduty.gemspec: -------------------------------------------------------------------------------- 1 | lib = File.expand_path('../lib', __FILE__) 2 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 3 | 4 | require 'date' 5 | require_relative 'lib/sensu-plugins-pagerduty' 6 | 7 | Gem::Specification.new do |s| 8 | s.authors = ['Sensu-Plugins and contributors'] 9 | 10 | s.date = Date.today.to_s 11 | s.description = 'This plugin provides a Sensu handler for PagerDuty' 12 | s.email = '' 13 | s.executables = Dir.glob('bin/**/*.rb').map { |file| File.basename(file) } 14 | s.files = Dir.glob('{bin,lib}/**/*') + %w(LICENSE README.md CHANGELOG.md) 15 | s.homepage = 'https://github.com/sensu-plugins/sensu-plugins-pagerduty' 16 | s.license = 'MIT' 17 | s.metadata = { 'maintainer' => 'sensu-plugin', 18 | 'development_status' => 'active', 19 | 'production_status' => 'stable - production ready', 20 | 'release_draft' => 'false', 21 | 'release_prerelease' => 'false' } 22 | s.name = 'sensu-plugins-pagerduty' 23 | s.platform = Gem::Platform::RUBY 24 | s.post_install_message = 'You can use the embedded Ruby by setting EMBEDDED_RUBY=true in /etc/default/sensu' 25 | s.require_paths = ['lib'] 26 | s.required_ruby_version = '>= 2.3.0' 27 | s.summary = 'Sensu plugins for pagerduty' 28 | s.test_files = s.files.grep(%r{^(test|spec|features)/}) 29 | s.version = SensuPluginsPagerduty::Version::VER_STRING 30 | 31 | s.add_runtime_dependency 'sensu-plugin', '~> 4.0' 32 | s.add_runtime_dependency 'pagerduty', '= 2.1.2' 33 | 34 | s.add_development_dependency 'bundler', '~> 1.7' 35 | s.add_development_dependency 'github-markup', '~> 3.0' 36 | s.add_development_dependency 'pry', '~> 0.10' 37 | s.add_development_dependency 'rake', '~> 13.0' 38 | s.add_development_dependency 'redcarpet', '~> 3.2' 39 | s.add_development_dependency 'rspec', '~> 3.1' 40 | s.add_development_dependency 'rubocop', '~> 0.40.0' 41 | s.add_development_dependency 'yard', '~> 0.8' 42 | end 43 | -------------------------------------------------------------------------------- /.bonsai.yml: -------------------------------------------------------------------------------- 1 | --- 2 | description: "#{repo}" 3 | builds: 4 | - platform: "alpine" 5 | arch: "amd64" 6 | asset_filename: "#{repo}_#{version}_alpine_linux_amd64.tar.gz" 7 | sha_filename: "#{repo}_#{version}_sha512-checksums.txt" 8 | filter: 9 | - "entity.system.os == 'linux'" 10 | - "entity.system.arch == 'amd64'" 11 | - "entity.system.platform == 'alpine'" 12 | - "entity.system.platform_version.split('.')[0] == '3'" 13 | - platform: "alpine3.8" 14 | arch: "amd64" 15 | asset_filename: "#{repo}_#{version}_alpine3.8_linux_amd64.tar.gz" 16 | sha_filename: "#{repo}_#{version}_sha512-checksums.txt" 17 | filter: 18 | - "entity.system.os == 'linux'" 19 | - "entity.system.arch == 'amd64'" 20 | - "entity.system.platform == 'alpine'" 21 | - platform: "centos" 22 | arch: "amd64" 23 | asset_filename: "#{repo}_#{version}_centos_linux_amd64.tar.gz" 24 | sha_filename: "#{repo}_#{version}_sha512-checksums.txt" 25 | filter: 26 | - "entity.system.os == 'linux'" 27 | - "entity.system.arch == 'amd64'" 28 | - "entity.system.platform_family == 'rhel'" 29 | - platform: "centos6" 30 | arch: "amd64" 31 | asset_filename: "#{repo}_#{version}_centos6_linux_amd64.tar.gz" 32 | sha_filename: "#{repo}_#{version}_sha512-checksums.txt" 33 | filter: 34 | - "entity.system.os == 'linux'" 35 | - "entity.system.arch == 'amd64'" 36 | - "entity.system.platform_family == 'rhel'" 37 | - "entity.system.platform_version.split('.')[0] == '6'" 38 | - platform: "centos7" 39 | arch: "amd64" 40 | asset_filename: "#{repo}_#{version}_centos7_linux_amd64.tar.gz" 41 | sha_filename: "#{repo}_#{version}_sha512-checksums.txt" 42 | filter: 43 | - "entity.system.os == 'linux'" 44 | - "entity.system.arch == 'amd64'" 45 | - "entity.system.platform_family == 'rhel'" 46 | - "entity.system.platform_version.split('.')[0] == '7'" 47 | - platform: "debian" 48 | arch: "amd64" 49 | asset_filename: "#{repo}_#{version}_debian_linux_amd64.tar.gz" 50 | sha_filename: "#{repo}_#{version}_sha512-checksums.txt" 51 | filter: 52 | - "entity.system.os == 'linux'" 53 | - "entity.system.arch == 'amd64'" 54 | - "entity.system.platform_family == 'debian'" 55 | - platform: "debian9" 56 | arch: "amd64" 57 | asset_filename: "#{repo}_#{version}_debian9_linux_amd64.tar.gz" 58 | sha_filename: "#{repo}_#{version}_sha512-checksums.txt" 59 | filter: 60 | - "entity.system.os == 'linux'" 61 | - "entity.system.arch == 'amd64'" 62 | -------------------------------------------------------------------------------- /bin/mutator-pagerduty-priority-override.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # PagerDuty 4 | # === 5 | # 6 | # DESCRIPTION: 7 | # This mutator take the Client hash and looks for overrides of the pager_team. 8 | # PagerDuty Handler looks for client['pager_team'] to know which pager duty api token to use. 9 | # This will allow user to set high and low priority alerts on the client as a whole, 10 | # or on a check by check basis. This will also allow override on a warning and critical basis 11 | # for each check. 12 | # 13 | # EX: Override all warnings on host 14 | # client.pd_override.baseline.warning: 15 | # 16 | # EX: Override warning on host for specific check 17 | # client.pd_override..warning: 18 | # 19 | # OUTPUT: 20 | # Sensu event with pager_team value changed if an override is passed. 21 | # 22 | # PLATFORM: 23 | # all 24 | # 25 | # DEPENDENCIES: 26 | # none 27 | # 28 | # Copyright 2015 Zach Bintliff 29 | # 30 | # Released under the same terms as Sensu (the MIT license); see LICENSE 31 | # for details. 32 | require 'json' 33 | 34 | module Sensu 35 | module Mutator 36 | class PagerDuty 37 | class PriorityOverride 38 | ## Make it a class that takes an IO object for easier testing 39 | def execute(input = STDIN) 40 | # parse event 41 | event = JSON.parse(input.read, symbolize_names: true) 42 | 43 | check_name = event[:check][:name] 44 | status = get_status_string(event[:check]) 45 | 46 | baseline_override = get_override(event, 'baseline', status) 47 | check_override = get_override(event, check_name, status) 48 | 49 | if !check_override.nil? 50 | event[:client][:pager_team] = check_override 51 | elsif !baseline_override.nil? 52 | event[:client][:pager_team] = baseline_override 53 | end 54 | JSON.dump(event) 55 | end 56 | 57 | def get_status_string(check) 58 | status = check[:status] 59 | result = 'critical' 60 | if status == 1 61 | result = 'warning' 62 | elsif status == 0 63 | ## 0 means its a resolve event, to know which PagerDuty API to resolve on 64 | ## we need to look at previous alert 65 | ## strangely enough the history array in the event is an array of strings... 66 | result = get_status_string(status: check[:history][-2].to_i) 67 | end 68 | result 69 | end 70 | 71 | def get_override(event, check, status) 72 | return nil if !event[:client].key?(:pd_override) || !event[:client][:pd_override].key?(check.to_sym) 73 | event[:client][:pd_override][check.to_sym][status.to_sym] 74 | end 75 | end 76 | end 77 | end 78 | end 79 | 80 | ## Is called from Gem script. Program name is full path to this script 81 | ### __FILE__ is the initial script ran, which is 82 | ### /usr/local/bin/mutator-pagerduty-priority-override.rb 83 | if $PROGRAM_NAME.include?(__FILE__.split('/').last) 84 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 85 | puts mutator.execute 86 | end 87 | -------------------------------------------------------------------------------- /bin/handler-pagerduty.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # This handler creates and resolves PagerDuty incidents, refreshing 4 | # stale incident details every 30 minutes 5 | # 6 | # Copyright 2011 Sonian, Inc 7 | # 8 | # Released under the same terms as Sensu (the MIT license); see LICENSE 9 | # for details. 10 | # 11 | # Note: The sensu api token could also be configured on a per client or per check basis. 12 | # By defining the "pager_team" attribute in the client config file or the check config. 13 | # The override order will be check > client > json_config 14 | # 15 | # Dependencies: 16 | # 17 | # sensu-plugin ~> 2.5 18 | # 19 | 20 | require 'sensu-handler' 21 | require 'pagerduty' 22 | 23 | # 24 | # Pagerduty 25 | # 26 | class PagerdutyHandler < Sensu::Handler 27 | option :json_config, 28 | description: 'Config key Name, this is not a path to a file but rather the key name within sensu to check', 29 | short: '-j JsonConfigKey', 30 | long: '--json_config JsonConfigKey', 31 | required: false, 32 | default: 'pagerduty' 33 | 34 | def incident_key 35 | source = @event['check']['source'] || @event['client']['name'] 36 | incident_id = [source, @event['check']['name']].join('/') 37 | dedup_rules = settings[json_config]['dedup_rules'] || {} 38 | dedup_rules.each do |key, val| 39 | incident_id = incident_id.gsub(Regexp.new(key), val) 40 | end 41 | incident_id 42 | end 43 | 44 | def json_config 45 | @json_config ||= config[:json_config] 46 | end 47 | 48 | def api_key 49 | @api_key ||= 50 | if @event['check']['pager_team'] 51 | settings[json_config][@event['check']['pager_team']]['api_key'] 52 | elsif @event['client']['pager_team'] && settings[json_config][@event['client']['pager_team']].nil? 53 | puts "you configured your client to use a pager team of #{@event['client']['pager_team']} but it was nil, falling back to default key" 54 | settings[json_config]['api_key'] 55 | elsif @event['client']['pager_team'] 56 | settings[json_config][@event['client']['pager_team']]['api_key'] 57 | else 58 | settings[json_config]['api_key'] 59 | end 60 | end 61 | 62 | def proxy_settings 63 | proxy_settings = {} 64 | 65 | proxy_settings['proxy_host'] = settings[json_config]['proxy_host'] || nil 66 | proxy_settings['proxy_port'] = settings[json_config]['proxy_port'] || 3128 67 | proxy_settings['proxy_username'] = settings[json_config]['proxy_username'] || '' 68 | proxy_settings['proxy_password'] = settings[json_config]['proxy_password'] || '' 69 | 70 | proxy_settings 71 | end 72 | 73 | def contexts 74 | @contexts ||= @event['check']['pagerduty_contexts'] || [] 75 | end 76 | 77 | def description_prefix 78 | @description_prefix = if @event['client'].key?(settings[json_config]['dynamic_description_prefix_key']) 79 | "(#{@event['client'][settings[json_config]['dynamic_description_prefix_key']]})" 80 | else 81 | settings[json_config]['description_prefix'] 82 | end 83 | end 84 | 85 | def handle(pd_client = nil) 86 | if settings[json_config].nil? 87 | p "invalid config: #{options[:json_config]} you need to pass a key and not a file" 88 | exit 3 # unknown 89 | end 90 | incident_key_prefix = settings[json_config]['incident_key_prefix'] 91 | description_prefix = description_prefix() 92 | proxy_settings = proxy_settings() 93 | begin 94 | tries ||= 3 95 | Timeout.timeout(10) do 96 | if proxy_settings['proxy_host'] 97 | pagerduty = pd_client || Pagerduty.new(api_key, 98 | proxy_host: proxy_settings['proxy_host'], 99 | proxy_port: proxy_settings['proxy_port'], 100 | proxy_username: proxy_settings['proxy_username'], 101 | proxy_password: proxy_settings['proxy_password']) 102 | else 103 | pagerduty = pd_client || Pagerduty.new(api_key) 104 | end 105 | 106 | begin 107 | case @event['action'] 108 | when 'create', 'flapping' 109 | pagerduty.trigger([description_prefix, event_summary].compact.join(' '), 110 | incident_key: [incident_key_prefix, incident_key].compact.join(''), 111 | details: @event, 112 | contexts: contexts) 113 | when 'resolve' 114 | pagerduty.get_incident([incident_key_prefix, incident_key].compact.join('')).resolve( 115 | [description_prefix, event_summary].compact.join(' '), @event 116 | ) 117 | end 118 | puts 'pagerduty -- ' + @event['action'].capitalize + 'd incident -- ' + incident_key 119 | rescue Net::HTTPServerException => error 120 | if (tries -= 1) > 0 121 | retry 122 | else 123 | puts 'pagerduty -- failed to ' + @event['action'] + ' incident -- ' + incident_key + ' -- ' + 124 | error.response.code + ' ' + error.response.message + ': ' + error.response.body 125 | end 126 | end 127 | end 128 | rescue Timeout::Error 129 | if (tries -= 1) > 0 130 | retry 131 | else 132 | puts 'pagerduty -- timed out while attempting to ' + @event['action'] + ' a incident -- ' + incident_key 133 | end 134 | end 135 | end 136 | end 137 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | This project adheres to [Semantic Versioning](http://semver.org/). 3 | 4 | This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md) 5 | 6 | ## [Unreleased] 7 | 8 | ## [5.0.0] - 2019-09-16 9 | ### Breaking Changes 10 | - Bump `sensu-plugin` dependency from `~> 2.5` to `~> 4.0` you can read the changelog entries for [4.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#400---2018-02-17), [3.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#300---2018-12-04), and [2.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#v200---2017-03-29) 11 | - Bump `ruby-version` from `~> 2.0` to `~> 2.3` 12 | 13 | ### Added 14 | - Travis build automation to generate Sensu Asset tarballs that can be used n conjunction with Sensu provided ruby runtime assets and the Bonsai Asset Index 15 | - Require latest sensu-plugin for [Sensu Go support](https://github.com/sensu-plugins/sensu-plugin#sensu-go-enablement) 16 | 17 | ## [4.1.0] - 2018-12-04 18 | ### Changed 19 | - updated `pagerduty` dependancy (@dependabot) 20 | 21 | ## [4.0.0] - 2018-06-04 22 | ### Breaking Changes 23 | - Bumped dependency of `sensu-plugin` to 2.x which will globally disable deprecated event filtering. You can read about it [here](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#v145---2017-03-07) (@rajiv-g) 24 | 25 | ## [3.1.0] - 2018-03-17 26 | ### Added 27 | - error handling when `json_config` key is not found to help users deal with the problem. Not great but better than a `NilClass` error (@majormoses) 28 | 29 | ### Changed 30 | - changed the description of `json_config` to reflect that this is a key not the json file (@majormoses) 31 | 32 | ## [3.0.1] - 2018-02-16 33 | ### Added 34 | - ruby 2.4 testing (@majormoses) 35 | 36 | ### Fixed 37 | - PR template typo (@majormoses) 38 | - if pager_team is not found in the handler json config, the default key will be used instead (@internaught) 39 | 40 | ### Changed 41 | - updated changelog guidelines location (@majormoses) 42 | 43 | ## [3.0.0] - 2017-06-01 44 | ### Breaking Change 45 | - changed the precedence of pager_team evaluation from `client -> check -> json_config` to `check -> client -> json_config` (@guru-beach) 46 | ### Added 47 | - support for flapping events to be created (@majormoses) 48 | 49 | ## [2.2.0] - 2017-03-23 50 | ### Added 51 | - Add retries for Timeouts and HTTP errors (@johanek) 52 | 53 | ## [2.1.0] - 2017-02-28 54 | ### Added 55 | - Add contexts support (@zroger) 56 | - Update timeout syntax and extend to 10 seconds. (@luckymike) 57 | - Allow adding some dynamic fields (from the event sensu client config) to the PD event description (@Oded-B) 58 | 59 | ## [2.0.0] - 2016-06-29 60 | ### Added 61 | - Proxy support (@lcrisci) 62 | - Support for Ruby 2.3 63 | 64 | ### Removed 65 | - Support for Ruby 1.9.3 66 | 67 | ### Changed 68 | - Update to Rubocop 0.40 and cleanup 69 | 70 | ## [1.0.0] - 2016-04-12 71 | 72 | NOTE: There is no new functionality in this release but with the addition of test coverage we are 73 | marking it as a stable 1.0.0 release. 74 | 75 | ### Added 76 | - Add tests (@zbintliff) 77 | 78 | ### Fixed 79 | - Fix tests that were always exiting 0 80 | - Fix resolution of events (#21) 81 | 82 | ### Changed 83 | - Update to rubocop 0.37 84 | 85 | ## [0.0.9] - 2015-12-10 86 | ### Fixed 87 | - fix dependencies 88 | 89 | ## [0.0.8] - 2015-12-10 90 | ### Added 91 | - Added a handler to allow overrides based on priority, now you can different 92 | alerts trigger different PagerDuty API endpoints. For example one can hit a high 93 | priority endpoint but warning can hit a lowpriority point. 94 | 95 | ### Changed 96 | - Use pagerduty gem instead of redphone, now also sends description and event details when resolving 97 | 98 | ## [0.0.7] - 2015-10-29 99 | ### Changed 100 | - handler-pagerduty: use json_config for incident key dedup_rules 101 | - adding override from client 102 | 103 | ## [0.0.6] - 2015-07-31 104 | ### Added 105 | - Added support for PagerDuty alert deduping. See the Readme file for an example. 106 | 107 | ### Changed 108 | - Updated rubocop to `0.32.1` 109 | 110 | ### Fixed 111 | - fixed rubocop errors 112 | 113 | ## [0.0.5] - 2015-07-14 114 | ### Changed 115 | - updated sensu-plugin gem to 1.2.0 116 | 117 | ## [0.0.4] - 2015-07-11 118 | ### Changed 119 | - updated documentation links in the README and CONTRIBUTING 120 | - set deps in gemspec and rakfile to be in alpha order 121 | - removed unused tasks from rakefile 122 | 123 | ### Fixed 124 | - fix binstubs to only be created for ruby files 125 | 126 | ## [0.0.3] - 2015-06-26 127 | ## Added 128 | - added option for json_config 129 | 130 | ## [0.0.2] - 2015-06-03 131 | ### Fixed 132 | - added binstubs 133 | 134 | ### Changed 135 | - removed cruft from /lib 136 | - added a new option for specifying the location of the json config file 137 | 138 | ## 0.0.1 - 2015-04-29 139 | ### Added 140 | - initial release 141 | 142 | [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/5.0.0...HEAD 143 | [5.0.0]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/4.1.0...5.0.0 144 | [4.1.0]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/4.0.0...4.1.0 145 | [4.0.0]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/3,1,0...4.0.0 146 | [3.1.0]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/3.0.1...3,1.0 147 | [3.0.1]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/3.0.0...3.0.1 148 | [3.0.0]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/2.2.0...3.0.0 149 | [2.2.0]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/2.1.0...2.2.0 150 | [2.1.0]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/2.0.0...2.1.0 151 | [2.0.0]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/1.0.0...2.0.0 152 | [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/0.0.9...1.0.0 153 | [0.0.9]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/0.0.8...0.0.9 154 | [0.0.8]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/0.0.7...0.0.8 155 | [0.0.7]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/0.0.6...0.0.7 156 | [0.0.6]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/0.0.5...0.0.6 157 | [0.0.5]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/0.0.4...0.0.5 158 | [0.0.4]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/0.0.3...0.0.4 159 | [0.0.3]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/0.0.2...0.0.3 160 | [0.0.2]: https://github.com/sensu-plugins/sensu-plugins-pagerduty/compare/0.0.1...0.0.2 161 | -------------------------------------------------------------------------------- /test/bin/handler-pagerduty_spec.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require_relative '../spec_helper.rb' 3 | require_relative '../../bin/handler-pagerduty.rb' 4 | 5 | # rubocop:disable Style/ClassVars 6 | class PagerdutyHandler 7 | at_exit do 8 | @@autorun = false 9 | end 10 | 11 | def settings 12 | @settings ||= JSON.parse(fixture('pagerduty_settings.json').read) 13 | end 14 | end 15 | 16 | describe 'Handlers' do 17 | before do 18 | @handler = PagerdutyHandler.new 19 | end 20 | 21 | describe '#incident_key' do 22 | it 'should return incident key with warning' do 23 | io_obj = fixture('no_override_warning.json') 24 | @handler.read_event(io_obj) 25 | incident_key = @handler.incident_key 26 | expect(incident_key).to eq('i-424242/frontend_http_check') 27 | end 28 | 29 | it 'should return incident key with critical' do 30 | io_obj = fixture('no_override_critical.json') 31 | @handler.read_event(io_obj) 32 | incident_key = @handler.incident_key 33 | expect(incident_key).to eq('i-424242/frontend_http_check') 34 | end 35 | 36 | it 'should return incident key with warning on resolve' do 37 | io_obj = fixture('recovery_no_override_warning.json') 38 | @handler.read_event(io_obj) 39 | incident_key = @handler.incident_key 40 | expect(incident_key).to eq('i-424242/frontend_http_check') 41 | end 42 | 43 | it 'should return incident key with critical on resolve' do 44 | io_obj = fixture('recovery_no_override_critical.json') 45 | @handler.read_event(io_obj) 46 | incident_key = @handler.incident_key 47 | expect(incident_key).to eq('i-424242/frontend_http_check') 48 | end 49 | end 50 | 51 | describe '#json_config' do 52 | it 'should return pagerduty' do 53 | expect(@handler.json_config).to eq('pagerduty') 54 | end 55 | 56 | it 'should return custom' do 57 | json_config = PagerdutyHandler.new('-j custom_key'.split).json_config 58 | expect(json_config).to eq('custom_key') 59 | end 60 | end 61 | 62 | describe '#api_key' do 63 | it 'should return base key' do 64 | io_obj = fixture('pd_no_override.json') 65 | @handler.read_event(io_obj) 66 | expect(@handler.api_key).to eq('BASE_KEY') 67 | end 68 | 69 | it 'should return check override' do 70 | io_obj = fixture('pd_check_override.json') 71 | @handler.read_event(io_obj) 72 | expect(@handler.api_key).to eq('CHECK_OVERRIDE') 73 | end 74 | 75 | it 'should return client override' do 76 | io_obj = fixture('pd_client_override.json') 77 | @handler.read_event(io_obj) 78 | expect(@handler.api_key).to eq('CLIENT_OVERRIDE') 79 | end 80 | end 81 | 82 | describe '#contexts' do 83 | it 'should return list as default' do 84 | io_obj = fixture('minimal_create.json') 85 | @handler.read_event(io_obj) 86 | expect(@handler.contexts).to eq([]) 87 | end 88 | 89 | it 'should return contexts hash from check' do 90 | io_obj = fixture('check_with_contexts.json') 91 | @handler.read_event(io_obj) 92 | expect(@handler.contexts).to eq( 93 | [ 94 | { 95 | 'type' => 'link', 96 | 'href' => 'http://example.com/' 97 | } 98 | ] 99 | ) 100 | end 101 | end 102 | 103 | describe '#handle' do 104 | it 'should create ticket with dynamic perfix' do 105 | stub_pd_client = double 106 | io_obj = fixture('create_dynamic_prefix.json') 107 | @handler.read_event(io_obj) 108 | allow(@handler).to receive(:event_summary).and_return('(i-424242) test_summary') 109 | allow(@handler).to receive(:json_config).and_return('pagerduty') 110 | allow(@handler).to receive(:incident_key).and_return('stub_incident_key') 111 | allow(@handler).to receive(:event_summary).and_return('test_summary') 112 | allow(@handler).to receive(:contexts).and_return( 113 | [ 114 | { 115 | 'type' => 'link', 116 | 'href' => 'http://example.com/' 117 | } 118 | ] 119 | ) 120 | expect(stub_pd_client).to receive(:trigger).with( 121 | '(i-424242) test_summary', 122 | incident_key: 'stub_incident_key', 123 | details: { 124 | 'action' => 'create', 125 | 'client' => { 'name' => 'i-424242' }, 126 | 'occurrences' => 1, 127 | 'check' => {} 128 | }, 129 | contexts: [ 130 | { 131 | 'type' => 'link', 132 | 'href' => 'http://example.com/' 133 | } 134 | ] 135 | ) 136 | @handler.handle(stub_pd_client) 137 | end 138 | 139 | it 'should create ticket' do 140 | stub_pd_client = double 141 | io_obj = fixture('minimal_create.json') 142 | @handler.read_event(io_obj) 143 | allow(@handler).to receive(:json_config).and_return('pagerduty') 144 | allow(@handler).to receive(:incident_key).and_return('stub_incident_key') 145 | allow(@handler).to receive(:event_summary).and_return('test_summary') 146 | allow(@handler).to receive(:contexts).and_return( 147 | [ 148 | { 149 | 'type' => 'link', 150 | 'href' => 'http://example.com/' 151 | } 152 | ] 153 | ) 154 | expect(stub_pd_client).to receive(:trigger).with( 155 | 'test_summary', 156 | incident_key: 'stub_incident_key', 157 | details: { 158 | 'action' => 'create', 159 | 'occurrences' => 1, 160 | 'check' => {}, 161 | 'client' => {} 162 | }, 163 | contexts: [ 164 | { 165 | 'type' => 'link', 166 | 'href' => 'http://example.com/' 167 | } 168 | ] 169 | ) 170 | @handler.handle(stub_pd_client) 171 | end 172 | 173 | it 'should resolve ticket' do 174 | stub_pd_client = double 175 | stub_incident = double 176 | io_obj = fixture('minimal_resolve.json') 177 | @handler.read_event(io_obj) 178 | allow(@handler).to receive(:json_config).and_return('pagerduty') 179 | allow(@handler).to receive(:incident_key).and_return('stub_incident_key') 180 | allow(@handler).to receive(:event_summary).and_return('test_summary') 181 | allow(stub_pd_client).to receive(:get_incident).and_return(stub_incident) 182 | expect(stub_pd_client).to receive(:get_incident).with('stub_incident_key') 183 | expect(stub_incident).to receive(:resolve).with( 184 | 'test_summary', 185 | 'action' => 'resolve', 186 | 'occurrences' => 1, 187 | 'check' => {}, 188 | 'client' => {} 189 | ) 190 | @handler.handle(stub_pd_client) 191 | end 192 | end 193 | end 194 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Sensu-Plugins-pagerduty 2 | 3 | [![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-pagerduty.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-pagerduty) 4 | [![Gem Version](https://badge.fury.io/rb/sensu-plugins-pagerduty.svg)](http://badge.fury.io/rb/sensu-plugins-pagerduty) 5 | [![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-pagerduty/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-pagerduty) 6 | [![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-pagerduty/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-pagerduty) 7 | [![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-pagerduty.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-pagerduty) 8 | [![Sensu Bonsai Asset](https://img.shields.io/badge/Bonsai-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/sensu-plugins/sensu-plugins-pagerduty) 9 | 10 | ## Sensu Asset 11 | The Sensu assets packaged from this repository are built against the Sensu Ruby runtime environment. When using these assets as part of a Sensu Go resource (check, mutator or handler), make sure you include the corresponding Sensu Ruby runtime asset in the list of assets needed by the resource. The current ruby-runtime assets can be found [here](https://bonsai.sensu.io/assets/sensu/sensu-ruby-runtime) in the [Bonsai Asset Index](bonsai.sensu.io). 12 | 13 | ## Functionality 14 | 15 | ## Files 16 | * bin/handler-pagerduty.rb 17 | * bin/mutator-pagerduty-priority-override.rb 18 | 19 | ## Usage of Handler 20 | 21 | PagerDuty supports dedup. Dedup is useful when you want to create a single alert (for a group of checks). Only one alert is sent out even if the checks fail at the same time. The following example groups check_service_`n` together for a single host. `dedup_rules` take in regular expressions as keys and re-write rules as values. `dedup_rules` entry is optional. 22 | 23 | ``` 24 | { 25 | "pagerduty": { 26 | "api_key": "12345", 27 | "team_name1": { 28 | "api_key": "23456" 29 | }, 30 | "team_name2": { 31 | "api_key": "34567" 32 | }, 33 | "dedup_rules": { 34 | "(.*)/check_service_(\\d+)": "\\1/check_service" 35 | } 36 | } 37 | } 38 | ``` 39 | 40 | In the Client hash you can define a `pager_team` key value pair. If the the client hash contains the `pager_team` key it will then no longer use the default `pagerduty.api_key` from the above hash but will look for the value given in the client. If the value given in the client is not found in the handler specified, then the default `pagerduty.api_key` will be used. The following client hash will alert using the team_name1 api key instead of the default api_key. This will allow different teams/hosts to alert different escalation paths. 41 | 42 | ``` 43 | { 44 | "client": { 45 | "name": "my.host.fqdn, 46 | "address": "8.8.8.8", 47 | "subscriptions": [ 48 | "production", 49 | "webserver", 50 | "mysql" 51 | ], 52 | "pager_team": "team_name1" 53 | } 54 | } 55 | ``` 56 | 57 | Please note, this sets the escalation path on the whole host. If you want more granular control on escalation paths please view the Mutator section below. 58 | 59 | In the Check hash you can define a `pagerduty_contexts` list to send contextual links and images with your events. This list should conform to the [PagerDuty documentation](https://developer.pagerduty.com/documentation/integration/events/trigger#contexts) about contexts. 60 | 61 | Another approach would be define this on a per check basis like so: 62 | ``` 63 | { 64 | "checks": { 65 | "cpu": { 66 | "command": "check-cpu.rb -w 90 -c 100", 67 | "subscribers": [ 68 | "base" 69 | ], 70 | "handlers": [ 71 | "pagerduty" 72 | ], 73 | "interval": 15, 74 | "pager_team": "team1", 75 | "notification": "CPU is running hot!", 76 | "occurrences": 8 77 | } 78 | } 79 | } 80 | ``` 81 | 82 | ## Usage of Priority Overide Mutator 83 | 84 | This mutator allows you to have fine grain control on PagerDuty escalation paths based on data within the client hash. The mutator will look in the following locations where `#{event_level}` is `warning` and `critical` (unknown, is replaced by critical), and `#{check_name}` is the name of the check. Items located lower in the list take precedence: 85 | 86 | ``` 87 | client['pager_team'] 88 | client['pd_override']['baseline'][#{event_level}] 89 | client['pd_override'][#{check_name}][#{event_level}] 90 | ``` 91 | 92 | For example if I have the following pager_duty escalations defined on my Sensu server: 93 | 94 | ``` 95 | { 96 | "pagerduty": { 97 | "api_key": "12345", 98 | "low_priority": { 99 | "api_key": "23456" 100 | }, 101 | "ops": { 102 | "api_key: "7890" 103 | } 104 | } 105 | } 106 | ``` 107 | 108 | And I also have the following client hash: 109 | 110 | ``` 111 | { 112 | "client": { 113 | "name": "my.host.fqdn", 114 | "address": "8.8.8.8", 115 | "subscriptions": [ 116 | "production", 117 | "webserver", 118 | "mysql" 119 | ], 120 | "pd_override": { 121 | "baseline" : { 122 | "warning": "low_priority" 123 | }, 124 | "check_disk": { 125 | "warning": "ops", 126 | "critical": "ops" 127 | } 128 | } 129 | } 130 | } 131 | 132 | ``` 133 | 134 | ## Usage of Proxy 135 | 136 | ``` 137 | { 138 | "pagerduty": { 139 | "api_key": "12345", 140 | "proxy_host": "my.proxy.fqdn", 141 | "proxy_port": "8080", 142 | "proxy_username": "", 143 | "proxy_password": "" 144 | } 145 | } 146 | ``` 147 | 148 | If a `critical` event is triggered from "my.host.fqdn" that is not named `check_disk` it will alert the default (with value api_key: 12345). If a `warning` event is triggered that is not `check_disk` it will alert the `low_proirity` escalation service. If any `check_disk` alert is triggerd it will the alert the `ops` escalation. 149 | 150 | 151 | ## Adding Dynamic Event Description Prefix 152 | 153 | You can add a custom field from the Sensu client config as a description prefix, like the host name, to add more context to the event description: 154 | 155 | ``` 156 | { 157 | "pagerduty": { 158 | "api_key": "12345", 159 | "dynamic_description_prefix_key" : "name", 160 | } 161 | } 162 | ``` 163 | 164 | ## Flapping Incidents 165 | By default handlers do not handle flapping incidents: [handler configuration documentation](https://sensuapp.org/docs/0.24/reference/handlers.html#handler-configuration) in order to change this you must set handle_flapping in your handler config like this: 166 | ```json 167 | { 168 | "pagerduty": { 169 | "api_key": "12345", 170 | "handle_flapping": true 171 | } 172 | } 173 | ``` 174 | 175 | ## Installation 176 | 177 | [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html) 178 | 179 | ## Notes 180 | -------------------------------------------------------------------------------- /test/bin/mutator-pagerduty-priority-override_spec.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require_relative '../spec_helper.rb' 3 | require_relative '../../bin/mutator-pagerduty-priority-override.rb' 4 | 5 | describe 'Mutators' do 6 | before do 7 | @script = File.expand_path('../../bin/mutator-pagerduty-priority-override.rb', File.dirname(__FILE__)) 8 | end 9 | 10 | it 'should pass event through -- critical' do 11 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 12 | io_obj = fixture('no_override_critical.json') 13 | 14 | raw_input = io_obj.read 15 | io_obj.rewind 16 | raw_output = mutator.execute(io_obj) 17 | 18 | event_input = JSON.parse(raw_input, symbolize_names: true) 19 | json_output = JSON.parse(raw_output, symbolize_names: true) 20 | 21 | expect(raw_output.strip).to eql(JSON.dump(event_input)) 22 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pager_team]) 23 | end 24 | 25 | it 'should pass event through -- warning' do 26 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 27 | io_obj = fixture('no_override_warning.json') 28 | 29 | raw_input = io_obj.read 30 | io_obj.rewind 31 | raw_output = mutator.execute(io_obj) 32 | 33 | event_input = JSON.parse(raw_input, symbolize_names: true) 34 | json_output = JSON.parse(raw_output, symbolize_names: true) 35 | 36 | expect(raw_output.strip).to eql(JSON.dump(event_input)) 37 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pager_team]) 38 | end 39 | 40 | it 'should override with baseline when status matches -- critical' do 41 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 42 | io_obj = fixture('baseline_override_critical_event.json') 43 | 44 | raw_input = io_obj.read 45 | io_obj.rewind 46 | raw_output = mutator.execute(io_obj) 47 | 48 | event_input = JSON.parse(raw_input, symbolize_names: true) 49 | json_output = JSON.parse(raw_output, symbolize_names: true) 50 | 51 | expect(raw_output.strip).not_to eql(JSON.dump(event_input)) 52 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pd_override][:baseline][:critical]) 53 | end 54 | 55 | it 'should override with baseline when status matches -- warning' do 56 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 57 | io_obj = fixture('baseline_override_warning_event.json') 58 | 59 | raw_input = io_obj.read 60 | io_obj.rewind 61 | raw_output = mutator.execute(io_obj) 62 | 63 | event_input = JSON.parse(raw_input, symbolize_names: true) 64 | json_output = JSON.parse(raw_output, symbolize_names: true) 65 | 66 | expect(raw_output.strip).not_to eql(JSON.dump(event_input)) 67 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pd_override][:baseline][:warning]) 68 | end 69 | 70 | it 'should override with check when status matches -- critical' do 71 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 72 | io_obj = fixture('check_override_critical_event.json') 73 | 74 | raw_input = io_obj.read 75 | io_obj.rewind 76 | raw_output = mutator.execute(io_obj) 77 | 78 | event_input = JSON.parse(raw_input, symbolize_names: true) 79 | json_output = JSON.parse(raw_output, symbolize_names: true) 80 | 81 | expect(raw_output.strip).not_to eql(JSON.dump(event_input)) 82 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pd_override][event_input[:check][:name].to_sym][:critical]) 83 | end 84 | 85 | it 'should override with check when status matches -- warning' do 86 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 87 | io_obj = fixture('check_override_warning_event.json') 88 | 89 | raw_input = io_obj.read 90 | io_obj.rewind 91 | raw_output = mutator.execute(io_obj) 92 | 93 | event_input = JSON.parse(raw_input, symbolize_names: true) 94 | json_output = JSON.parse(raw_output, symbolize_names: true) 95 | 96 | expect(raw_output.strip).not_to eql(JSON.dump(event_input)) 97 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pd_override][event_input[:check][:name].to_sym][:warning]) 98 | end 99 | 100 | it 'should use check override if baseline is also provided -- critical' do 101 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 102 | io_obj = fixture('check_and_baseline_override_critical_event.json') 103 | 104 | raw_input = io_obj.read 105 | io_obj.rewind 106 | raw_output = mutator.execute(io_obj) 107 | 108 | event_input = JSON.parse(raw_input, symbolize_names: true) 109 | json_output = JSON.parse(raw_output, symbolize_names: true) 110 | 111 | expect(raw_output.strip).not_to eql(JSON.dump(event_input)) 112 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pd_override][event_input[:check][:name].to_sym][:critical]) 113 | end 114 | 115 | it 'should use check override if baseline is also provided -- warning' do 116 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 117 | io_obj = fixture('check_and_baseline_override_warning_event.json') 118 | 119 | raw_input = io_obj.read 120 | io_obj.rewind 121 | raw_output = mutator.execute(io_obj) 122 | 123 | event_input = JSON.parse(raw_input, symbolize_names: true) 124 | json_output = JSON.parse(raw_output, symbolize_names: true) 125 | 126 | expect(raw_output.strip).not_to eql(JSON.dump(event_input)) 127 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pd_override][event_input[:check][:name].to_sym][:warning]) 128 | end 129 | 130 | it 'should use check on recovery if provided -- critical' do 131 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 132 | io_obj = fixture('recovery_check_critical_event.json') 133 | 134 | raw_input = io_obj.read 135 | io_obj.rewind 136 | raw_output = mutator.execute(io_obj) 137 | 138 | event_input = JSON.parse(raw_input, symbolize_names: true) 139 | json_output = JSON.parse(raw_output, symbolize_names: true) 140 | 141 | expect(raw_output.strip).not_to eql(JSON.dump(event_input)) 142 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pd_override][event_input[:check][:name].to_sym][:critical]) 143 | end 144 | 145 | it 'should use check on recovery if provided -- warning' do 146 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 147 | io_obj = fixture('recovery_check_warning_event.json') 148 | 149 | raw_input = io_obj.read 150 | io_obj.rewind 151 | raw_output = mutator.execute(io_obj) 152 | 153 | event_input = JSON.parse(raw_input, symbolize_names: true) 154 | json_output = JSON.parse(raw_output, symbolize_names: true) 155 | 156 | expect(raw_output.strip).not_to eql(JSON.dump(event_input)) 157 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pd_override][event_input[:check][:name].to_sym][:warning]) 158 | end 159 | 160 | it 'should use baseline on recovery if provided and check is not -- critical' do 161 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 162 | io_obj = fixture('recovery_baseline_critical_event.json') 163 | 164 | raw_input = io_obj.read 165 | io_obj.rewind 166 | raw_output = mutator.execute(io_obj) 167 | 168 | event_input = JSON.parse(raw_input, symbolize_names: true) 169 | json_output = JSON.parse(raw_output, symbolize_names: true) 170 | 171 | expect(raw_output.strip).not_to eql(JSON.dump(event_input)) 172 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pd_override][:baseline][:critical]) 173 | end 174 | 175 | it 'should use baseline on recovery if provided and check is not -- warning' do 176 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 177 | io_obj = fixture('recovery_baseline_warning_event.json') 178 | 179 | raw_input = io_obj.read 180 | io_obj.rewind 181 | raw_output = mutator.execute(io_obj) 182 | 183 | event_input = JSON.parse(raw_input, symbolize_names: true) 184 | json_output = JSON.parse(raw_output, symbolize_names: true) 185 | 186 | expect(raw_output.strip).not_to eql(JSON.dump(event_input)) 187 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pd_override][:baseline][:warning]) 188 | end 189 | 190 | it 'pass event recovery through when neither baseline nor check is used -- critical' do 191 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 192 | io_obj = fixture('recovery_no_override_critical.json') 193 | 194 | raw_input = io_obj.read 195 | io_obj.rewind 196 | raw_output = mutator.execute(io_obj) 197 | 198 | event_input = JSON.parse(raw_input, symbolize_names: true) 199 | json_output = JSON.parse(raw_output, symbolize_names: true) 200 | 201 | expect(raw_output.strip).to eql(JSON.dump(event_input)) 202 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pager_team]) 203 | end 204 | 205 | it 'pass recovery event through when neither baseline nor check is used -- warning' do 206 | mutator = Sensu::Mutator::PagerDuty::PriorityOverride.new 207 | io_obj = fixture('recovery_no_override_warning.json') 208 | 209 | raw_input = io_obj.read 210 | io_obj.rewind 211 | raw_output = mutator.execute(io_obj) 212 | 213 | event_input = JSON.parse(raw_input, symbolize_names: true) 214 | json_output = JSON.parse(raw_output, symbolize_names: true) 215 | 216 | expect(raw_output.strip).to eql(JSON.dump(event_input)) 217 | expect(json_output[:client][:pager_team]).to eql(event_input[:client][:pager_team]) 218 | end 219 | end 220 | --------------------------------------------------------------------------------