Beispiel #1
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;
 }
 static function runUnavaibility($services_id = 0)
 {
     global $DB;
     $pmUnavaibility = new PluginMonitoringUnavaibility();
     $pmServiceevent = new PluginMonitoringServiceevent();
     $where = '';
     if ($services_id != '0') {
         $where = " WHERE `id`='" . $services_id . "' ";
     }
     $query = "SELECT * FROM `glpi_plugin_monitoring_services` " . $where;
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         $pmUnavaibility->getCurrentState($data['id']);
         $query2 = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n            WHERE `unavailability`='0'\n               AND `state_type`='HARD'\n               AND `plugin_monitoring_services_id`='" . $data['id'] . "'\n            ORDER BY `date`";
         $result2 = $DB->query($query2);
         while ($data2 = $DB->fetch_array($result2)) {
             $pmUnavaibility->checkState($data2['state'], $data2['date']);
             $input = array();
             $input['id'] = $data2['id'];
             $input['unavailability'] = 1;
             $pmServiceevent->update($input);
         }
     }
 }
Beispiel #3
0
 static function displayLine($data, $displayhost = 1)
 {
     global $DB, $CFG_GLPI;
     $pMonitoringService = new PluginMonitoringService();
     $networkPort = new NetworkPort();
     $pMonitoringComponent = new PluginMonitoringComponent();
     $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
     $entity = new Entity();
     $pMonitoringService->getFromDB($data['id']);
     echo "<td width='32' class='center'>";
     $shortstate = self::getState($data['state'], $data['state_type'], $data['event'], $data['is_acknowledged']);
     $alt = __('Ok', 'monitoring');
     if ($shortstate == 'orange') {
         $alt = __('Warning (data)', 'monitoring');
     } else {
         if ($shortstate == 'yellow') {
             $alt = __('Warning (connection)', 'monitoring');
         } else {
             if ($shortstate == 'red') {
                 $alt = __('Critical', 'monitoring');
             } else {
                 if ($shortstate == 'redblue') {
                     $alt = __('Critical / Acknowledge', 'monitoring');
                 }
             }
         }
     }
     echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/box_" . $shortstate . "_32.png'\n         title='" . $alt . "' alt='" . $alt . "' />";
     echo "</td>";
     echo "<td>";
     $entity->getFromDB($data['entities_id']);
     echo $entity->fields['completename'];
     echo "</td>";
     $pMonitoringComponent->getFromDB($data['plugin_monitoring_components_id']);
     echo "<td class='center'>";
     $timezone = '0';
     if (isset($_SESSION['plugin_monitoring_timezone'])) {
         $timezone = $_SESSION['plugin_monitoring_timezone'];
     }
     if ($pMonitoringComponent->fields['graph_template'] != '') {
         echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/display.form.php?itemtype=PluginMonitoringService&items_id=" . $data['id'] . "'>";
         $pmServicegraph = new PluginMonitoringServicegraph();
         ob_start();
         $pmServicegraph->displayGraph($pMonitoringComponent->fields['graph_template'], "PluginMonitoringService", $data['id'], "0", '2h', "div", "600");
         $div = ob_get_contents();
         ob_end_clean();
         $chart = "<table width='600' class='tab_cadre'><tr><td>" . $div . "</td></tr></table>";
         Html::showToolTip($chart, array('img' => $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/stats_32.png"));
         $pmServicegraph->displayGraph($pMonitoringComponent->fields['graph_template'], "PluginMonitoringService", $data['id'], "0", '2h', "js");
     }
     echo "</a>";
     echo "</td>";
     if ($displayhost == '1') {
         $pmComponentscatalog_Host->getFromDB($data["plugin_monitoring_componentscatalogs_hosts_id"]);
         if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') {
             $itemtype = $pmComponentscatalog_Host->fields['itemtype'];
             $item = new $itemtype();
             $item->getFromDB($pmComponentscatalog_Host->fields['items_id']);
             echo "<td>";
             echo $item->getTypeName() . " : " . $item->getLink();
             if (!is_null($pMonitoringService->fields['networkports_id']) and $pMonitoringService->fields['networkports_id'] > 0) {
                 $networkPort->getFromDB($pMonitoringService->fields['networkports_id']);
                 echo " [" . $networkPort->getLink() . "]";
             }
             echo "</td>";
         } else {
             echo "<td>" . __('Resources', 'monitoring') . "</td>";
         }
     }
     echo "<td>" . $pMonitoringComponent->getLink();
     if (!is_null($pMonitoringService->fields['networkports_id']) and $pMonitoringService->fields['networkports_id'] > 0) {
         $networkPort->getFromDB($pMonitoringService->fields['networkports_id']);
         echo " [" . $networkPort->getLink() . "]";
     }
     echo "</td>";
     //      $nameitem = '';
     //      if (isset($itemmat->fields['name'])) {
     //         $nameitem = "[".$itemmat->getLink(1)."]";
     //      }
     //if ($pMonitoringService->fields['plugin_monitoring_services_id'] == '0') {
     //echo "<td>".$itemmat->getLink(1)."</td>";
     //      } else {
     //         $pMonitoringServiceH->getFromDB($pMonitoringService->fields['plugin_monitoring_services_id']);
     //         $itemtypemat = $pMonitoringServiceH->fields['itemtype'];
     //         $itemmat = new $itemtypemat();
     //         $itemmat->getFromDB($pMonitoringServiceH->fields['items_id']);
     //         echo "<td>".$pMonitoringService->getLink(1).$nameitem." ".__('on', 'monitoring')." ".$itemmat->getLink(1)."</td>";
     //      }
     //      unset($itemmat);
     echo "<td class='center'>";
     if ($shortstate == 'red') {
         echo "<table>";
         echo "<tr>";
         echo "<td>";
         echo $data['state'];
         echo "</td>";
         echo "<td>";
         echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/acknowledge.form.php?id=" . $data['id'] . "'>" . "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/acknowledge_checked.png'" . " alt='" . __('Define an acknowledge', 'monitoring') . "'" . " title='" . __('Define an acknowledge', 'monitoring') . "'/>" . "</a>";
         echo "</td>";
         echo "</tr>";
         echo "</table>";
     } else {
         echo $data['state'];
     }
     echo "</td>";
     echo "<td>";
     echo Html::convDate($data['last_check']) . ' ' . substr($data['last_check'], 11, 8);
     echo "</td>";
     echo "<td>";
     echo $data['event'];
     echo "</td>";
     echo "<td align='center'>";
     $segments = CalendarSegment::getSegmentsBetween($pMonitoringComponent->fields['calendars_id'], date('w', date('U')), date('H:i:s'), date('w', date('U')), date('H:i:s'));
     if (count($segments) == '0') {
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/service_pause.png' />";
     } else {
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/service_run.png' />";
     }
     echo "</td>";
     if ($displayhost == '0') {
         $pmUnavaibility = new PluginMonitoringUnavaibility();
         $pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'currentmonth', 1);
         $pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'lastmonth', 1);
         $pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'currentyear', 1);
         echo "<td class='center'>";
         echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/unavaibility.php?" . "field[0]=2&searchtype[0]=equals&contains[0]=" . $pMonitoringService->fields['id'] . "&sort=3&order=DESC&itemtype=PluginMonitoringUnavaibility'>\n            <img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/info.png'/></a>";
         echo "</td>";
     }
     echo "<td>";
     if ($shortstate == 'redblue') {
         echo "<i>" . _n('User', 'Users', 1) . " : </i>";
         $user = new User();
         $user->getFromDB($data['acknowledge_users_id']);
         echo $user->getName(1);
         echo "<br/>";
         echo "<i>" . __('Comments') . " : </i>" . $data['acknowledge_comment'];
     }
     echo "</td>";
     if ($displayhost == '0') {
         echo "<td>";
         if (PluginMonitoringProfile::haveRight("componentscatalog", 'w')) {
             $a_arg = importArrayFromDB($pMonitoringService->fields['arguments']);
             $cnt = '';
             if (count($a_arg) > 0) {
                 $cnt = " (" . count($a_arg) . ")";
             }
             echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/servicearg.form.php?id=" . $data['id'] . "'>" . __('Configure', 'monitoring') . $cnt . "</a>";
         }
         echo "</td>";
     }
 }
 function parseToDB($plugin_monitoring_services_id)
 {
     global $DB;
     $pmService = new PluginMonitoringService();
     $pmComponent = new PluginMonitoringComponent();
     if ($pmService->getFromDB($plugin_monitoring_services_id)) {
         $pmComponent->getFromDB($pmService->fields['plugin_monitoring_components_id']);
         if (!isset($pmComponent->fields['plugin_monitoring_commands_id'])) {
             return;
         }
         if (is_null($pmComponent->fields['graph_template'])) {
             return;
         }
         $pmUnavaibility = new PluginMonitoringUnavaibility();
         $pmUnavaibility->runUnavaibility($plugin_monitoring_services_id);
         $a_dateold = array();
         // *** 1 day (x 30 min)
         $dateold = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m'), date('d') - 1, date('Y')));
         $a_dateold['30m'] = $dateold;
         // Gest last value, and see if we must calculate new values
         $query = "SELECT * FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                  AND `type`='30m'\n               ORDER BY `date` DESC\n               LIMIT 1";
         $result = $DB->query($query);
         $lastdate = $dateold;
         $new_date = '';
         if ($DB->numrows($result) == '1') {
             $data = $DB->fetch_assoc($result);
             $new_date = PluginMonitoringServiceevent::convert_datetime_timestamp($data['date']);
             $new_date += 30 * 60;
         } else {
             $split = explode(" ", $lastdate);
             $a_time = explode(":", $split[1]);
             $a_date = explode("-", $split[0]);
             $new_date = date('U', mktime($a_time[0], '0', '0', $a_date[1], $a_date[2], $a_date[0]));
         }
         //get data in serviceevents for each 30 minutes from this date to now
         while ($new_date + 15 * 60 < date('U')) {
             $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n                  WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                     AND `date` >= '" . date('Y-m-d H:i:m', $new_date - 15 * 60) . "'\n                     AND`date` <= '" . date('Y-m-d H:i:m', $new_date + 15 * 60) . "'\n                  ORDER BY `date`";
             $result = $DB->query($query);
             // get data
             $mydatat = array();
             $pmServiceevent = new PluginMonitoringServiceevent();
             $pmService = new PluginMonitoringService();
             $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template']);
             if (is_array($ret)) {
                 $mydatat = $ret[0];
             }
             $array_data = array();
             foreach ($mydatat as $name => $a_values) {
                 $valfloat = array_sum($a_values) / count($a_values);
                 if ($valfloat > 2) {
                     $array_data[$name] = round($valfloat);
                 } else {
                     $array_data[$name] = round($valfloat, 2);
                 }
             }
             $input = array();
             $input['plugin_monitoring_services_id'] = $plugin_monitoring_services_id;
             $input['date'] = date('Y-m-d H:i:s', $new_date);
             $input['data'] = exportArrayToDB($array_data);
             $input['type'] = '30m';
             $this->add($input);
             $new_date = $new_date + 30 * 60;
         }
         // *** 1w (x 6 hours)
         $dateold = date('Y-m-d H:i:s', date('U') - 7 * 24 * 3600);
         $a_dateold['6h'] = $dateold;
         // Gest last value, and see if we must calculate new values
         $query = "SELECT * FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                  AND `type`='6h'\n               ORDER BY `date` DESC\n               LIMIT 1";
         $result = $DB->query($query);
         $lastdate = $dateold;
         $new_date = '';
         if ($DB->numrows($result) == '1') {
             $data = $DB->fetch_assoc($result);
             $new_date = PluginMonitoringServiceevent::convert_datetime_timestamp($data['date']);
             $new_date += 6 * 3600;
         } else {
             $split = explode(" ", $lastdate);
             $a_time = explode(":", $split[1]);
             $a_date = explode("-", $split[0]);
             $hour = '0';
             $addtime = 0;
             if ($a_time[0] > 18) {
                 $hour = 0;
                 $addtime = 24 * 3600;
             } else {
                 if ($a_time[0] > 12) {
                     $hour = 18;
                 } else {
                     if ($a_time[0] > 6) {
                         $hour = 12;
                     } else {
                         $hour = 6;
                     }
                 }
             }
             $new_date = date('U', mktime($hour, '0', '0', $a_date[1], $a_date[2], $a_date[0])) + $addtime;
         }
         //get data in serviceevents for each 6 hours from this date to now
         while ($new_date + 3 * 3600 < date('U')) {
             $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n                  WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                     AND `date` >= '" . date('Y-m-d H:i:m', $new_date - 3 * 3600) . "'\n                     AND`date` <= '" . date('Y-m-d H:i:m', $new_date + 3 * 3600) . "'\n                  ORDER BY `date`";
             $result = $DB->query($query);
             // get data
             $mydatat = array();
             $pmServiceevent = new PluginMonitoringServiceevent();
             $pmService = new PluginMonitoringService();
             $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template']);
             if (is_array($ret)) {
                 $mydatat = $ret[0];
             }
             $array_data = array();
             foreach ($mydatat as $name => $a_values) {
                 $valfloat = array_sum($a_values) / count($a_values);
                 if ($valfloat > 2) {
                     $array_data[$name] = round($valfloat);
                 } else {
                     $array_data[$name] = round($valfloat, 2);
                 }
             }
             $input = array();
             $input['plugin_monitoring_services_id'] = $plugin_monitoring_services_id;
             $input['date'] = date('Y-m-d H:i:s', $new_date);
             $input['data'] = exportArrayToDB($array_data);
             $input['type'] = '6h';
             $this->add($input);
             $new_date = $new_date + 6 * 3600;
         }
         // *** 1m (x 1 day)
         $dateold = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m') - 1, date('d'), date('Y')));
         //            $a_dateold['1d'] = $dateold; //NOTE to keep data for each day (if we want use it in future)
         // Gest last value, and see if we must calculate new values
         $query = "SELECT * FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                  AND `type`='1d'\n               ORDER BY `date` DESC\n               LIMIT 1";
         $result = $DB->query($query);
         $lastdate = $dateold;
         $new_date = '';
         if ($DB->numrows($result) == '1') {
             $data = $DB->fetch_assoc($result);
             $new_date = PluginMonitoringServiceevent::convert_datetime_timestamp($data['date']);
             $new_date += 24 * 3600;
         } else {
             $split = explode(" ", $lastdate);
             $a_date = explode("-", $split[0]);
             $new_date = date('U', mktime('0', '0', '0', $a_date[1], $a_date[2], $a_date[0]));
         }
         //get data in serviceevents for each 6 hours from this date to now
         while ($new_date + 12 * 3600 < date('U')) {
             $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n                  WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                     AND `date` >= '" . date('Y-m-d H:i:m', $new_date - 12 * 3600) . "'\n                     AND`date` <= '" . date('Y-m-d H:i:m', $new_date + 12 * 3600) . "'\n                  ORDER BY `date`";
             $result = $DB->query($query);
             // get data
             $mydatat = array();
             $pmServiceevent = new PluginMonitoringServiceevent();
             $pmService = new PluginMonitoringService();
             $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template']);
             if (is_array($ret)) {
                 $mydatat = $ret[0];
             }
             $array_data = array();
             foreach ($mydatat as $name => $a_values) {
                 $valfloat = array_sum($a_values) / count($a_values);
                 if ($valfloat > 2) {
                     $array_data[$name] = round($valfloat);
                 } else {
                     $array_data[$name] = round($valfloat, 2);
                 }
             }
             $input = array();
             $input['plugin_monitoring_services_id'] = $plugin_monitoring_services_id;
             $input['date'] = date('Y-m-d H:i:s', $new_date);
             $input['data'] = exportArrayToDB($array_data);
             $input['type'] = '1d';
             $this->add($input);
             $new_date = $new_date + 24 * 3600;
         }
         // *** 6m (x 5 days)
         $dateold = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m') - 6, date('d'), date('Y')));
         $a_dateold['5d'] = $dateold;
         // Gest last value, and see if we must calculate new values
         $query = "SELECT * FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                  AND `type`='5d'\n               ORDER BY `date` DESC\n               LIMIT 1";
         $result = $DB->query($query);
         $lastdate = $dateold;
         $new_date = '';
         if ($DB->numrows($result) == '1') {
             $data = $DB->fetch_assoc($result);
             $new_date = PluginMonitoringServiceevent::convert_datetime_timestamp($data['date']);
             $new_date += 5 * 24 * 3600;
         } else {
             $split = explode(" ", $lastdate);
             $a_date = explode("-", $split[0]);
             $new_date = date('U', mktime('0', '0', '0', $a_date[1], $a_date[2], $a_date[0]));
         }
         //get data in serviceevents for each 6 hours from this date to now
         while ($new_date + 5 * 24 * 3600 / 2 < date('U')) {
             $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n                  WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                     AND `date` >= '" . date('Y-m-d H:i:m', $new_date - 5 * 24 * 3600 / 2) . "'\n                     AND`date` <= '" . date('Y-m-d H:i:m', $new_date + 5 * 24 * 3600 / 2) . "'\n                  ORDER BY `date`";
             $result = $DB->query($query);
             // get data
             $mydatat = array();
             $pmServiceevent = new PluginMonitoringServiceevent();
             $pmService = new PluginMonitoringService();
             $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template']);
             if (is_array($ret)) {
                 $mydatat = $ret[0];
             }
             $array_data = array();
             foreach ($mydatat as $name => $a_values) {
                 $valfloat = array_sum($a_values) / count($a_values);
                 if ($valfloat > 2) {
                     $array_data[$name] = round($valfloat);
                 } else {
                     $array_data[$name] = round($valfloat, 2);
                 }
             }
             $input = array();
             $input['plugin_monitoring_services_id'] = $plugin_monitoring_services_id;
             $input['date'] = date('Y-m-d H:i:s', $new_date);
             $input['data'] = exportArrayToDB($array_data);
             $input['type'] = '5d';
             $this->add($input);
             $new_date = $new_date + 5 * 24 * 3600;
         }
         // *** 1y (x 10 days)
         $dateold = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m') - 10, date('d'), date('Y')));
         $a_dateold['5d'] = $dateold;
         // Gest last value, and see if we must calculate new values
         $query = "SELECT * FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                  AND `type`='10d'\n               ORDER BY `date` DESC\n               LIMIT 1";
         $result = $DB->query($query);
         $lastdate = $dateold;
         $new_date = '';
         if ($DB->numrows($result) == '1') {
             $data = $DB->fetch_assoc($result);
             $new_date = PluginMonitoringServiceevent::convert_datetime_timestamp($data['date']);
             $new_date += 10 * 24 * 3600;
         } else {
             $split = explode(" ", $lastdate);
             $a_date = explode("-", $split[0]);
             $new_date = date('U', mktime('0', '0', '0', $a_date[1], $a_date[2], $a_date[0]));
         }
         //get data in serviceevents for each 6 hours from this date to now
         while ($new_date + 5 * 24 * 3600 < date('U')) {
             $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n                  WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                     AND `date` >= '" . date('Y-m-d H:i:m', $new_date - 5 * 24 * 3600) . "'\n                     AND`date` <= '" . date('Y-m-d H:i:m', $new_date + 5 * 24 * 3600) . "'\n                  ORDER BY `date`";
             $result = $DB->query($query);
             // get data
             $mydatat = array();
             $pmServiceevent = new PluginMonitoringServiceevent();
             $pmService = new PluginMonitoringService();
             $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template']);
             if (is_array($ret)) {
                 $mydatat = $ret[0];
             }
             $array_data = array();
             foreach ($mydatat as $name => $a_values) {
                 $valfloat = array_sum($a_values) / count($a_values);
                 if ($valfloat > 2) {
                     $array_data[$name] = round($valfloat);
                 } else {
                     $array_data[$name] = round($valfloat, 2);
                 }
             }
             $input = array();
             $input['plugin_monitoring_services_id'] = $plugin_monitoring_services_id;
             $input['date'] = date('Y-m-d H:i:s', $new_date);
             $input['data'] = exportArrayToDB($array_data);
             $input['type'] = '10d';
             $this->add($input);
             $new_date = $new_date + 10 * 24 * 3600;
         }
         // *** Delete old values
         foreach ($a_dateold as $name => $date) {
             $query = "DELETE FROM `" . $this->getTable() . "`\n               WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                  AND `type`='" . $name . "'\n                  AND `date` < '" . $date . "'";
             $result = $DB->query($query);
         }
     }
 }
 static function displayLine($data, $displayhost = 1)
 {
     global $DB, $CFG_GLPI, $LANG;
     $pMonitoringService = new PluginMonitoringService();
     $networkPort = new NetworkPort();
     $pMonitoringComponent = new PluginMonitoringComponent();
     $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
     $pmServicegraph = new PluginMonitoringServicegraph();
     $entity = new Entity();
     $pMonitoringService->getFromDB($data['id']);
     echo "<td width='32' class='center'>";
     $shortstate = self::getState($data['state'], $data['state_type']);
     echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/box_" . $shortstate . "_32.png'/>";
     echo "</td>";
     echo "<td>";
     $entity->getFromDB($data['entities_id']);
     echo $entity->fields['completename'];
     echo "</td>";
     $pMonitoringComponent->getFromDB($data['plugin_monitoring_components_id']);
     echo "<td class='center'>";
     $img = '';
     $timezone = '0';
     if (isset($_SESSION['plugin_monitoring_timezone'])) {
         $timezone = $_SESSION['plugin_monitoring_timezone'];
     }
     $timezone_file = str_replace("+", ".", $timezone);
     $img = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=PluginMonitoringService-" . $data['id'] . "-2h" . $timezone_file . ".png'/>";
     echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/display.form.php?itemtype=PluginMonitoringService&items_id=" . $data['id'] . "'>";
     if (file_exists(GLPI_ROOT . "/files/_plugins/monitoring/PluginMonitoringService-" . $data['id'] . "-2h" . $timezone_file . ".png") or $pMonitoringComponent->fields['graph_template'] != '') {
         $img = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=PluginMonitoringService-" . $data['id'] . "-2h" . $timezone_file . ".png'/>";
         showToolTip($img, array('img' => $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/stats_32.png"));
     } else {
     }
     echo "</a>";
     echo "</td>";
     if ($displayhost == '1') {
         $pmComponentscatalog_Host->getFromDB($data["plugin_monitoring_componentscatalogs_hosts_id"]);
         if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') {
             $itemtype = $pmComponentscatalog_Host->fields['itemtype'];
             $item = new $itemtype();
             $item->getFromDB($pmComponentscatalog_Host->fields['items_id']);
             echo "<td>";
             echo $item->getTypeName() . " : " . $item->getLink();
             if (!is_null($pMonitoringService->fields['networkports_id']) and $pMonitoringService->fields['networkports_id'] > 0) {
                 $networkPort->getFromDB($pMonitoringService->fields['networkports_id']);
                 echo " [" . $networkPort->getLink() . "]";
             }
             echo "</td>";
         } else {
             echo "<td>" . $LANG['plugin_monitoring']['service'][0] . "</td>";
         }
     }
     echo "<td>" . $pMonitoringComponent->getLink();
     if (!is_null($pMonitoringService->fields['networkports_id']) and $pMonitoringService->fields['networkports_id'] > 0) {
         $networkPort->getFromDB($pMonitoringService->fields['networkports_id']);
         echo " [" . $networkPort->getLink() . "]";
     }
     echo "</td>";
     //      $nameitem = '';
     //      if (isset($itemmat->fields['name'])) {
     //         $nameitem = "[".$itemmat->getLink(1)."]";
     //      }
     //if ($pMonitoringService->fields['plugin_monitoring_services_id'] == '0') {
     //echo "<td>".$itemmat->getLink(1)."</td>";
     //      } else {
     //         $pMonitoringServiceH->getFromDB($pMonitoringService->fields['plugin_monitoring_services_id']);
     //         $itemtypemat = $pMonitoringServiceH->fields['itemtype'];
     //         $itemmat = new $itemtypemat();
     //         $itemmat->getFromDB($pMonitoringServiceH->fields['items_id']);
     //         echo "<td>".$pMonitoringService->getLink(1).$nameitem." ".$LANG['networking'][25]." ".$itemmat->getLink(1)."</td>";
     //      }
     //      unset($itemmat);
     echo "<td class='center'>";
     echo $data['state'];
     echo "</td>";
     echo "<td>";
     echo convDate($data['last_check']) . ' ' . substr($data['last_check'], 11, 8);
     echo "</td>";
     echo "<td>";
     echo $data['event'];
     echo "</td>";
     echo "<td align='center'>";
     $segments = CalendarSegment::getSegmentsBetween($pMonitoringComponent->fields['calendars_id'], date('w', date('U')), date('H:i:s'), date('w', date('U')), date('H:i:s'));
     if (count($segments) == '0') {
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/service_pause.png' />";
     } else {
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/service_run.png' />";
     }
     echo "</td>";
     if ($displayhost == '0') {
         $pmUnavaibility = new PluginMonitoringUnavaibility();
         $pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'currentmonth', 1);
         $pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'lastmonth', 1);
         $pmUnavaibility->displayValues($pMonitoringService->fields['id'], 'currentyear', 1);
         echo "<td>";
         $a_arg = importArrayFromDB($pMonitoringService->fields['arguments']);
         $cnt = '';
         if (count($a_arg) > 0) {
             $cnt = " (" . count($a_arg) . ")";
         }
         echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/servicearg.form.php?id=" . $data['id'] . "'>" . $LANG['plugin_monitoring']['service'][25] . $cnt . "</a>";
         echo "</td>";
     }
 }
 function generateSyntheseReport($array)
 {
     global $DB;
     $end_date = $array[$array['reporttype'] . 'date_end'];
     $end_date_timestamp = strtotime($end_date);
     $number = $array[$array['reporttype'] . 'number'];
     $period = $array[$array['reporttype'] . 'period'];
     $componentscatalogs_id = $array['componentscatalogs_id'];
     $pmComponent = new PluginMonitoringComponent();
     $pmUnavaibility = new PluginMonitoringUnavaibility();
     $pmServiceevent = new PluginMonitoringServiceevent();
     PluginMonitoringReport::beginCapture();
     $a_groups = array("avaibility");
     foreach ($array['perfname'] as $perfname) {
         $a_groups[] = $perfname;
     }
     $a_groups = array_unique($a_groups);
     foreach ($a_groups as $groupname) {
         foreach ($array['components_id'] as $components_id) {
             $pmComponent->getFromDB($components_id);
             echo "<table class='tab_cadre_fixe'>";
             echo '<tr class="tab_bg_1">';
             echo '<th colspan="' . (3 + $number * 2) . '">';
             echo $pmComponent->getName() . " / ";
             if ($groupname == 'avaibility') {
                 echo __('Avaibility', 'monitoring');
             } else {
                 echo $groupname;
             }
             echo '</th>';
             echo '</tr>';
             echo '<tr class="tab_bg_1">';
             echo '<th>';
             echo __('Name');
             echo '</th>';
             echo '<th>';
             echo __('Entity');
             echo '</th>';
             echo '<th>';
             echo __('Itemtype');
             echo '</th>';
             for ($i = $number; $i >= 1; $i--) {
                 echo '<th colspan="2">';
                 echo Html::convDate(date('Y-m-d', strtotime("-" . $i . " " . $period, $end_date_timestamp)));
                 echo "<br/>";
                 echo Html::convDate(date('Y-m-d', strtotime("-" . ($i - 1) . " " . $period, $end_date_timestamp)));
                 echo '</th>';
             }
             echo '</tr>';
             $query = "SELECT `glpi_plugin_monitoring_componentscatalogs_hosts`.*, \n                  `glpi_plugin_monitoring_services`.`id` as sid FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n               LEFT JOIN `glpi_plugin_monitoring_services`\n                  ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`=`plugin_monitoring_componentscatalogs_hosts_id`\n               WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'\n                  AND `plugin_monitoring_components_id`='" . $components_id . "'";
             $result = $DB->query($query);
             $rownb = true;
             while ($data = $DB->fetch_array($result)) {
                 $itemtype = $data['itemtype'];
                 $item = new $itemtype();
                 $item->getFromDB($data['items_id']);
                 if ($groupname == 'avaibility') {
                     $a_times = $pmUnavaibility->parseEvents($data['id'], '', date('Y-m-d', strtotime("-" . ($number + 1) . " " . $period, $end_date_timestamp)), date('Y-m-d', strtotime("-" . $number . " " . $period, $end_date_timestamp)));
                     $previous_value = round(($a_times[1] - $a_times[0]) / $a_times[1] * 100, 3);
                 } else {
                     $previous_value = 0;
                 }
                 echo '<tr class="tab_bg_1' . (($rownb = !$rownb) ? '_2' : '') . '">';
                 echo '<td>';
                 echo $item->getName();
                 echo '</td>';
                 echo '<td>';
                 echo Dropdown::getDropdownName("glpi_entities", $item->fields['entities_id']);
                 echo '</td>';
                 echo '<td>';
                 echo $item->getTypeName();
                 echo '</td>';
                 for ($i = $number; $i >= 1; $i--) {
                     echo '<td>';
                     $startdatet = date('Y-m-d', strtotime("-" . $i . " " . $period, $end_date_timestamp));
                     $enddatet = date('Y-m-d', strtotime("-" . ($i - 1) . " " . $period, $end_date_timestamp));
                     if ($groupname == 'avaibility') {
                         $a_times = $pmUnavaibility->parseEvents($data['id'], '', $startdatet, $enddatet);
                         $value = round(($a_times[1] - $a_times[0]) / $a_times[1] * 100, 3);
                         echo $value . "%";
                     } else {
                         $queryevents = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n                        WHERE `plugin_monitoring_services_id`='" . $data['sid'] . "'\n                           AND `date` >= '" . $startdatet . "'\n                           AND `date` <= '" . $enddatet . "'\n                        ORDER BY `date`";
                         $resultevents = $DB->query($queryevents);
                         $ret = $pmServiceevent->getData($resultevents, $pmComponent->fields['graph_template']);
                         $value = round(array_sum($ret[0][$groupname]) / count($ret[0][$groupname]), 3);
                         echo $value;
                     }
                     echo '</td>';
                     echo '<td>';
                     if ($previous_value < $value) {
                         echo '<img src="../pics/arrow-up-right.png" width="16" />';
                     } else {
                         if ($previous_value == $value) {
                             echo '<img src="../pics/arrow-right.png" width="16" />';
                         } else {
                             if ($previous_value > $value) {
                                 echo '<img src="../pics/arrow-down-right.png" width="16" />';
                             }
                         }
                     }
                     $previous_value = $value;
                     echo '</td>';
                 }
                 echo "</tr>";
             }
             echo "</table>";
         }
         echo "<br/><br/>";
     }
     $content = PluginMonitoringReport::endCapture();
     PluginMonitoringReport::generatePDF($content, 'L');
 }
    switch ($_POST['glpi_tab']) {
        case -1:
            break;
        case 1:
            $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component();
            $pmComponentscatalog_Component->showComponents($_POST['id']);
            break;
        case 2:
            $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
            $pmComponentscatalog_Host->showHosts($_POST['id'], 1);
            break;
        case 3:
            $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule();
            $pmComponentscatalog_rule->showRules($_POST['id']);
            break;
        case 4:
            $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
            $pmComponentscatalog_Host->showHosts($_POST['id'], 0);
            break;
        case 5:
            $pmContact_Item = new PluginMonitoringContact_Item();
            $pmContact_Item->showContacts("PluginMonitoringComponentscatalog", $_POST['id']);
            break;
        case 6:
            $pmUnavaibility = new PluginMonitoringUnavaibility();
            $pmUnavaibility->displayComponentscatalog($_POST['id']);
            break;
        default:
    }
}
ajaxFooter();
Beispiel #8
0
  Plugin Monitoring for GLPI is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with Monitoring. If not, see <http://www.gnu.org/licenses/>.

  ------------------------------------------------------------------------

  @package   Plugin Monitoring for GLPI
  @author    David Durieux
  @co-author 
  @comment   
  @copyright Copyright (c) 2011-2013 Plugin Monitoring for GLPI team
  @license   AGPL License 3.0 or (at your option) any later version
             http://www.gnu.org/licenses/agpl-3.0-standalone.html
  @link      https://forge.indepnet.net/projects/monitoring/
  @since     2013

  ------------------------------------------------------------------------
