<?php
/* 
 * Scanne les clients existants et appelle à distance le monitoring
 */

require 'monitoring.class.php';

define("PATH_CONFIG", './config.ini');

//Gestion des paramètres en cas d'appel CLI
if (count($_GET) == 0 && $_SERVER['argc'] > 1) {
    $_GET['client'] = $_SERVER['argv'][1];
}

$tabClientsCli = array();
if (isset($_GET['client'])) $tabClientsCli = explode(",", $_GET['client']);

$monitoring = new monitoringWS(PATH_CONFIG);
$configuration = $monitoring->tabConfig;

if ($configuration['server']['active'] == 'T') {
    if (!file_exists($configuration['server']['path'].'config/clients.ini')) exit('Fichier de configuration '.$configuration['server']['path'].'config/clients.ini'.' inexistant');
    $tabClients = $monitoring->readConfig($configuration['server']['path'].'config/clients.ini');
    if (!empty($tabClients)) {
        foreach ($tabClients as $idclient => $details) {
            if (empty($tabClientsCli) || in_array($idclient, $tabClientsCli)) {
                $ret = $monitoring->remote_file_exists('http://'.$details['ip_agent'].'/webservices/monitoring/monitoring.php');
                if ($ret && $ret == 200) echo '['.$idclient.'] '.file_get_contents('http://'.$details['ip_agent'].'/webservices/monitoring/monitoring.php?client='.$idclient).'<br />';
                else echo '['.$idclient.'] Monitoring non disponible<br />';
            }
        }
    }
}

?>
