/** * {@inheritdoc} */ public function render(ResultCollection $resultCollection) { $table = new Table(); $table->setHeaderRow(['Global Status', 'Status Code', 'Name', 'Response Time', 'Http Error Log', 'Validator Error Log']); $statusGuesser = new StatusGuesser(); foreach ($resultCollection as $result) { $color = $statusGuesser->isFailed($result) ? 'red' : 'green'; $table->addRow([$statusGuesser->isFailed($result) ? 'FAIL' : 'OK', sprintf('<bg=%s>%s</>', $color, $result->getStatusCode()), $result->getUrl()->getName(), $result->getReponseTime(), sprintf('<bg=red>%s</>', $result->getHandlerError()), sprintf('<bg=red>%s</>', $result->getValidatorError())]); } $table->render($this->io); }
/** * {@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; } }
/** * {@inheritdoc} */ public function render(ResultCollection $resultCollection) { $format = '[%s][%s] %s - %s%s%s'; $errorFormat = ' - <bg=red>%s</>'; $statusGuesser = new StatusGuesser(); foreach ($resultCollection as $result) { $errorLog = $result->getHandlerError(); $validatorErrorLog = $result->getValidatorError(); $this->io->write(sprintf($format, $statusGuesser->isFailed($result) ? 'FAIL' : 'OK', $result->getStatusCode(), $result->getUrl()->getName(), $result->getReponseTime(), null !== $errorLog ? sprintf($errorFormat, $errorLog) : '', null !== $validatorErrorLog ? sprintf($errorFormat, $validatorErrorLog) : '') . "\n"); } }
/** * {@inheritdoc} */ public function render(ResultCollection $resultCollection) { $stream = fopen('php://temp', 'w'); fputcsv($stream, ['Global Status', 'Status Code', 'Name', 'Reponse Time', 'Http Error Log', 'Validator Error Log']); $statusGuesser = new StatusGuesser(); foreach ($resultCollection as $result) { fputcsv($stream, [$statusGuesser->isFailed($result) ? 'FAIL' : 'OK', $result->getStatusCode(), $result->getUrl()->getName(), $result->getReponseTime(), $result->getHandlerError(), $result->getValidatorError()]); } rewind($stream); $this->io->write(stream_get_contents($stream)); fclose($stream); }
/** * testIsFailed. */ public function testIsFailed() { $statusGuesser = new StatusGuesser(); $this->assertTrue($statusGuesser->isFailed($this->createResult())); }