isDBSlaveActive() static public method

Indicates is the DB replicate is active or not
static public isDBSlaveActive ( ) : true
return true if active / false if not active
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     switch ($item->getType()) {
         case 'Preference':
             return __('Personalization');
         case 'User':
             if (User::canUpdate() && $item->currentUserHaveMoreRightThan($item->getID())) {
                 return __('Settings');
             }
             break;
         case __CLASS__:
             $tabs[1] = __('General setup');
             // Display
             $tabs[2] = __('Default values');
             // Prefs
             $tabs[3] = __('Assets');
             $tabs[4] = __('Assistance');
             if (Config::canUpdate()) {
                 $tabs[5] = __('System');
             }
             if (DBConnection::isDBSlaveActive() && Config::canUpdate()) {
                 $tabs[6] = _n('Mysql replica', 'Mysql replicas', Session::getPluralNumber());
                 // Slave
             }
             return $tabs;
     }
     return '';
 }
Ejemplo n.º 2
0
 /**
  * This method return GLPI status (same as status.php)
  *
  * @param $params    array of option : ignored
  * @param $protocol        the communication protocol used
  *
  * @return an response ready to be encode
  **/
 static function methodStatus($params, $protocol)
 {
     global $DB;
     if (isset($params['help'])) {
         return array('help' => 'bool,optional');
     }
     $resp = array();
     $ok_master = true;
     $ok_slave = true;
     $ok = true;
     // Check slave server connection
     if (DBConnection::isDBSlaveActive()) {
         $DBslave = DBConnection::getDBSlaveConf();
         if (is_array($DBslave->dbhost)) {
             $hosts = $DBslave->dbhost;
         } else {
             $hosts = array($DBslave->dbhost);
         }
         foreach ($hosts as $num => $name) {
             $diff = DBConnection::getReplicateDelay($num);
             if ($diff > 1000000000) {
                 $resp['slavedb_' . $num] = "offline";
                 $ok_slave = false;
             } else {
                 if ($diff) {
                     $resp['slavedb_' . $num] = $diff;
                     if ($diff > HOUR_TIMESTAMP) {
                         $ok_slave = false;
                     }
                 } else {
                     $resp['slavedb_' . $num] = "ok";
                 }
             }
         }
     } else {
         $resp['slavedb'] = "not configured";
     }
     // Check main server connection
     if (DBConnection::establishDBConnection(false, true, false)) {
         $resp['maindb'] = "ok";
     } else {
         $resp['slavedb'] = "offline";
         $ok_master = false;
     }
     // Slave and master ok;
     $ok = $ok_slave && $ok_master;
     // Check session dir (usefull when NFS mounted))
     if (is_dir(GLPI_SESSION_DIR) && is_writable(GLPI_SESSION_DIR)) {
         $resp['sessiondir'] = "ok";
     } else {
         $resp['sessiondir'] = "not writable";
         $ok = false;
     }
     // Reestablished DB connection
     if (($ok_master || $ok_slave) && DBConnection::establishDBConnection(false, false, false)) {
         // Check Auth connections
         $auth = new Auth();
         $auth->getAuthMethods();
         $ldap_methods = $auth->authtypes["ldap"];
         if (count($ldap_methods)) {
             foreach ($ldap_methods as $method) {
                 if ($method['is_active']) {
                     if (AuthLdap::tryToConnectToServer($method, $method["rootdn"], Toolbox::decrypt($method["rootdn_passwd"], GLPIKEY))) {
                         $resp['LDAP_' . $method['name']] = "ok";
                     } else {
                         $resp['LDAP_' . $method['name']] = "offline";
                         $ok = false;
                     }
                 }
             }
         }
     }
     if ($ok) {
         $resp['glpi'] = "ok";
     } else {
         $resp['glpi'] = "error";
     }
     return $resp;
 }
