示例#1
0
 /**
  * {@inheritdoc}
  */
 public function push(Result $result)
 {
     $statusGuesser = new StatusGuesser();
     $resourceFactory = new ResourceFactory($this->client);
     $incidentResource = $resourceFactory->get('incident');
     $serviceResource = $resourceFactory->get('service');
     $service = $serviceResource->getService($result->getUrl()->getServiceUuid());
     $alreadyInFailure = false;
     if ($service['status'] != StatusGuesser::RESOLVED) {
         $alreadyInFailure = true;
     }
     try {
         // If the service is not already in failure,
         // we check if there is a failure.
         if (false === $alreadyInFailure && $statusGuesser->isFailed($result)) {
             $incidentResource->createIncident(['name' => str_replace('%service_name%', $service['name'], $this->getDefaultFailedIncidentMessage()), 'service' => $result->getUrl()->getServiceUuid(), 'status' => StatusGuesser::IDENTIFIED, 'error_log' => sprintf('%s %s', $result->getHandlerError(), $result->getValidatorError())]);
         }
         // If the service is already in failture,
         // we check if it's back to normal and create a incident resolver
         if ($alreadyInFailure && $statusGuesser->isOk($result)) {
             $incidentResource->createIncident(['name' => str_replace('%service_name%', $service['name'], $this->getDefaultResolvedIncidentMessage()), 'service' => $result->getUrl()->getServiceUuid(), 'status' => StatusGuesser::RESOLVED]);
         }
     } catch (BadResponseException $e) {
         throw $e;
     }
 }
示例#2
0
 /**
  * isOk.
  *
  * @param Result $result
  *
  * @return bool Return true is the condition is true
  */
 public function isOk(Result $result)
 {
     //The validator is used, so we can apply the rule
     if (null !== $result->getValidatorResult()) {
         return $result->getUrl()->getExpectedStatus() == $result->getStatusCode() && $result->getValidatorResult();
     }
     return $result->getUrl()->getExpectedStatus() == $result->getStatusCode();
 }