Example #1
0
 /**
  * handle.
  *
  * @param Args $args
  * @param IO   $io
  *
  * @return int
  */
 public function handle(Args $args, IO $io)
 {
     $configFileExist = true;
     $overwrite = is_string($args->getOption('force'));
     try {
         $this->configurationLoader->setRootDirectory($args->getOption('config'));
         $configuration = $this->configurationLoader->loadConfiguration();
     } catch (ConfigurationLoadingException $e) {
         $configFileExist = false;
     }
     if (!$configFileExist || $overwrite) {
         $configuration = ['urls' => ['google' => ['url' => 'https://www.google.fr', 'method' => 'GET', 'headers' => [], 'timeout' => 1, 'validator' => [], 'status_code' => 200, 'metric_uuid' => null, 'service_uuid' => null]], 'hogosha_portal' => ['username' => '', 'password' => '', 'base_uri' => 'http://localhost:8000/api/', 'metric_update' => false, 'incident_update' => false, 'default_failed_incident_message' => 'An error as occured, we are investigating %service_name%', 'default_resolved_incident_message' => 'The service %service_name% is back to normal']];
         // Dump configuration
         $content = $this->configurationDumper->dumpConfiguration($configuration);
         $this->filesystem->dumpFile($this->configurationLoader->getConfigurationFilepath(), $content);
         $io->writeLine('<info>Creating monitor file</info>');
     } else {
         $io->writeLine(sprintf('<info>You already have a configuration file in</info> "%s"', $this->configurationLoader->getConfigurationFilepath()));
     }
 }
Example #2
0
 /**
  * handle.
  *
  * @param Args $args
  * @param IO   $io
  *
  * @return int
  */
 public function handle(Args $args, IO $io)
 {
     $this->configurationLoader->setRootDirectory($args->getOption('config'));
     $config = $this->configurationLoader->loadConfiguration();
     try {
         $urlProvider = new UrlProvider($config);
         $runner = new Runner($urlProvider, GuzzleClient::createClient($io));
         $renderer = RendererFactory::create($args->getOption('format'), $io);
         $results = $runner->run();
         $renderer->render($results);
         if (isset($config['hogosha_portal']['metric_update']) || isset($config['hogosha_portal']['incident_update'])) {
             $pusher = new PusherManager($config, $io);
             $pusher->push($results);
         }
     } catch (BadResponseException $e) {
         $io->writeLine(sprintf('<error>Exception:</error> "%s"', $e->getMessage()));
     } catch (ConfigurationLoadingException $e) {
         $io->writeLine(sprintf('<info>There is no configuration file in</info> "%s"', $this->configurationLoader->getRootDirectory()));
     }
 }