/** @file
* @brief
*/
define('DO_NOT_CHECK_HTTP_REFERER', 1);
include './inc/includes.php';
// Force in normal mode
$_SESSION['glpi_use_mode'] = Session::NORMAL_MODE;
// Need to be used using :
// check_http -H servername -u /glpi/status.php -s GLPI_OK
// Plain text content
header('Content-type: text/plain');
$ok_master = true;
$ok_slave = true;
$ok = true;
// Check slave server connection
if (DBConnection::isDBSlaveActive()) {
    $DBslave = DBConnection::getDBSlaveConf();
    if (is_array($DBslave->dbhost)) {
        $hosts = $DBslave->dbhost;
    } else {
        $hosts = array($DBslave->dbhost);
    }
    foreach ($hosts as $num => $name) {
        $diff = DBConnection::getReplicateDelay($num);
        if (abs($diff) > 1000000000) {
            echo "GLPI_DBSLAVE_{$num}_OFFLINE\n";
            $ok_slave = false;
        } else {
            if (abs($diff) > HOUR_TIMESTAMP) {
                echo "GLPI_DBSLAVE_{$num}_PROBLEM\n";
                $ok_slave = false;
Ejemplo n.º 4
0
 /**
  * Display a HTML report about systeme information / configuration
  *
  **/
 function showSystemInformations()
 {
     global $DB, $LANG, $CFG_GLPI;
     echo "<div class='center' id='tabsbody'>";
     echo "<form name='form' action=\"" . getItemTypeFormURL(__CLASS__) . "\" method='post'>";
     echo "<input type='hidden' name='id' value='" . $CFG_GLPI["id"] . "'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='4'>" . $LANG['setup'][70] . "</th></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . $LANG['setup'][102] . " &nbsp;:</td><td>";
     $values[1] = $LANG['setup'][103];
     $values[2] = $LANG['setup'][104];
     $values[3] = $LANG['setup'][105];
     $values[4] = $LANG['setup'][106];
     $values[5] = $LANG['setup'][107];
     Dropdown::showFromArray('event_loglevel', $values, array('value' => $CFG_GLPI["event_loglevel"]));
     echo "</td><td>" . $LANG['setup'][101] . "&nbsp;:</td><td>";
     Dropdown::showInteger('cron_limit', $CFG_GLPI["cron_limit"], 1, 30);
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td> " . $LANG['setup'][185] . "&nbsp;:</td><td>";
     Dropdown::showYesNo("use_log_in_files", $CFG_GLPI["use_log_in_files"]);
     echo "</td><td> " . $LANG['setup'][801] . "&nbsp;:</td><td>";
     $active = DBConnection::isDBSlaveActive();
     Dropdown::showYesNo("_dbslave_status", $active);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='4' class='center b'>" . $LANG['setup'][306] . ' - ' . $LANG['setup'][400] . "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . $LANG['common'][52] . "&nbsp;:</td>";
     echo "<td><input type='text' name='proxy_name' value='" . $CFG_GLPI["proxy_name"] . "'></td>";
     echo "<td>" . $LANG['setup'][175] . "&nbsp;:</td>";
     echo "<td><input type='text' name='proxy_port' value='" . $CFG_GLPI["proxy_port"] . "'></td>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . $LANG['login'][6] . "&nbsp;:</td>";
     echo "<td><input type='text' name='proxy_user' value='" . $CFG_GLPI["proxy_user"] . "'></td>";
     echo "<td>" . $LANG['login'][7] . "&nbsp;:</td>";
     echo "<td><input type='password' name='proxy_passwd' value='' autocomplete='off'></td>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td colspan='4' class='center'>";
     echo "<input type='submit' name='update' class='submit' value=\"" . $LANG['buttons'][2] . "\"></td>";
     echo "</tr>";
     echo "</table>";
     echo "</form>";
     $width = 128;
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th>" . $LANG['setup'][721] . "</th></tr>";
     echo "<tr class='tab_bg_1'><td><pre>[code]\n&nbsp;\n";
     $oldlang = $_SESSION['glpilanguage'];
     loadLanguage('en_GB');
     echo "GLPI " . $CFG_GLPI['version'] . " (" . $CFG_GLPI['root_doc'] . " => " . dirname(dirname($_SERVER["SCRIPT_FILENAME"])) . ")\n";
     echo "\n</pre></td></tr>";
     echo "<tr><th>" . $LANG['common'][52] . "</th></tr>\n";
     echo "<tr class='tab_bg_1'><td><pre>\n&nbsp;\n";
     echo wordwrap($LANG['setup'][5] . "&nbsp;: " . php_uname() . "\n", $width, "\n\t");
     $exts = get_loaded_extensions();
     sort($exts);
     echo wordwrap("PHP " . phpversion() . " (" . implode(', ', $exts) . ")\n", $width, "\n\t");
     $msg = $LANG['common'][12] . ": ";
     foreach (array('memory_limit', 'max_execution_time', 'safe_mode', 'session.save_handler', 'post_max_size', 'upload_max_filesize') as $key) {
         $msg .= $key . '="' . ini_get($key) . '" ';
     }
     echo wordwrap($msg . "\n", $width, "\n\t");
     $msg = $LANG['Menu'][4] . ": ";
     if (isset($_SERVER["SERVER_SOFTWARE"])) {
         $msg .= $_SERVER["SERVER_SOFTWARE"];
     }
     if (isset($_SERVER["SERVER_SIGNATURE"])) {
         $msg .= ' (' . html_clean($_SERVER["SERVER_SIGNATURE"]) . ')';
     }
     echo wordwrap($msg . "\n", $width, "\n\t");
     if (isset($_SERVER["HTTP_USER_AGENT"])) {
         echo "\t" . $_SERVER["HTTP_USER_AGENT"] . "\n";
     }
     $version = "???";
     foreach ($DB->request('SELECT VERSION() as ver') as $data) {
         $version = $data['ver'];
     }
     echo "MySQL: {$version} (" . $DB->dbuser . "@" . $DB->dbhost . "/" . $DB->dbdefault . ")\n\n";
     checkWriteAccessToDirs(true);
     foreach ($CFG_GLPI["systeminformations_types"] as $type) {
         $tmp = new $type();
         $tmp->showSystemInformations($width);
     }
     loadLanguage($oldlang);
     echo "\n</pre></td></tr>";
     echo "<tr class='tab_bg_1'><td>[/code]\n</td></tr>";
     echo "<tr class='tab_bg_2'><th>" . $LANG['setup'][722] . "</th></tr>\n";
     echo "</table></div>\n";
 }