bin/check-service-consul.rb in sensu-plugins-consul-1.0.0 vs bin/check-service-consul.rb in sensu-plugins-consul-1.1.0

- old
+ new

@@ -49,10 +49,15 @@ option :all, description: 'get all services in a non-passing status', short: '-a', long: '--all' + option :fail_if_not_found, + description: 'fail if no service is found', + short: '-f', + long: '--fail-if-not-found' + # Get the check data for the service from consul # def acquire_service_data if config[:all] Diplomat::Health.state('any') @@ -87,10 +92,21 @@ 'service' => d['ServiceName'], 'service_id' => d['ServiceID'], 'notes' => d['Notes'] } if d['Status'] == 'failing' end - unknown 'Could not find service - are there checks defined?' if failing.empty? && passing.empty? + + if failing.empty? && passing.empty? + msg = 'Could not find checks for any services' + if config[:service] + msg = "Could not find checks for service #{config[:service]}" + end + if config[:fail_if_not_found] + critical msg + else + unknown msg + end + end critical failing unless failing.empty? ok passing unless passing.empty? end end