*/
include "../../../inc/includes.php";
Session::checkCentralAccess();
Html::header(__('Monitoring', 'monitoring'), $_SERVER["PHP_SELF"], "plugins", "monitoring", "unavaibility");
if (isset($_GET['contains'])) {
    $pmUnavaibility = new PluginMonitoringUnavaibility();
    $pmUnavaibility->showList($_GET);
}
Html::footer();
 function parseToRrdtool($plugin_monitoring_services_id)
 {
     global $DB;
     $pmRrdtool = new PluginMonitoringRrdtool();
     $pmCommand = new PluginMonitoringCommand();
     $pmService = new PluginMonitoringService();
     $pmComponent = new PluginMonitoringComponent();
     if ($pmService->getFromDB($plugin_monitoring_services_id)) {
         $pmComponent->getFromDB($pmService->fields['plugin_monitoring_components_id']);
         if (!isset($pmComponent->fields['plugin_monitoring_commands_id'])) {
             return;
         }
         if (is_null($pmComponent->fields['graph_template'])) {
             return;
         }
         $pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']);
         $pmUnavaibility = new PluginMonitoringUnavaibility();
         $pmUnavaibility->runUnavaibility($plugin_monitoring_services_id);
         $query = "SELECT * FROM `" . $this->getTable() . "`\n            WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n            ORDER BY `date`";
         $result = $DB->query($query);
         $i = 0;
         $nb_rows = $DB->numrows($result);
         $rrdtool_value = '';
         $last_date = '';
         while ($edata = $DB->fetch_array($result)) {
             $i++;
             if ($edata['unavailability'] == '0') {
                 if ($last_date != '') {
                     $pmRrdtool->addData($pmComponent->fields['graph_template'], $plugin_monitoring_services_id, 0, '', $rrdtool_value, 1);
                 }
                 break;
             }
             $perf_data = $edata['perf_data'];
             if ($edata['perf_data'] == '') {
                 $perf_data = $edata['output'];
             }
             if ($edata['unavailability'] != '2' and $i < $nb_rows) {
                 $rrdtool_value = $pmRrdtool->addData($pmComponent->fields['graph_template'], $plugin_monitoring_services_id, $this->convert_datetime_timestamp($edata['date']), $perf_data, $rrdtool_value, 0);
             }
             $last_date = $edata['date'];
             if ($i == $nb_rows) {
                 if ($edata['unavailability'] != '2') {
                     $input = array();
                     $input['id'] = $edata['id'];
                     $input['unavailability'] = 2;
                     $this->update($input);
                     $pmRrdtool->addData($pmComponent->fields['graph_template'], $plugin_monitoring_services_id, $this->convert_datetime_timestamp($edata['date']), $perf_data, $rrdtool_value, 1);
                     $queryd = "DELETE FROM `" . $this->getTable() . "`\n                     WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n                        AND `date`<'" . $edata['date'] . "'";
                     $DB->query($queryd);
                 }
             }
         }
         $a_list = array();
         $a_list[] = "2h";
         $a_list[] = "12h";
         $a_list[] = "1d";
         $a_list[] = "1w";
         $a_list[] = "1m";
         $a_list[] = "0y6m";
         $a_list[] = "1y";
         $pmConfig = new PluginMonitoringConfig();
         $pmConfig->getFromDB(1);
         $a_timezones = importArrayFromDB($pmConfig->fields['timezones']);
         foreach ($a_list as $time) {
             foreach ($a_timezones as $timezone) {
                 $pmRrdtool->displayGLPIGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $plugin_monitoring_services_id, $timezone, $time);
             }
         }
     } else {
         $query = "DELETE FROM `" . $this->getTable() . "`\n            WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'";
         $DB->query($query);
     }
 }