protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->setConfiguraton($input); $client = new \GuzzleHttp\Client(['defaults' => ['allow_redirects' => false, 'timeout' => 5, 'connect_timeout' => 5]]); /** @var Instance $instance */ foreach ($config->getInstances() as $instance) { $requests[] = $client->createRequest('HEAD', $instance->getUrl()); } $options = []; Pool::send($client, $requests, ['complete' => function (CompleteEvent $event) { }, 'error' => function (ErrorEvent $event) use($config) { $instance = $config->findInstanceByUrl($event->getRequest()->getUrl()); if ($instance == null) { throw new \RuntimeException('Instance not found'); } if (!$event->getException()->hasResponse()) { $raven = new \Raven_Client($instance->getSentryDsn()); $event_id = $raven->getIdent($raven->captureMessage(sprintf('The website %s with url -> %s is down or has a problem', $instance->getName(), $event->getRequest()->getUrl()), [], \Raven_Client::FATAL)); if ($raven->getLastError() !== null) { printf('There was an error sending the event to Sentry: %s', $raven->getLastError()); } $error_handler = new \Raven_ErrorHandler($raven); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); $error_handler->registerShutdownFunction(); } }]); }
/** * Return if configuration is valid * * @return array Array of errors. Empty array if ok. */ public function checkConfiguration() { global $conf; $errors = array(); $dsn = $conf->global->SYSLOG_SENTRY_DSN; try { $client = new Raven_Client($dsn, array('curl_method' => 'sync')); } catch (InvalidArgumentException $ex) { $errors[] = "ERROR: There was an error parsing your DSN:\n " . $ex->getMessage(); } if (!$errors) { // Send test event and check for errors $client->captureMessage('TEST: Sentry syslog configuration check', null, Raven_Client::DEBUG); $last_error = $client->getLastError(); if ($last_error) { $errors[] = $last_error; } } if (!$errors) { // Install handlers $error_handler = new Raven_ErrorHandler($client); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); $error_handler->registerShutdownFunction(); } return $errors; }
/** * Returns the request response from sentry if and only if the last message * was not sent successfully. * * @return mixed Last error */ public function getLastError() { return $this->_client->getLastError(); }