static function cronCleanlogs()
 {
     global $DB;
     $pmLog = new PluginMonitoringLog();
     $pmConfig = new PluginMonitoringConfig();
     $id_restart = 0;
     $a_restarts = $pmLog->find("`action`='restart'", "`id` DESC", 1);
     if (count($a_restarts) > 0) {
         $a_restart = current($a_restarts);
         $id_restart = $a_restart['id'];
     }
     $id_reload = 0;
     $a_reloads = $pmLog->find("`action`='reload'", "`id` DESC", 1);
     if (count($a_reloads) > 0) {
         $a_reload = current($a_reloads);
         $id_reload = $a_reload['id'];
     }
     $pmConfig->getFromDB(1);
     $secs = $pmConfig->fields['logretention'] * DAY_TIMESTAMP;
     $query = "DELETE FROM `" . $pmLog->getTable() . "`\n         WHERE UNIX_TIMESTAMP(date_mod) < UNIX_TIMESTAMP()-{$secs}";
     if ($id_restart > 0 || $id_reload > 0) {
         // Keep last reload or restart command
         $id_restart = max($id_restart, $id_reload);
         $query .= " AND `id` < '" . $id_restart . "'";
     }
     $DB->query($query);
     // TODO: Delete serviceevents table content ???
     $query = "DELETE FROM `glpi_plugin_monitoring_serviceevents`\n         WHERE UNIX_TIMESTAMP(date) < UNIX_TIMESTAMP()-{$secs}";
     $DB->query($query);
     return true;
 }
Ejemplo n.º 2
0
 static function cronCleanlogs()
 {
     global $DB;
     $pmLog = new PluginMonitoringLog();
     $pmConfig = new PluginMonitoringConfig();
     $id_restart = 0;
     $a_restarts = $pmLog->find("`action`='restart'", "`id` DESC", 1);
     if (count($a_restarts) > 0) {
         $a_restart = current($a_restarts);
         $id_restart = $a_restart['id'];
     }
     $pmConfig->getFromDB(1);
     $secs = $pmConfig->fields['logretention'] * DAY_TIMESTAMP;
     $query = "DELETE FROM `" . $pmLog->getTable() . "`\n         WHERE UNIX_TIMESTAMP(date_mod) < UNIX_TIMESTAMP()-{$secs}";
     if ($id_restart > 0) {
         $query .= " AND `id` < '" . $id_restart . "'";
     }
     $DB->query($query);
     // Clean too events
     PluginMonitoringServiceevent::cronUpdaterrd();
     $pmUnavaibility = new PluginMonitoringUnavaibility();
     $pmUnavaibility->runUnavaibility();
     $query = "DELETE FROM `glpi_plugin_monitoring_serviceevents`\n         WHERE UNIX_TIMESTAMP(date) < UNIX_TIMESTAMP()-{$secs}";
     $DB->query($query);
     return true;
 }
 function displayShinkenRestart()
 {
     $pmLog = new PluginMonitoringLog();
     $a_reload_planned = $pmLog->find("(`action`='reload' OR `action`='reload_planned') AND " . "`date_mod` > date_add(now(), interval - 10 MINUTE)", "`id` DESC", 1);
     if (count($a_reload_planned) == 1) {
         $a_reload = current($a_reload_planned);
         if ($a_reload['action'] == 'reload_planned') {
             echo "<div class='msgboxmonit msgboxmonit-red'>";
             echo __('Shinken reload order has been sent at', 'monitoring') . " " . Html::convDateTime($a_reload['date_mod']);
             echo "</div>";
         } else {
             echo "<div class='msgboxmonit msgboxmonit-orange'>";
             echo __('Shinken reloaded at ' . Html::convDateTime($a_reload['date_mod']));
             echo "</div>";
         }
     }
     $a_restart_planned = $pmLog->find("(`action`='restart' OR `action`='restart_planned') AND " . "`date_mod` > date_add(now(), interval - 10 MINUTE)", "`id` DESC", 1);
     if (count($a_restart_planned) == 1) {
         $a_restart = current($a_restart_planned);
         if ($a_restart['action'] == 'restart_planned') {
             echo "<div class='msgboxmonit msgboxmonit-red'>";
             echo __('Shinken restart order has been sent at', 'monitoring') . " " . Html::convDateTime($a_restart['date_mod']);
             echo "</div>";
         } else {
             echo "<div class='msgboxmonit msgboxmonit-orange'>";
             echo __('Shinken restarted at ' . Html::convDateTime($a_restart['date_mod']));
             echo "</div>";
         }
     }
 }
