<commit_before><?php

namespace Spotlab\Sentinel\Command;

use Spotlab\Sentinel\Tools\Guardian;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Class Backup
 * @package Spotlab\Sentinel\Command
 */
class Ping extends Command
{
    /**
     * Set us up the command!
     */
    public function configure()
    {
        $this->setName('ping')
             ->setDescription('Ping all websites');

        $this->addArgument(
            'config',
            InputArgument::REQUIRED,
            'The path to the config file (.yml)'
        );
    }

    /**
     * Parses the clover XML file and spits out coverage results to the console.
     *
     * @param  InputInterface  $input
     * @param  OutputInterface $output
     * @return int
     */
    public function execute(InputInterface $input, OutputInterface $output)
    {
        // First step : Analysing config
        $config_path = $input->getArgument('config');
        $guardian = new Guardian($config_path);
        $output->writeln(sprintf('Analysing config file : <info>%s</info>', $config_path));
        $output->write("\n");

        // Actions for every projects in config
        $requests = $guardian->getRequests();
        $data = $guardian->getData();

        // Register time
        $now = time();

        foreach ($requests as $line => $config) {

            $output->writeln(sprintf('> Start : <info>%s</info>', $line));
            $output->writeln('------------------------------');

            // Création d'un gestionnaire curl
            $ch = curl_init();

            // Configuration de l'URL et d'autres options
            curl_setopt($ch, CURLOPT_URL, $config['url']);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 20);
            if(!empty($config['method']) && $config['method'] == 'POST') curl_setopt($ch, CURLOPT_POST, true);
            if(!empty($config['header'])) curl_setopt($ch, CURLOPT_HTTPHEADER, $config['header']);
            if(!empty($config['content'])) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($config['content']));

            // // Exécution
            curl_exec($ch);

            // Vérification si une erreur est survenue
            $error = '';
            if(!curl_errno($ch)) {
                $total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
                $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                $output->write($total_time . 's (' . $http_code . ')');

                // Failed if 404, 500, ...
                if ($http_code >= 400) {
                    $total_time = null;
                    $error = $http_code;
                }
            } else {
                $error = curl_error($ch);
                $total_time = null;
                $http_code = 999;
                $output->write($error);
            }

            // Add Data
            $data[$line][] = array(
                'date' => $now,
                'total_time' => $total_time,<commit_msg>Timeout 30s<commit_after><?php

namespace Spotlab\Sentinel\Command;

use Spotlab\Sentinel\Tools\Guardian;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Class Backup
 * @package Spotlab\Sentinel\Command
 */
class Ping extends Command
{
    /**
     * Set us up the command!
     */
    public function configure()
    {
        $this->setName('ping')
             ->setDescription('Ping all websites');

        $this->addArgument(
            'config',
            InputArgument::REQUIRED,
            'The path to the config file (.yml)'
        );
    }

    /**
     * Parses the clover XML file and spits out coverage results to the console.
     *
     * @param  InputInterface  $input
     * @param  OutputInterface $output
     * @return int
     */
    public function execute(InputInterface $input, OutputInterface $output)
    {
        // First step : Analysing config
        $config_path = $input->getArgument('config');
        $guardian = new Guardian($config_path);
        $output->writeln(sprintf('Analysing config file : <info>%s</info>', $config_path));
        $output->write("\n");

        // Actions for every projects in config
        $requests = $guardian->getRequests();
        $data = $guardian->getData();

        // Register time
        $now = time();

        foreach ($requests as $line => $config) {

            $output->writeln(sprintf('> Start : <info>%s</info>', $line));
            $output->writeln('------------------------------');

            // Création d'un gestionnaire curl
            $ch = curl_init();

            // Configuration de l'URL et d'autres options
            curl_setopt($ch, CURLOPT_URL, $config['url']);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            if(!empty($config['method']) && $config['method'] == 'POST') curl_setopt($ch, CURLOPT_POST, true);
            if(!empty($config['header'])) curl_setopt($ch, CURLOPT_HTTPHEADER, $config['header']);
            if(!empty($config['content'])) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($config['content']));

            // // Exécution
            curl_exec($ch);

            // Vérification si une erreur est survenue
            $error = '';
            if(!curl_errno($ch)) {
                $total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
                $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                $output->write($total_time . 's (' . $http_code . ')');

                // Failed if 404, 500, ...
                if ($http_code >= 400) {
                    $total_time = null;
                    $error = $http_code;
                }
            } else {
                $error = curl_error($ch);
                $total_time = null;
                $http_code = 999;
                $output->write($error);
            }

            // Add Data
            $data[$line][] = array(
                'date' => $now,
                'total_time' => $total_time,
{'fraction_non_alphanumeric': 0.14664634146341463, 'fraction_numerical': 0.004573170731707317, 'mean_word_length': 1.9527452745274527, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4212888', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1824, 'n_words': 392}