Exemple #1
0
function probes()
{
    $array = array();
    $unix = new unix();
    $gluster = $unix->find_program("gluster");
    $q = new mysql();
    $results = $q->QUERY_SQL("SELECT client_ip,hostname FROM glusters_clients WHERE LENGTH(uuid)=0 AND NotifToDelete=0", "artica_backup");
    if ($GLOBALS["VERBOSE"]) {
        echo "SELECT client_ip,hostname FROM glusters_clients WHERE LENGTH(uuid)=0 = " . mysql_num_rows($results) . " rows\n";
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Probe {$ligne["client_ip"]}\n";
        }
        if ($ligne["client_ip"] != null) {
            $results2 = array();
            exec("{$gluster} peer probe {$ligne["client_ip"]} 2>&1", $results2);
            if (preg_match("#is already part of another cluster#", $results2[0])) {
                $glusterClass = new gluster_client($ligne["client_ip"]);
                $glusterClass->state = "WARN: is already part of another cluster";
                $glusterClass->edit_client();
            }
            system_admin_events("Probe {$ligne["client_ip"]}:\n" . @implode("\n", $results2), __FUNCTION__, __FILE__, __LINE__, "clusters");
            continue;
        }
    }
    $q = new mysql();
    $results = $q->QUERY_SQL("SELECT client_ip,hostname FROM glusters_clients WHERE NotifToDelete=1", "artica_backup");
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "detach {$ligne["client_ip"]}/{$ligne["hostname"]}\n";
        }
        if ($ligne["client_ip"] != null) {
            $results2 = array();
            exec("{$gluster} peer detach {$ligne["client_ip"]} 2>&1", $results2);
            if (preg_match("#is not part of cluster#i", $results2[0])) {
                $glusterClass = new gluster_client($ligne["client_ip"]);
                $glusterClass->remove();
            }
            if (preg_match("#successful#i", $results2[0])) {
                $glusterClass = new gluster_client($ligne["client_ip"]);
                $glusterClass->remove();
            }
            if (preg_match("#exist in cluster#", $results2[0])) {
                $glusterClass = new gluster_client($ligne["client_ip"]);
                $glusterClass->state = "WARN: {$results2[0]}";
                $glusterClass->edit_client();
                $NOSTATUS[$ligne["client_ip"]] = true;
                continue;
            }
            if (preg_match("#is probably down#", $results2[0])) {
                $glusterClass = new gluster_client($ligne["client_ip"]);
                $glusterClass->state = "WARN: {$results2[0]}";
                $glusterClass->edit_client();
                $NOSTATUS[$ligne["client_ip"]] = true;
                continue;
            }
            system_admin_events("detach {$ligne["client_ip"]}:\n" . @implode("\n", $results2), __FUNCTION__, __FILE__, __LINE__, "clusters");
            continue;
        }
    }
    exec("{$gluster} peer status 2>&1", $results);
    while (list($index, $line) = each($results)) {
        if (preg_match("#Hostname:\\s+(.+)#", $line, $re)) {
            $hostname = $re[1];
            if (!preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $hostname)) {
                $array[$hostname]["client_ip"] = gethostbyname($hostname);
            }
            continue;
        }
        if (preg_match("#Uuid:\\s+(.+)#i", $line, $re)) {
            $array[$hostname]["UUID"] = $re[1];
            continue;
        }
        if (preg_match("#State:\\s+(.+)#i", $line, $re)) {
            $array[$hostname]["STATE"] = $re[1];
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "peer status: {$line} -> SKIP\n";
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "peer status: " . count($array) . " items\n";
    }
    while (list($hostname, $line) = each($array)) {
        $hostnameText = null;
        if (preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $hostname)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$hostname} -> is an ip -> resolve it\n";
            }
            $line["client_ip"] = $hostname;
            $hostnameText = gethostbyaddr($hostname);
        }
        if (isset($NOSTATUS[$line["client_ip"]])) {
            continue;
        }
        $gluster = new gluster_client($hostname);
        if ($gluster->client_ip == null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$hostname} -> ADD -> {$line["STATE"]}\n";
            }
            if (isset($line["client_ip"])) {
                $gluster->client_ip = $line["client_ip"];
            }
            $gluster->state = $line["STATE"];
            $gluster->uuid = $line["UUID"];
            if ($hostnameText != null) {
                $gluster->hostname = $hostnameText;
            }
            $gluster->add_client();
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$hostname} -> EDIT -> {$line["STATE"]} - {$hostnameText}\n";
        }
        $gluster->state = $line["STATE"];
        $gluster->uuid = $line["UUID"];
        $gluster->edit_client();
    }
}