Ejemplo n.º 4
0
 function displayShinkenRestart()
 {
     global $CFG_GLPI;
     $pmLog = new PluginMonitoringLog();
     $a_restart_planned = $pmLog->find("`action` LIKE 'restart%' AND " . "`date_mod` > date_add(now(), interval - 10 MINUTE)", "`id` DESC", 1);
     if (count($a_restart_planned) == 1) {
         $a_restart = current($a_restart_planned);
         if ($a_restart['action'] == 'restart_planned') {
             echo "<div class='msgboxmonit msgboxmonit-red'>";
             echo __('Shiken restart order has been made at ' . Html::convDateTime($a_restart['date_mod']));
             echo "</div>";
         } else {
             echo "<div class='msgboxmonit msgboxmonit-orange'>";
             echo __('Shiken has restarted at ' . Html::convDateTime($a_restart['date_mod']));
             echo "</div>";
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Get modifications of resources (if have modifications);
  */
 function configurationchangesMessage()
 {
     global $DB, $LANG;
     $input = '';
     $pmLog = new PluginMonitoringLog();
     // Get id of last Shinken restart
     $id_restart = 0;
     $a_restarts = $pmLog->find("`action`='restart'", "`id` DESC", 1);
     if (count($a_restarts) > 0) {
         $a_restart = current($a_restarts);
         $id_restart = $a_restart['id'];
     }
     // get number of modifications
     $nb_delete = 0;
     $nb_add = 0;
     $nb_delete = countElementsInTable(getTableForItemType('PluginMonitoringLog'), "`id` > '" . $id_restart . "'\n         AND `action`='delete'");
     $nb_add = countElementsInTable(getTableForItemType('PluginMonitoringLog'), "`id` > '" . $id_restart . "'\n         AND `action`='add'");
     if ($nb_delete > 0 or $nb_add > 0) {
         $input .= $LANG['plugin_monitoring']['log'][1] . "<br/>";
         if ($nb_add > 0) {
             $input .= "<a onClick='Ext.get(\"addelements\").toggle();'>" . $nb_add . "</a> " . $LANG['plugin_monitoring']['log'][2];
             echo "<div style='position:absolute;z-index:10;left: 50%; \n               margin-left: -350px;margin-top:40px;display:none'\n               class='msgboxmonit msgboxmonit-grey' id='addelements'>";
             $query = "SELECT * FROM `" . getTableForItemType('PluginMonitoringLog') . "`\n               WHERE `id` > '" . $id_restart . "' AND `action`='add'\n               ORDER BY `id` DESC";
             $result = $DB->query($query);
             while ($data = $DB->fetch_array($result)) {
                 echo "[" . convDateTime($data['date_mod']) . "] Add " . $data['value'] . "<br/>";
             }
             echo "</div>";
         }
         if ($nb_delete > 0) {
             if ($nb_add > 0) {
                 $input .= " / ";
             }
             $input .= "<a onClick='Ext.get(\"deleteelements\").toggle();'>" . $nb_delete . "</a> " . $LANG['plugin_monitoring']['log'][3];
             echo "<div style='position:absolute;z-index:10;left: 50%; \n               margin-left: -350px;margin-top:40px;display:none'\n               class='msgboxmonit msgboxmonit-grey' id='deleteelements'>";
             $query = "SELECT * FROM `" . getTableForItemType('PluginMonitoringLog') . "`\n               WHERE `id` > '" . $id_restart . "' AND `action`='delete'\n               ORDER BY `id` DESC";
             $result = $DB->query($query);
             while ($data = $DB->fetch_array($result)) {
                 echo "[" . convDateTime($data['date_mod']) . "] Delete " . $data['value'] . "<br/>";
             }
             echo "</div>";
         }
         $input .= "<br/>";
         $input .= $LANG['plugin_monitoring']['log'][4];
     }
     return $input;
 }