diff --git a/CHANGELOG.md b/CHANGELOG.md index e5a910d..ef0902a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md) ## [Unreleased] +- Added possibility to specify different priorities per status (@passing) ## [5.0.0] - 2019-03-05 ### Breaking Changes diff --git a/README.md b/README.md index 4e70a07..6675943 100644 --- a/README.md +++ b/README.md @@ -208,3 +208,17 @@ The list of valid values, per [OpsGenie alert docs](https://docs.opsgenie.com/do * P5 Any value other than these will be ignored. + +You can as well configure different priorities per status: +``` +{ + "checks": { + "check_mysql_access": { + "opsgenie": { + "priority": { + "critical": "P1", + "warning": "P2", + "unknown": "P5" + } + +``` diff --git a/bin/handler-opsgenie.rb b/bin/handler-opsgenie.rb index 7984026..fcca758 100755 --- a/bin/handler-opsgenie.rb +++ b/bin/handler-opsgenie.rb @@ -132,8 +132,17 @@ def create_alert end def event_priority - return DEFAULT_PRIORITY unless json_config['priority'] - priority = json_config['priority'] + if event_status == 1 && json_config['priority']['warning'] + priority = json_config['priority']['warning'] + elsif event_status == 2 && json_config['priority']['critical'] + priority = json_config['priority']['critical'] + elsif event_status >= 3 && json_config['priority']['unknown'] + priority = json_config['priority']['unknown'] + elsif json_config['priority'] + priority = json_config['priority'] + else + return DEFAULT_PRIORITY + end canonical_priority = priority.upcase unless PRIORITIES.include? canonical_priority