示例#1
0
 static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
 {
     if ($item->getID() > 0) {
         if ($tabnum == 0) {
             PluginMonitoringServicegraph::loadLib();
             $pmService = new PluginMonitoringService();
             $pmService->manageServices(get_class($item), $item->fields['id']);
             $pmHostconfig = new PluginMonitoringHostconfig();
             $pmHostconfig->showForm($item->getID(), get_class($item));
         } else {
             if ($tabnum == 1) {
                 $pmService = new PluginMonitoringService();
                 $pmService->showGraphsByHost(get_class($item), $item->fields['id']);
             }
         }
     }
     return true;
 }
示例#2
0
   function showWidget($id, $time) {
      global $DB, $CFG_GLPI;

      $pmComponent = new PluginMonitoringComponent();

      if ($this->getFromDB($id)) {
         $pmComponent->getFromDB($this->fields['plugin_monitoring_components_id']);

         $pmServicegraph = new PluginMonitoringServicegraph();
         ob_start();
         $pmServicegraph->displayGraph($pmComponent->fields['graph_template'],
                                       "PluginMonitoringService",
                                       $id,
                                       "0",
                                       $time,
                                       "div",
                                       "475");
         $chart = ob_get_contents();
         ob_end_clean();
         return $chart;
      }
   }
  @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     2011

  ------------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
    define('GLPI_ROOT', '../../..');
}
include GLPI_ROOT . "/inc/includes.php";
checkCentralAccess();
commonHeader($LANG['plugin_monitoring']['title'][0], $_SERVER["PHP_SELF"], "plugins", "monitoring", "display");
if (isset($_POST['sessionupdate'])) {
    $_SESSION['glpi_plugin_monitoring']['_refresh'] = $_POST['_refresh'];
    glpi_header($_SERVER['HTTP_REFERER']);
    exit;
}
if (isset($_POST["plugin_monitoring_timezone"])) {
    $_SESSION['plugin_monitoring_timezone'] = $_POST["plugin_monitoring_timezone"];
    glpi_header($_SERVER['HTTP_REFERER']);
}
$pMonitoringDisplay = new PluginMonitoringDisplay();
if (isset($_GET['itemtype']) and isset($_GET['items_id'])) {
    $pMonitoringDisplay->refreshPage();
    echo '<meta http-equiv ="refresh" content="' . $_SESSION['glpi_plugin_monitoring']['_refresh'] . '">';
    $pmServicegraph = new PluginMonitoringServicegraph();
    $pmServicegraph->parseToDB($_GET['items_id']);
    $pMonitoringDisplay->displayGraphs($_GET['itemtype'], $_GET['items_id']);
}
commonFooter();
   function showSyntheseReport($componentscatalogs_id) {
      global $CFG_GLPI;

      if (!isset($_SESSION['glpi_plugin_monitoring']['synthese'])) {
         $_SESSION['glpi_plugin_monitoring']['synthese'] = array();
      }
      if (!isset($_SESSION['glpi_plugin_monitoring']['synthese'][$componentscatalogs_id])) {
         $_SESSION['glpi_plugin_monitoring']['synthese'][$componentscatalogs_id] = array();
      }
      $sess = $_SESSION['glpi_plugin_monitoring']['synthese'][$componentscatalogs_id];
      $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component();
      $pmComponent = new PluginMonitoringComponent();
      $a_options = array();

      $this->getFromDB($componentscatalogs_id);

      echo "<form name='form' method='post'
         action='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/report_componentscatalog.form.php'>";

      echo "<table class='tab_cadre_fixe'>";
      echo '<tr class="tab_bg_1">';
      echo '<th colspan="5">';
      echo __('Report');
      echo "<input type='hidden' name='componentscatalogs_id' value='".$componentscatalogs_id."' />";
      echo "<input type='hidden' name='reporttype' value='synthese' />";
      $a_options['componentscatalogs_id'] = $componentscatalogs_id;
      echo '</th>';
      echo '</tr>';

      echo '<tr class="tab_bg_1">';
      echo '<td>';
      echo '</td>';
      echo '<td colspan="2">';
      $default_value = 12;
      if (isset($sess['synthesenumber'])) {
         $default_value = $sess['synthesenumber'];
      }
      Dropdown::showNumber("synthesenumber", array(
                'value' => $default_value,
                'min'   => 2,
                'max'   => 30)
      );
      $a_options['synthesenumber'] = $default_value;
      echo "&nbsp;";
      $a_time = array('week' => __('Week'),
                      'month' => __('Month'),
                      'year' => __('Year'));
      $default_value = 'week';
      if (isset($sess['synthesenumber'])) {
         $default_value = $sess['synthesenumber'];
      }
      Dropdown::showFromArray("syntheseperiod", $a_time, array('value' => $default_value));
      $a_options['syntheseperiod'] = $default_value;
      echo '</td>';
      echo "<td>".__('End date')." :</td>";
      echo "<td>";
      $default_value = date('Y-m-d');
      if (isset($sess['synthesedate_end'])) {
         $default_value = $sess['synthesedate_end'];
      }
      Html::showDateFormItem("synthesedate_end", $default_value);
      $a_options['synthesedate_end'] = $default_value;
      echo "</td>";
      echo '</tr>';

      echo "</table>";

      echo "<table class='tab_cadre_fixe'>";
      $a_composants = $pmComponentscatalog_Component->find("`plugin_monitoring_componentscalalog_id`='".$componentscatalogs_id."'");
      foreach ($a_composants as $comp_data) {
         $pmComponent->getFromDB($comp_data['plugin_monitoring_components_id']);

         echo "<tr class='tab_bg_1'>";
         echo "<td width='10'>";
         //echo "<input type='checkbox' name='components_id[]' value='".$pmComponent->getID()."' checked />";
         echo "<input type='hidden' name='components_id[]' value='".$pmComponent->getID()."' />";
         $a_options['components_id'][] = $pmComponent->getID();
         echo "</td>";
         echo "<td>";
         echo $pmComponent->getLink();
         echo "</td>";
         echo "</tr>";

         echo "<tr class='tab_bg_1'>";
         echo "<td width='10'>";
         echo "</td>";
         echo "<td>";

         PluginMonitoringToolbox::loadPreferences($pmComponent->getID());

         $a_perfnames = PluginMonitoringServicegraph::getperfdataNames($pmComponent->fields['graph_template']);
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_3'>";
         echo "<td rowspan='".count($a_perfnames)."' width='90'>";
         echo __('Use for report', 'monitoring')."&nbsp;:";

         echo "</td>";
         $i = 0;
         $j = 0;
         if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->getID()])) {
            foreach ($a_perfnames as $name) {
               $_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->getID()][$name] = 'checked';
            }
         }

         foreach ($a_perfnames as $name) {
            if ($i > 0) {
               echo "<tr class='tab_bg_3'>";
            }
            echo "<td>";
            $checked = "checked";
            if (isset($sess['perfname'])
                 && isset($sess['perfname'][$pmComponent->getID()])) {

               if (isset($sess['perfname'][$pmComponent->getID()])) {
                  $checked = "";
               }
               if (isset($sess['perfname'][$pmComponent->getID()][$name])) {
                  $checked = "checked";
               }
            } else {
               if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->getID()])) {
                  $checked = "";
               }
               if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->getID()][$name])) {
                  $checked = $_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->getID()][$name];
               }
            }
            echo "<input type='checkbox' name='perfname[".$pmComponent->getID()."][".$name."]' value='".$name."' ".$checked."/> ".$name;
            if ($checked == 'checked') {
               $a_options['perfname'][$pmComponent->getID()][] = $name;
            }
            echo "</td>";
            echo "<td>";
            echo __('Best is high value', 'monitoring').' :';
            echo "</td>";
            echo "<td>";
            $default_value = 1;
            if (isset($sess['perfname_val'])
                 && isset($sess['perfname_val'][$pmComponent->getID()])) {

               if (isset($sess['perfname_val'][$pmComponent->getID()][$name])) {
                  $default_value = $sess['perfname_val'][$pmComponent->getID()][$name];
               }
            }
            Dropdown::showYesNo('perfname_val['.$pmComponent->getID().']['.$name.']', $default_value);
            if ($checked == 'checked') {
               $a_options['perfname_val'][$pmComponent->getID()][$name] = $default_value;
            }
            echo "</td>";
            echo "</tr>";
            $i++;
         }

         echo "</table>";

         echo "</td>";

         echo "</tr>";
      }
      echo "<tr class='tab_bg_1'>";
      echo "<td colspan='2' align='center'>";
      echo "<input type='submit' class='submit' name='update' value='".__('Save')."'/>";
      echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <input type='submit' class='submit' name='generatepdf' value='".__('Generate PDF', 'monitoring')."'/>";
      echo "</td>";
      echo "</tr>";
      echo "</table>";

      Html::closeForm();

      if (isset($_SESSION['plugin_monitoring_report'])) {
//         $a_options = $_SESSION['plugin_monitoring_report'];
      }
      $this->generateSyntheseReport(
              $_SESSION['glpi_plugin_monitoring']['synthese'][$componentscatalogs_id],
              FALSE);
   }
 function show_panel($id, $config)
 {
     global $DB, $CFG_GLPI;
     $pmDisplayview = new PluginMonitoringDisplayview();
     $pmDisplayview->getFromDB($id);
     $queryitems = "SELECT * FROM `glpi_plugin_monitoring_displayviews_items`\n         WHERE `plugin_monitoring_displayviews_id`='" . $id . "'";
     $resultitems = $DB->query($queryitems);
     $a_items = array();
     while ($dataitems = $DB->fetch_array($resultitems)) {
         //         if ($this->displayItem($dataitems, $config)) {
         $a_items[] = $dataitems;
         //         }
         //         }
     }
     echo "\n      <script type=\"text/javascript\">\n      \$(function() {\n      ";
     foreach ($a_items as $item) {
         if ($config == '1') {
             $event = ", stop: function() {\n                 pos = \$('#draggable" . $item['id'] . "').position();\n                 \$.get('" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/displayview_itemcoordinates.php" . "?id=" . $item['id'] . "&x=' + pos.left + '&y=' + pos.top);\n               }";
         } else {
             $event = '';
         }
         $size = $this->getSizeOfWidget($item['itemtype']);
         echo "\$( \"#draggable" . $item['id'] . "\" ).draggable({ cursor: 'move', cursorAt: { " . "top: " . $size['height'] / 2 . ", left: " . $size['width'] / 2 . ", " . " }, grid: [ 10, 10 ]" . $event . " } );";
     }
     echo "\n      });\n      </script>";
     echo "<div id='viewform' style='width: " . $pmDisplayview->fields['width'] . "px;height:1200px;position: relative;'>";
     foreach ($a_items as $item) {
         $itemtype2 = '';
         $size = $this->getSizeOfWidget($item['itemtype']);
         echo '<div id="draggable' . $item['id'] . '" ';
         if ($item['itemtype'] != 'PluginMonitoringServicescatalog' && $item['itemtype'] != 'PluginMonitoringComponentscatalog' && $item['itemtype'] != 'PluginMonitoringDisplayview' && $item['itemtype'] != 'host' && !($item['itemtype'] == 'PluginMonitoringWeathermap' && $item['items_id'] == -1)) {
             echo 'class="ui-widget-content" ';
         }
         if ($item['itemtype'] == 'host' || $item['itemtype'] == 'service') {
             $itemtype2 = $item['itemtype'];
             $item['itemtype'] = 'PluginMonitoringDisplayview';
         }
         if ($item['itemtype'] == 'PluginMonitoringService') {
             echo 'style="width: ' . $size['width'] . 'px; height: ' . $size['height'] . 'px; ' . 'position: absolute; left: ' . $item['x'] . 'px; top: ' . $item['y'] . 'px;">';
             $pmComponent = new PluginMonitoringComponent();
             $pmService = new PluginMonitoringService();
             if ($pmService->getFromDB($item['items_id'])) {
                 $pmComponent->getFromDB($pmService->fields['plugin_monitoring_components_id']);
                 $pmServicegraph = new PluginMonitoringServicegraph();
                 $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $item['items_id'], "0", $item['extra_infos'], "", $size['width'] - 15);
             } else {
                 $this->delete($item);
             }
         } else {
             if ($item['itemtype'] == 'PluginMonitoringWeathermap') {
                 if ($item['items_id'] == -1) {
                     $title = " : " . __('Legend', 'monitoring');
                     echo 'style="width: 400px; height: 51px; ' . 'position: absolute; left: ' . $item['x'] . 'px; top: ' . $item['y'] . 'px;">';
                 } else {
                     $weathermap = new PluginMonitoringWeathermap();
                     $weathermap->getFromDB($item['items_id']);
                     //            $title .= " : ".Dropdown::getDropdownName(
                     //                     getTableForItemType('PluginMonitoringWeathermap'), $item['items_id']);
                     $width = $weathermap->fields['width'] * $item['extra_infos'] / 100;
                     $height = $weathermap->fields['height'] * $item['extra_infos'] / 100;
                     echo 'style="width: ' . $width . 'px; height: ' . $height . 'px; ' . 'position: absolute; left: ' . $item['x'] . 'px; top: ' . $item['y'] . 'px;">';
                 }
                 echo '<div id="weathermap-' . $item['items_id'] . '"></div>';
                 echo "<script type=\"text/javascript\">\n                  (function worker() {\n                    \$.get('" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/widgetWeathermap.php?" . "id=" . $item['items_id'] . "&extra_infos=" . $item['extra_infos'] . "&glpiID=" . $_SESSION['glpiID'] . "', function(data) {\n                      \$('#weathermap-" . $item['items_id'] . "').html(data);\n                      setTimeout(worker, 50000);\n                    });\n                  })();\n               </script>";
             } else {
                 if ($item['itemtype'] == "PluginMonitoringDisplayview") {
                     echo 'style="width: ' . $size['width'] . 'px; height: ' . $size['height'] . 'px; ' . 'position: absolute; left: ' . $item['x'] . 'px; top: ' . $item['y'] . 'px;">';
                     $pmDisplayview = new PluginMonitoringDisplayview();
                     if (!empty($itemtype2)) {
                         echo "<div id=\"updatedisplayview" . $item['id'] . "\"></div>";
                         $pmDisplayview->ajaxLoad2($item['id'], $item['is_minemap']);
                     } else {
                         echo "<div id=\"updatedisplayview" . $item['items_id'] . "\"></div>";
                         $pmDisplayview->ajaxLoad($item['items_id']);
                     }
                 } else {
                     echo 'style="width: ' . $size['width'] . 'px; height: ' . $size['height'] . 'px; ' . 'position: absolute; left: ' . $item['x'] . 'px; top: ' . $item['y'] . 'px;">';
                     echo "<div id=\"update" . $item['itemtype'] . $item['items_id'] . "\"></div>";
                     echo "<script type=\"text/javascript\">";
                     echo "\n                     (function worker() {\n                       \$.get('" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/updateWidgetComponentscatalog.php" . "?id=" . $item['items_id'] . "&is_minemap=" . $item['is_minemap'] . "', function(data) {\n                         \$('#update" . $item['itemtype'] . $item['items_id'] . "').html(data);\n                         setTimeout(worker, 30000);\n                       });\n                     })();";
                     echo "</script>";
                 }
             }
         }
         echo '</div>';
     }
     //      echo "<script type='text/javascript'>
     //
     //        //Simple 'border layout' panel to house both grids
     //        var displayPanel = new Ext.Panel({
     //          id       : 'viewpanel',
     //          width    : ".$pmDisplayview->fields['width'].",
     //          height   : 1200,
     //          layout: 'absolute',
     //          renderTo : 'panel',
     //          items    : []
     //        });
     //
     //      </script>";
     echo "</div>";
     echo "<script type=\"text/javascript\">\n         function reloadview() {\n              \$.get('" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/loadView.php?id=' + \$('#updateviewid').val() + '&config=" . $config . "', function(data) {\n                \$('#viewform').html(data);\n               });\n         }\n      </script>";
 }
示例#6
0
 function displayGraphs($itemtype, $items_id)
 {
     global $CFG_GLPI;
     $pmComponent = new PluginMonitoringComponent();
     $pmConfig = new PluginMonitoringConfig();
     $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
     $item = new $itemtype();
     $item->getFromDB($items_id);
     $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
     if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
         PluginMonitoringServicegraph::loadPreferences($pmComponent->fields['id']);
     }
     $css_width = '950';
     if (isset($_GET['mobile'])) {
         $css_width = '300';
     }
     echo "<table class='tab_cadre' width='" . $css_width . "'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>";
     $title = Dropdown::getDropdownName(getTableForItemType('PluginMonitoringComponent'), $item->fields['plugin_monitoring_components_id']);
     $title .= ' ' . __('on', 'monitoring') . ' ';
     $pmComponentscatalog_Host->getFromDB($item->fields["plugin_monitoring_componentscatalogs_hosts_id"]);
     if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') {
         $itemtype2 = $pmComponentscatalog_Host->fields['itemtype'];
         $item2 = new $itemtype2();
         $item2->getFromDB($pmComponentscatalog_Host->fields['items_id']);
         $title .= str_replace("'", "\"", $item2->getLink() . " (" . $item2->getTypeName() . ")");
     }
     echo $title;
     echo "</th>";
     echo "<th width='200'>";
     if (!isset($_GET['mobile'])) {
         echo "<form method='post'>";
         $a_timezones = PluginMonitoringConfig::getTimezones();
         if (!isset($_SESSION['plugin_monitoring_timezone'])) {
             $_SESSION['plugin_monitoring_timezone'] = '0';
         }
         $a_timezones_allowed = array();
         $pmConfig->getFromDB(1);
         $a_temp = importArrayFromDB($pmConfig->fields['timezones']);
         foreach ($a_temp as $key) {
             $a_timezones_allowed[$key] = $a_timezones[$key];
         }
         if (count($a_timezones_allowed) == '0') {
             $a_timezones_allowed['0'] = $a_timezones['0'];
         }
         Dropdown::showFromArray('plugin_monitoring_timezone', $a_timezones_allowed, array('value' => $_SESSION['plugin_monitoring_timezone']));
         echo "&nbsp;<input type='submit' name='update' value=\"" . __('Save') . "\" class='submit'>";
         Html::closeForm();
     }
     echo "</th>";
     echo "</tr>";
     $timezone = '0';
     if (isset($_SESSION['plugin_monitoring_timezone'])) {
         $timezone = $_SESSION['plugin_monitoring_timezone'];
     }
     if (!isset($_GET['mobile'])) {
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>";
         echo "<div id='legendlink'><a onClick='Ext.get(\"options\").toggle();'>[ Options ]</a></div>";
         echo "</th>";
         echo "</tr>";
         // * Display perfname
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='2'>";
         echo "<div id='options' style='display:none'>";
         PluginMonitoringServicegraph::preferences($pmComponent->fields['id'], 0);
         echo "</div>";
         echo "</td>";
         echo "</tr>";
         // * Display date slider
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>";
         echo __('Select date (only last 2, 12 and 24 hours)', 'monitoring');
         echo "</th>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='2'>";
         $end = time();
         $oldvalue = current(getAllDatasFromTable('glpi_plugin_monitoring_serviceevents', "`plugin_monitoring_services_id`='" . $items_id . "'", false, 'date ASC LIMIT 1'));
         $date = new DateTime($oldvalue['date']);
         $start = $date->getTimestamp();
         $pmServicegraph = new PluginMonitoringServicegraph();
         echo "\n<script type=\"text/javascript\">\n\nExt.onReady(function(){\n\n    var tip = new Ext.slider.Tip({\n        getText: function(thumb){\n            return String.format('<b> ' + new Date(thumb.value * 1000).format('Y-m-d') + '</b>');\n        }\n    });\n\n    new Ext.Slider({\n        renderTo: 'custom-tip-slider',\n        width: 940,\n        increment: 86400,\n        minValue: " . $start . ",\n        maxValue: " . $end . ",\n        value: " . $end . ",\n        plugins: tip,\n        listeners: {\n            dragend: function(slider, thumb, value){\n               document.getElementById('custom_date').textContent = slider.getValue();\n               mgr" . $items_id . "2h.stopAutoRefresh();\n               mgr" . $items_id . "12h.stopAutoRefresh();\n               mgr" . $items_id . "1d.stopAutoRefresh();\n                  ";
         $a_graphlist = array('2h', '12h', '1d');
         foreach ($a_graphlist as $time) {
             $pmServicegraph->startAutoRefresh($pmComponent->fields['graph_template'], $itemtype, $items_id, $timezone, $time, $pmComponent->fields['id']);
         }
         echo "\n            }\n        }\n    });\n\n});\n</script>";
         echo '<center><div id="custom-tip-slider"></div></center>';
         echo '<div id="custom_date" style="display:none"></div>';
         echo "</td>";
         echo "</tr>";
         // * Display time slider
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>";
         echo __('Select time (only last 2, 12 and 24 hours)', 'monitoring');
         echo "</th>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='2'>";
         $start = 0 + 86400 - 3600;
         $end = 86400 + 86400 - 3600 - 300;
         $current = mktime(date('H'), date('i'), 0, 1, 2, 1970);
         echo "\n<script type=\"text/javascript\">\n\nExt.onReady(function(){\n\n    var tiptime = new Ext.slider.Tip({\n        getText: function(thumb){\n            return String.format('<b> ' + new Date(thumb.value * 1000).format('H:i:s') + '</b>');\n        }\n    });\n\n    new Ext.Slider({\n        renderTo: 'custom-tip-slider-time',\n        width: 940,\n        increment: 300,\n        minValue: " . $start . ",\n        maxValue: " . $end . ",\n        value: " . $current . ",\n        plugins: tiptime,\n        listeners: {\n            dragend: function(slider, thumb, value){\n               document.getElementById('custom_time').textContent = slider.getValue();\n               mgr" . $items_id . "2h.stopAutoRefresh();\n               mgr" . $items_id . "12h.stopAutoRefresh();\n               mgr" . $items_id . "1d.stopAutoRefresh();\n                  ";
         $a_graphlist = array('2h', '12h', '1d');
         foreach ($a_graphlist as $time) {
             $pmServicegraph->startAutoRefresh($pmComponent->fields['graph_template'], $itemtype, $items_id, $timezone, $time, $pmComponent->fields['id']);
         }
         echo "\n            }\n        }\n    });\n});\n</script>";
         echo '<center><div id="custom-tip-slider-time"></div></center>';
         echo '<div id="custom_time" style="display:none"></div>';
         echo "</td>";
         echo "</tr>";
     }
     $a_list = array();
     $a_list["2h"] = __("Last 2 hours", "monitoring");
     $a_list["12h"] = __("Last 12 hours", "monitoring");
     $a_list["1d"] = __("Last 24 hours", "monitoring");
     if (!isset($_GET['mobile'])) {
         $a_list["1w"] = __("Last 7 days (average)", "monitoring");
         $a_list["1m"] = __("Last month (average)", "monitoring");
         $a_list["0y6m"] = __("Last 6 months (average)", "monitoring");
         $a_list["1y"] = __("Last year (average)", "monitoring");
     }
     foreach ($a_list as $time => $name) {
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>";
         echo $name;
         echo "</th>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td align='center' colspan='2'>";
         $pmServicegraph = new PluginMonitoringServicegraph();
         $part = '';
         $width = '950';
         if (isset($_GET['mobile'])) {
             $width = '294';
         }
         $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], $itemtype, $items_id, $timezone, $time, $part, $width);
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
 }
   function generateAllGraphs($weathermaps_id) {
      global $DB;

      $pmServicegraph = new PluginMonitoringServicegraph();
      $pmComponent = new PluginMonitoringComponent();

      $cache = array();

      $query = "SELECT * FROM `glpi_plugin_monitoring_weathermaplinks`
         LEFT JOIN `glpi_plugin_monitoring_weathermapnodes`
            ON `glpi_plugin_monitoring_weathermapnodes`.`id`=`plugin_monitoring_weathermapnodes_id_1`
         LEFT JOIN `glpi_plugin_monitoring_services`
            ON `glpi_plugin_monitoring_services`.`id`=`plugin_monitoring_services_id`
         WHERE `plugin_monitoring_weathermaps_id`='".$weathermaps_id."'";
      $result = $DB->query($query);
      while ($data=$DB->fetch_array($result)) {

         $graph_template = 0;
         if (isset($cache[$data['plugin_monitoring_components_id']])) {
            $graph_template = $cache[$data['plugin_monitoring_components_id']];
         } else {
            $pmComponent->getFromDB($data['plugin_monitoring_components_id']);
            $cache[$data['plugin_monitoring_components_id']] = $pmComponent->fields['graph_template'];
            $graph_template = $pmComponent->fields['graph_template'];
         }

         $pmServicegraph->displayGraph($graph_template,
                                       "PluginMonitoringService",
                                       $data['plugin_monitoring_services_id'],
                                       0,
                                       '2h');

      }
   }
示例#8
0
   function slideSlider($id) {
      global $CFG_GLPI, $DB;

      echo "<script type='text/javascript'>
         function fittext(itemid) {
            document.getElementById(itemid).style.fontSize = '50px';
            var fontsize = 50;
            while(document.getElementById(itemid).offsetWidth > 120) {
               fontsize--;
               if (fontsize > 20) {
                  fontsize--;
               }
               document.getElementById(itemid).style.fontSize = fontsize + 'px';
            }
            while(document.getElementById(itemid).offsetHeight > 67) {
               fontsize--;
               document.getElementById(itemid).style.fontSize = fontsize + 'px';
            }
            if (fontsize > 30) {
               document.getElementById(itemid).style.fontSize = '30px';
            }
            if (fontsize < 7) {
               document.getElementById(itemid).style.fontSize = '7px';
            }
         }
      </script>";
      PluginMonitoringToolbox::loadLib();

      $this->getFromDB($id);
      echo '<div id="custom_date" style="display:none"></div>';
      echo '<div id="custom_time" style="display:none"></div>';

      echo '<script src="'.$CFG_GLPI["root_doc"].'/plugins/monitoring/lib/slider.js-14/js/jssor.slider.mini.js"></script>
<script>
    jQuery(document).ready(function ($) {
        //Define an array of slideshow transition code
        var _SlideshowTransitions = [
        {$Duration:0001,$Opacity:2}
        ];
        var options = {
            $AutoPlay: true,
            $AutoPlayInterval: '.$this->fields['duration'].'000,
            $SlideshowOptions: {
                    $Class: $JssorSlideshowRunner$,
                    $Transitions: _SlideshowTransitions,
                    $TransitionsOrder: 1,
                    $ShowLink: true
        }
        };
        var jssor_slider1 = new $JssorSlider$(\'slider1_container\', options);
    });
</script>';
      echo "<table class='tab_cadre'>";

      echo "<tr>";
      echo "<td>";

      $query = "SELECT * FROM `glpi_plugin_monitoring_sliders_items`
              WHERE `plugin_monitoring_sliders_id`='".$id."'";

      $result = $DB->query($query);
      $maxWidth = 0;
      $maxHeight = 0;
      $is_minemap = 0;
      while ($data=$DB->fetch_array($result)) {
         if ($data['itemtype'] == 'PluginMonitoringServicescatalog'
                 || $data['itemtype'] == 'PluginMonitoringComponentscatalog'
                 || $data['itemtype'] == 'PluginMonitoringCustomitem_Gauge'
                 || $data['itemtype'] == 'PluginMonitoringCustomitem_Counter') {
            if ($maxWidth < 180) {
               $maxWidth = 180;
            }
            if ($maxHeight < 180) {
               $maxHeight = 180;
            }
            if ($data['is_minemap'] == 1) {
               $is_minemap = 1;
            }
         } else if ($data['itemtype'] == 'PluginMonitoringService') {
            if ($maxWidth < 475) {
               $maxWidth = 475;
            }
            if ($maxHeight < 330) {
               $maxHeight = 330;
            }
         } else if ($data['itemtype'] == "PluginMapsMap") {
            if ($maxWidth < 950) {
               $maxWidth = 950;
            }
            if ($maxHeight < 800) {
               $maxHeight = 800;
            }
         } else {
            $itemtype = $data['itemtype'];
            $item = new $itemtype();
            $item->getFromDB($data['items_id']);
            if ($maxWidth < $item->fields['width']) {
               $maxWidth = $item->fields['width'];
            }
            if (isset($item->fields['height'])) {
               if ($maxHeight < $item->fields['width']) {
                  $maxHeight = $item->fields['height'];
               }
            }
         }
      }
      if ($is_minemap) {
         $maxHeight = '1500';
      }

      $pm = new PluginMonitoringComponentscatalog();
      echo '<div id="slider1_container" style="position: relative;
top: 0px; left: 0px; width: '.$maxWidth.'px; height: '.$maxHeight.'px;">
    <!-- Slides Container -->
    <div u="slides" style="cursor: move; position: absolute; overflow: hidden;
    left: 0px; top: 0px; width: '.$maxWidth.'px; height: '.$maxHeight.'px;">';

      $result = $DB->query($query);
      while ($data=$DB->fetch_array($result)) {
         $itemtype = $data['itemtype'];
         $item = new $itemtype();
         if ($itemtype == "PluginMonitoringService") {
            echo '<div>';
            echo $item->showWidget($data['items_id'], $data['extra_infos']);
            echo '</div>';
         } else if ($itemtype == "PluginMonitoringWeathermap") {
            echo '<div>';
            echo '<div id="weathermap-'.$data['items_id'].'"></div>';
            echo '</div>';
         } else if ($itemtype == 'PluginMonitoringDisplayview') {
            echo '<div>';
            $pmDisplayview_item = new PluginMonitoringDisplayview_item();
            echo $pmDisplayview_item->view($data['items_id']);
            echo '</div>';
         } else if ($itemtype == "PluginMapsMap") {
            echo '<div>';
            echo '<div id="pluginmap"></div>';
            echo '</div>';
         } else {
            echo '<div>';
            echo $item->showWidget($data['items_id']);
            echo '</div>';
         }

      }
echo '    </div>
</div>';
      $result = $DB->query($query);
      while ($data=$DB->fetch_array($result)) {
         $itemtype = $data['itemtype'];
         $item = new $itemtype();
         // Ajax
         if ($itemtype == "PluginMonitoringService") {
            $pmComponent = new PluginMonitoringComponent();
            $item = new $itemtype();

            $item->getFromDB($data['items_id']);
            $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
            $pmServicegraph = new PluginMonitoringServicegraph();
            $pmServicegraph->displayGraph($pmComponent->fields['graph_template'],
                                          "PluginMonitoringService",
                                          $data['items_id'],
                                          "0",
                                          $data['extra_infos'],
                                          "js");
         } else if($itemtype == "PluginMonitoringComponentscatalog") {
            $pmComponentscatalog = new PluginMonitoringComponentscatalog();
            $pmComponentscatalog->ajaxLoad($data['items_id'], $data['is_minemap']);
         } else if($itemtype == "PluginMonitoringServicescatalog") {
            $pmServicescatalog = new PluginMonitoringServicescatalog();
            $pmServicescatalog->ajaxLoad($data['items_id']);
         } else if($itemtype == "PluginMonitoringDisplayview") {

         } else if($itemtype == "PluginMonitoringCustomitem_Gauge") {
            $pmCustomitem_Gauge = new PluginMonitoringCustomitem_Gauge();
            $pmCustomitem_Gauge->ajaxLoad($data['items_id']);
         } else if($itemtype == "PluginMonitoringCustomitem_Counter") {
            $pmCustomitem_Counter = new PluginMonitoringCustomitem_Counter();
            $pmCustomitem_Counter->ajaxLoad($data['items_id']);
         }
         if ($itemtype == "PluginMonitoringWeathermap") {
            $sess_id = session_id();
            PluginMonitoringSecurity::updateSession();

            echo "<script type='text/javascript'>
            var mgr = new Ext.UpdateManager('weathermap-".$data['items_id']."');
            mgr.startAutoRefresh(50, \"".$CFG_GLPI["root_doc"].
                    "/plugins/monitoring/ajax/widgetWeathermap.php\","
                    . " \"id=".$data['items_id']."&extra_infos=".
                    $data['extra_infos']."&sess_id=".$sess_id.
                    "&glpiID=".$_SESSION['glpiID'].
                    "&plugin_monitoring_securekey=".$_SESSION['plugin_monitoring_securekey'].
                    "\", \"\", true);
            </script>";
         }
         if ($itemtype == "PluginMapsMap") {
            $sess_id = session_id();
            PluginMonitoringSecurity::updateSession();

            echo "<script type='text/javascript'>
            var mgr = new Ext.UpdateManager('pluginmap');
            mgr.startAutoRefresh(50, \"".$CFG_GLPI["root_doc"].
                    "/plugins/monitoring/ajax/widgetPluginmap.php\","
                    . " \"extra_infos=".
                    $data['extra_infos']."&sess_id=".$sess_id.
                    "&glpiID=".$_SESSION['glpiID'].
                    "&plugin_monitoring_securekey=".$_SESSION['plugin_monitoring_securekey'].
                    "\", \"\", true);
            </script>";
         }
      }
      echo "</td>";
      echo "</tr>";
      echo "</table>";
   }
 function showReport($componentscatalogs_id)
 {
     global $CFG_GLPI;
     $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component();
     $pmComponent = new PluginMonitoringComponent();
     $this->getFromDB($componentscatalogs_id);
     echo "<form name='form' method='post' \n         action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/report_componentscatalog.form.php'>";
     echo "<table class='tab_cadre_fixe'>";
     echo '<tr class="tab_bg_1">';
     echo '<th colspan="5">';
     echo __('Report');
     echo "<input type='hidden' name='componentscatalogs_id' value='" . $componentscatalogs_id . "' />";
     echo '</th>';
     echo '</tr>';
     // ** simple report
     echo '<tr class="tab_bg_1">';
     echo '<tr class="tab_bg_1">';
     echo '<td>';
     echo '<input type="radio" name="reporttype" value="simplereport" checked />';
     echo '</td>';
     echo '<td colspan="4">';
     echo '<strong>' . __('Simple report', "monitoring") . '</strong>';
     echo '</td>';
     echo '</tr>';
     echo '<tr class="tab_bg_1">';
     echo '<td>';
     echo '</td>';
     echo "<td>" . __('Start date') . " :</td>";
     echo "<td>";
     Html::showDateFormItem("date_start", date('Y-m-d H:i:s', date('U') - 24 * 3600 * 7));
     echo "</td>";
     echo "<td>" . __('End date') . " :</td>";
     echo "<td>";
     Html::showDateFormItem("date_end", date('Y-m-d'));
     echo "</td>";
     echo "</tr>";
     // ** synthese
     echo '<tr class="tab_bg_1">';
     echo '<td>';
     echo '<input type="radio" name="reporttype" value="synthese" />';
     echo '</td>';
     echo '<td colspan="4">';
     echo '<strong>' . __('Synthese', "monitoring") . '</strong>';
     echo '</td>';
     echo '</tr>';
     echo '<tr class="tab_bg_1">';
     echo '<td>';
     echo '</td>';
     echo '<td colspan="2">';
     Dropdown::showNumber("synthesenumber", array('value' => 12, 'min' => 2, 'max' => 30));
     echo "&nbsp;";
     $a_time = array('week' => __('Week'), 'month' => __('Month'), 'year' => __('Year'));
     Dropdown::showFromArray("syntheseperiod", $a_time);
     echo '</td>';
     echo "<td>" . __('End date') . " :</td>";
     echo "<td>";
     Html::showDateFormItem("synthesedate_end", date('Y-m-d'));
     echo "</td>";
     echo '</tr>';
     // ** synthese ++
     echo '<tr class="tab_bg_1">';
     echo '<td>';
     echo '<input type="radio" name="reporttype" value="syntheseplus" />';
     echo '</td>';
     echo '<td colspan="4">';
     echo '<strong>' . __('Synthese detail', "monitoring") . '</strong>';
     echo '</td>';
     echo '</tr>';
     echo '<tr class="tab_bg_1">';
     echo '<td>';
     echo '</td>';
     echo '<td colspan="2">';
     Dropdown::showNumber("syntheseplusnumber", array('value' => 12, 'min' => 2, 'max' => 30));
     echo "&nbsp;";
     $a_time = array('week' => __('Week'), 'month' => __('Month'), 'year' => __('Year'));
     Dropdown::showFromArray("syntheseplusperiod", $a_time);
     echo '</td>';
     echo "<td>" . __('End date') . " :</td>";
     echo "<td>";
     Html::showDateFormItem("syntheseplusdate_end", date('Y-m-d'));
     echo "</td>";
     echo '</tr>';
     echo "</table>";
     echo "<table class='tab_cadre_fixe'>";
     $a_composants = $pmComponentscatalog_Component->find("`plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'");
     foreach ($a_composants as $comp_data) {
         $pmComponent->getFromDB($comp_data['plugin_monitoring_components_id']);
         echo "<tr class='tab_bg_1'>";
         echo "<td width='10'>";
         echo "<input type='checkbox' name='components_id[]' value='" . $pmComponent->getID() . "' checked />";
         echo "</td>";
         echo "<td>";
         echo $pmComponent->getLink();
         echo "</td>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td width='10'>";
         echo "</td>";
         echo "<td>";
         PluginMonitoringServicegraph::preferences($pmComponent->getID(), 1, 1);
         echo "</td>";
         echo "</tr>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='2' align='center'>";
     echo "<input type='submit' class='submit' name='generate' value='" . __('Generate the report', 'monitoring') . "'/>";
     echo "</td>";
     echo "</tr>";
     Html::closeForm();
 }
  @package   Plugin Monitoring for GLPI
  @author    David Durieux
  @co-author
  @comment
  @copyright Copyright (c) 2011-2014 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     2011

  ------------------------------------------------------------------------
*/
include "../../../inc/includes.php";
Session::checkLoginUser();
$docDir = GLPI_PLUGIN_DOC_DIR . '/monitoring';
if (isset($_GET['file'])) {
    $filename = $_GET['file'];
    $file = $docDir . '/' . $filename;
    if (preg_match("/PluginMonitoringService-([0-9]+)-2h([0-9]+).png/", $filename)) {
        include GLPI_ROOT . "/inc/includes.php";
        $match = array();
        preg_match("/PluginMonitoringService-([0-9]+)-2h([0-9]+).png/", $filename, $match);
        $pmServicegraph = new PluginMonitoringServicegraph();
        $pmService = new PluginMonitoringService();
        $pmComponent = new PluginMonitoringComponent();
        $pmService->getFromDB($match[1]);
        $pmComponent->getFromDB($pmService->fields['plugin_monitoring_components_id']);
        $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $match[1], $match[2], '2h');
    }
    Toolbox::sendFile($file, $filename);
}
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
session_write_close();
if (!defined('GLPI_ROOT')) {
    die("Can not acces directly to this file");
}
Session::checkLoginUser();
$itemtype = $_GET['itemtype'];
$item = new $itemtype();
if (!$item->getFromDB($_GET['items_id'])) {
    echo json_encode(array());
    //   echo __('Item not exist', 'monitoring');
    exit;
}
$pmServicegraph = new PluginMonitoringServicegraph();
$enddate = '';
if ($_GET['customdate'] == '' && $_GET['customtime'] == '') {
    $enddate = '';
} else {
    if ($_GET['customdate'] == '') {
        $enddate = mktime(date('H', $_GET['customtime']), date('i', $_GET['customtime']), date('s', $_GET['customtime']));
    } else {
        if ($_GET['customtime'] == '') {
            $enddate = $_GET['customdate'];
        } else {
            // have the 2 defined
            $enddate = mktime(date('H', $_GET['customtime']), date('i', $_GET['customtime']), date('s', $_GET['customtime']), date('n', $_GET['customdate']), date('d', $_GET['customdate']), date('Y', $_GET['customdate']));
        }
    }
}
示例#12
0
*/
// ----------------------------------------------------------------------
// Original Author of file: David DURIEUX
// Purpose of file:
// ----------------------------------------------------------------------
// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "updateChart.php")) {
    include "../../../inc/includes.php";
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
if (!defined('GLPI_ROOT')) {
    die("Can not acces directly to this file");
}
Session::checkLoginUser();
$pmServicegraph = new PluginMonitoringServicegraph();
$enddate = '';
if ($_POST['customdate'] == '' && $_POST['customtime'] == '') {
    $enddate = '';
} else {
    if ($_POST['customdate'] == '') {
        $enddate = mktime(date('H', $_POST['customtime']), date('i', $_POST['customtime']), date('s', $_POST['customtime']));
    } else {
        if ($_POST['customtime'] == '') {
            $enddate = $_POST['customdate'];
        } else {
            // have the 2 defined
            $enddate = mktime(date('H', $_POST['customtime']), date('i', $_POST['customtime']), date('s', $_POST['customtime']), date('n', $_POST['customdate']), date('d', $_POST['customdate']), date('Y', $_POST['customdate']));
        }
    }
}
示例#13
0
 static function cronUpdaterrd()
 {
     ini_set("max_execution_time", "0");
     //      $pmServiceevent = new PluginMonitoringServiceevent();
     $pmService = new PluginMonitoringService();
     $pmServicegraph = new PluginMonitoringServicegraph();
     $a_lisths = $pmService->find();
     foreach ($a_lisths as $data) {
         $pmServicegraph->parseToDB($data['id']);
     }
     return true;
 }
    static function preferences($components_id, $loadpreferences = 1, $displayonly = 0)
    {
        global $CFG_GLPI;
        if ($loadpreferences == 1) {
            if (!PluginMonitoringToolbox::loadPreferences($components_id)) {
                return false;
            }
        }
        $pmComponent = new PluginMonitoringComponent();
        $pmComponent->getFromDB($components_id);
        $a_perfnames = array();
        $a_perfnames = PluginMonitoringServicegraph::getperfdataNames($pmComponent->fields['graph_template']);
        echo "<table class='tab_cadre_fixe'>";
        echo "<tr class='tab_bg_3'>";
        echo "<td rowspan='" . ceil(count($a_perfnames) / 7) . "' width='90'>";
        echo __('Display', 'monitoring') . "&nbsp;:";
        echo "</td>";
        $i = 0;
        $j = 0;
        if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$components_id])) {
            foreach ($a_perfnames as $name) {
                $_SESSION['glpi_plugin_monitoring']['perfname'][$components_id][$name] = 'checked';
            }
        }
        echo "<td>";
        $a_incremental = array();
        $a_perfdatadetails = getAllDatasFromTable('glpi_plugin_monitoring_perfdatadetails', "plugin_monitoring_perfdatas_id='" . $pmComponent->fields['graph_template'] . "'");
        foreach ($a_perfdatadetails as $data) {
            for ($nb = 1; $nb <= 15; $nb++) {
                if ($data['dsnameincr' . $nb] == '1') {
                    $a_incremental[$data['dsname' . $nb]] = 1;
                }
            }
        }
        $a_list = array();
        $a_list_val = array();
        foreach ($a_perfnames as $name) {
            $a_list[] = $name;
            if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$components_id][$name])) {
                $a_list_val[] = $name;
            }
            if (isset($a_incremental[$name])) {
                $name .= ' | diff';
                if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$components_id][$name])) {
                    $a_list_val[] = $name;
                }
                $a_list[] = $name;
            }
        }
        //      <input name="perfname" id="jquery-tagbox-select" type="text" value="'.implode('####', $a_list_val).'" />';
        echo '      <div id="tagbox-container"></div>';
        echo "        <script>\n            \$('#tagbox-container').tagbox({\n                taglist: ['" . implode("', '", $a_list) . "'],\n                selectedlist: ['" . implode("', '", $a_list_val) . "'],\n                cols: 3,\n                maxtags: 4,\n                expand: true\n            });\n\n            \$('#tagbox-container').on('tagAdded', function() {\n               \$.get('" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/updatePerfname.php" . "?components_id=" . $components_id . "&db=" . $loadpreferences . "&perfname=' + \$('.tagbox').data('selected'));\n            });\n            \$('#tagbox-container').on('tagRemoved', function() {\n               \$.get('" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/updatePerfname.php" . "?components_id=" . $components_id . "&db=" . $loadpreferences . "&perfname=' + \$('.tagbox').data('selected'));\n            });\n        </script>";
        echo "</td>";
        echo "</tr>";
        echo "</table>";
        if ($displayonly == 1) {
            return;
        }
        // * Invert perfname
        $a_perfnames = array();
        $a_perfnames = PluginMonitoringServicegraph::getperfdataNames($pmComponent->fields['graph_template']);
        echo "<table class='tab_cadre_fixe'>";
        echo "<tr class='tab_bg_3'>";
        echo "<td rowspan='" . ceil(count($a_perfnames) / 7) . "' width='90'>";
        echo __('Invert values', 'monitoring') . "&nbsp;:";
        echo "</td>";
        $i = 0;
        $j = 0;
        echo "<td>";
        echo '<select id="jquery-tagbox-select2-options">';
        $a_incremental = array();
        $a_perfdatadetails = getAllDatasFromTable('glpi_plugin_monitoring_perfdatadetails', "plugin_monitoring_perfdatas_id='" . $pmComponent->fields['graph_template'] . "'");
        foreach ($a_perfdatadetails as $data) {
            for ($nb = 1; $nb <= 15; $nb++) {
                if ($data['dsnameincr' . $nb] == '1') {
                    $a_incremental[$data['dsname' . $nb]] = 1;
                }
            }
        }
        $a_list_val2 = array();
        foreach ($a_list_val as $name) {
            $disabled = '';
            if (isset($_SESSION['glpi_plugin_monitoring']['perfnameinvert'][$components_id][$name])) {
                $a_list_val2[] = $name;
                $disabled = 'disabled="disabled"';
            }
            echo '<option value="' . $name . '" ' . $disabled . '>' . $name . '</option>';
            if (isset($a_incremental[$name])) {
                $name .= ' | diff';
                $disabled = '';
                if (isset($_SESSION['glpi_plugin_monitoring']['perfnameinvert'][$components_id][$name])) {
                    $a_list_val[] = $name;
                    $disabled = 'disabled="disabled"';
                }
                echo '<option value="' . $name . '" ' . $disabled . '>' . $name . '</option>';
            }
        }
        echo '</select>
      <input name="perfnameinvert" id="jquery-tagbox-select2" type="text" value="' . implode('####', $a_list_val2) . '" />';
        echo "</td>";
        //      foreach ($a_perfnames as $name) {
        //         if ($i == 'O'
        //                 AND $j == '1') {
        //            echo "<tr>";
        //         }
        //         echo "<td>";
        //         $checked = "";
        //         if (isset($_SESSION['glpi_plugin_monitoring']['perfnameinvert'][$components_id][$name])) {
        //            $checked = $_SESSION['glpi_plugin_monitoring']['perfnameinvert'][$components_id][$name];
        //         }
        //         echo "<input type='checkbox' name='perfnameinvert[]' value='".$name."' ".$checked."/> ".$name;
        //         echo "</td>";
        //         $i++;
        //         if ($i == 6) {
        //            $i = 0;
        //            echo "</tr>";
        //         }
        //         $j = 1;
        //      }
        //      if ($i != 6) {
        //         echo "<td colspan='".(6-$i)."'></td>";
        //         echo "</tr>";
        //      }
        echo "<tr class='tab_bg_3'>";
        echo "<td colspan='9' align='center'>";
        echo "<input type='hidden' name='id' value='" . $components_id . "'/>";
        echo "<input type='submit' name='updateperfdata' value=\"" . __('Save') . "\" class='submit'>";
        echo "</td>";
        echo "</tr>";
        echo "</table>";
        // * Define color of perfname
        $a_perfnames = array();
        $a_perfnames = PluginMonitoringServicegraph::getperfdataNames($pmComponent->fields['graph_template']);
        foreach ($a_perfnames as $key => $name) {
            if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$components_id][$name])) {
                unset($a_perfnames[$key]);
            }
        }
        echo "<table class='tab_cadre_fixe'>";
        echo "<tr class='tab_bg_1'>";
        echo "<td rowspan='" . ceil(count($a_perfnames) / 4) . "' width='90'>";
        echo __('Colors', 'monitoring') . "&nbsp;:";
        echo "</td>";
        $i = 0;
        $j = 0;
        $a_colors_warn = PluginMonitoringServicegraph::colors("warn");
        $a_colors_crit = PluginMonitoringServicegraph::colors("crit");
        $a_colors = PluginMonitoringServicegraph::colors();
        foreach ($a_list_val as $name) {
            if ($i == 'O' and $j == '1') {
                echo "<tr>";
            }
            echo "<td>";
            echo $name . "&nbsp;:";
            echo "</td>";
            echo "<td>";
            $color = 'ffffff';
            if (isset($_SESSION['glpi_plugin_monitoring']['perfnamecolor'][$components_id][$name])) {
                $color = $_SESSION['glpi_plugin_monitoring']['perfnamecolor'][$components_id][$name];
            } else {
                if (strstr($name, "warn")) {
                    $color = array_shift($a_colors_warn);
                } else {
                    if (strstr($name, "crit")) {
                        $color = array_shift($a_colors_crit);
                    } else {
                        $color = array_shift($a_colors);
                    }
                }
            }
            echo ' <input class="color" id="color' . $name . '" name="perfnamecolor[' . $name . ']" value="' . $color . '" size="6" />';
            echo '<script type="text/javascript">
var myPicker = new jscolor.color(document.getElementById(\'color' . $name . '\'), {})
myPicker.fromString(\'' . $color . '\')
</script>
';
            //         echo " <select name='perfnamecolor[".$name."]' id='color".$name."'>";
            //         echo "<option value=''>".Dropdown::EMPTY_VALUE."</option>";
            //         foreach ($a_colors as $color) {
            //            $checked = '';
            //            if (isset($_SESSION['glpi_plugin_monitoring']['perfnamecolor'][$components_id][$name])
            //                    AND $_SESSION['glpi_plugin_monitoring']['perfnamecolor'][$components_id][$name] == $color) {
            //               $checked = 'selected';
            //            }
            //            echo "<option value='".$color."' style='background-color: #".$color.";' ".$checked.">".$color."</option>";
            //         }
            //         echo "</select>";
            echo "</td>";
            $i++;
            if ($i == 4) {
                $i = 0;
                echo "</tr>";
            }
            $j = 1;
        }
        if ($i != 4) {
            echo "<td colspan='" . (4 - $i) * 2 . "'></td>";
            echo "</tr>";
        }
        echo "<tr>";
        echo "<td colspan='9' align='center'>";
        echo "<input type='hidden' name='id' value='" . $components_id . "'/>";
        echo "<input type='submit' name='updateperfdata' value=\"" . __('Save') . "\" class='submit'>";
        echo "</td>";
        echo "</tr>";
        echo "</table>";
        Html::closeForm();
        return true;
    }
    function displayGraph($rrdtool_template, $itemtype, $items_id, $timezone, $time = '1d', $part = '', $width = '900')
    {
        global $CFG_GLPI;
        $pmComponent = new PluginMonitoringComponent();
        //      if (isset($_GET['itemtype'])) {
        //         $itemtype = $_GET['itemtype'];
        //         $items_id = $_GET['items_id'];
        //      }
        $item = new $itemtype();
        if ($item->getFromDB($items_id)) {
            $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
            $ident = $items_id . $time;
            if ($part == '' or $part == 'div') {
                echo '<div id="chart' . $ident . '">' . '<svg style="width: ' . $width . 'px;display: block;height: 300px;"></svg>' . '</div>';
                echo "<div id=\"updategraph" . $items_id . $time . "\"></div>";
            }
            if ($part == '' or $part == 'js') {
                if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
                    PluginMonitoringToolbox::loadPreferences($pmComponent->fields['id']);
                }
                if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
                    $format = '%H:%M';
                } else {
                    if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']][''])) {
                        unset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']]['']);
                    }
                    $pmServicegraph = new PluginMonitoringServicegraph();
                    $a_ret = $pmServicegraph->generateData($rrdtool_template, $itemtype, $items_id, $timezone, $time, '', $_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']]);
                    $format = $a_ret[2];
                }
                echo "<script>";
                echo '

            var formaty = ".0f";
            var data' . $ident . ' = [];
            var chart' . $ident . ';
            redraw' . $ident . ' = function () {
               nv.addGraph(function() {
                  if (typeof data' . $ident . '[0] != "undefined") {
                     formaty = data' . $ident . '[0]["formaty"];
                  }
                  chart' . $ident . ' = nv.models.lineChart();

                  chart' . $ident . '.useInteractiveGuideline(true);

                  chart' . $ident . '.xAxis
                     .tickFormat(function(d) { return d3.time.format("' . $format . '")(new Date(d)); });

                  chart' . $ident . '.yAxis
                     .axisLabel("test")
                     .tickFormat(d3.format(formaty));

                  chart' . $ident . '.forceY([0]);

                  d3.select("#chart' . $ident . ' svg")
                    .attr("height", 300)
                    .datum(data' . $ident . ')
                    .transition().duration(50)
                    .call(chart' . $ident . ');

                 return chart' . $ident . ';
               });
            };';
                echo "\n            (function worker" . $items_id . $time . "() {\n              startDate = new Date(\$('#custom_date').val());\n              startTime = Date.parse('04/03/1980 ' + (\$('#custom_time').val()) + ':00');\n              \$.getJSON('" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/updateChart.php" . "?rrdtool_template=" . $rrdtool_template . "&itemtype=" . $itemtype . "&items_id=" . $items_id . "&timezone=" . $timezone . "&time=" . $time . "&customdate=' + (startDate.getTime()/1000.0) + '" . "&customtime=' + (startTime/1000.0) + '" . "&components_id=" . $pmComponent->fields['id'] . "', function(data) {\n                data" . $ident . " = data;\n\n                var newDate = \$('#custom_date').val() + ' ' + \$('#custom_time').val();\n                var timestamp = new Date(newDate).getTime();\n                if (timestamp > (new Date().getTime() - 3600000)) {\n                    var datenow = new Date();\n                    \$('#custom_time').val(datenow.getHours() + ':' + datenow.getMinutes());\n                    \$('#custom_date').val((datenow.getMonth() + 1) + '/' + datenow.getDate() + '/' + datenow.getFullYear());\n                }\n\n                redraw" . $ident . "();\n                ";
                $refresh = 30;
                // 30 seconds
                if ($time == '12h') {
                    $refresh = 240;
                    // 4 minutes
                } else {
                    if ($time == '1d') {
                        $refresh = 600;
                        // 10 minutes
                    } else {
                        if ($time == '1w') {
                            $refresh = 1800;
                            // 30 minutes
                        }
                    }
                }
                echo "\n                setTimeout(worker" . $items_id . $time . ", " . $refresh . "000);\n              });\n            })();";
                echo "\n            </script>";
            }
        }
        return;
    }
 function displayGraphs($itemtype, $items_id)
 {
     global $CFG_GLPI;
     $pmComponent = new PluginMonitoringComponent();
     $pmConfig = new PluginMonitoringConfig();
     $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
     $networkPort = new NetworkPort();
     $item = new $itemtype();
     $item->getFromDB($items_id);
     $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
     if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
         PluginMonitoringToolbox::loadPreferences($pmComponent->fields['id']);
     }
     $css_width = '950';
     if (isset($_GET['mobile'])) {
         $css_width = '300';
     }
     echo "<table class='tab_cadre' width='" . $css_width . "'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>";
     $title = Dropdown::getDropdownName(getTableForItemType('PluginMonitoringComponent'), $item->fields['plugin_monitoring_components_id']);
     if (!is_null($item->fields['networkports_id']) && $item->fields['networkports_id'] > 0) {
         $networkPort->getFromDB($item->fields['networkports_id']);
         $title .= " [" . $networkPort->getLink() . "]";
     }
     $title .= ' ' . __('on', 'monitoring') . ' ';
     $pmComponentscatalog_Host->getFromDB($item->fields["plugin_monitoring_componentscatalogs_hosts_id"]);
     if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') {
         $itemtype2 = $pmComponentscatalog_Host->fields['itemtype'];
         $item2 = new $itemtype2();
         $item2->getFromDB($pmComponentscatalog_Host->fields['items_id']);
         $title .= str_replace("'", "\"", $item2->getLink() . " (" . $item2->getTypeName() . ")");
     }
     echo $title;
     echo "</th>";
     echo "<th width='200'>";
     if (!isset($_GET['mobile'])) {
         echo "<form method='post'>";
         $a_timezones = PluginMonitoringConfig::getTimezones();
         if (!isset($_SESSION['plugin_monitoring_timezone'])) {
             $_SESSION['plugin_monitoring_timezone'] = '0';
         }
         $a_timezones_allowed = array();
         $pmConfig->getFromDB(1);
         $a_temp = importArrayFromDB($pmConfig->fields['timezones']);
         foreach ($a_temp as $key) {
             $a_timezones_allowed[$key] = $a_timezones[$key];
         }
         if (count($a_timezones_allowed) == '0') {
             $a_timezones_allowed['0'] = $a_timezones['0'];
         }
         Dropdown::showFromArray('plugin_monitoring_timezone', $a_timezones_allowed, array('value' => $_SESSION['plugin_monitoring_timezone']));
         echo "&nbsp;<input type='submit' name='update' value=\"" . __('Save') . "\" class='submit'>";
         Html::closeForm();
     }
     echo "</th>";
     echo "</tr>";
     $timezone = '0';
     if (isset($_SESSION['plugin_monitoring_timezone'])) {
         $timezone = $_SESSION['plugin_monitoring_timezone'];
     }
     if (!isset($_GET['mobile'])) {
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>";
         echo "<div id='legendlink'><a onClick='\$(\"#options\").toggle();'>[ Options ]</a></div>";
         echo "</th>";
         echo "</tr>";
         // * Display perfname
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='2'>";
         echo "<div id='options' style='display:none'>";
         PluginMonitoringToolbox::preferences($pmComponent->fields['id'], 0);
         echo "</div>";
         echo "</td>";
         echo "</tr>";
         // * Display date slider
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>";
         echo __('Select date', 'monitoring') . " - " . __('Select time', 'monitoring');
         echo "</th>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>";
         $start = time();
         $oldvalue = current(getAllDatasFromTable('glpi_plugin_monitoring_serviceevents', "`plugin_monitoring_services_id`='" . $items_id . "'", false, 'date ASC LIMIT 1'));
         $date = new DateTime($oldvalue['date']);
         if ($date->getTimestamp() < $start) {
             $start = $date->getTimestamp();
         }
         $nbdays = round((date('U') - $start) / 86400);
         echo "<script type=\"text/javascript\">\n            \$(function() {\n                \$( \"#custom_date\" ).datepicker({ minDate: -" . $nbdays . ", maxDate: \"+0D\", dateFormat:'mm/dd/yy' });\n                \$( \"#custom_time\" ).timepicker();\n\n            });\n         </script>";
         echo '<center><input type="text" id="custom_date" value="' . date('m/d/Y') . '"> ' . ' <input type="text" id="custom_time" value="' . date('H:i') . '"></center>';
         echo "</th>";
         echo "</tr>";
     }
     $a_list = array();
     $a_list["2h"] = __("Last 2 hours", "monitoring");
     $a_list["12h"] = __("Last 12 hours", "monitoring");
     $a_list["1d"] = __("Last 24 hours", "monitoring");
     $a_list["1w"] = __("Last 7 days (average)", "monitoring");
     //      $a_list["1m"]     = __("Last month (average)", "monitoring");
     //      $a_list["0y6m"]   = __("Last 6 months (average)", "monitoring");
     //      $a_list["1y"]     = __("Last year (average)", "monitoring");
     foreach ($a_list as $time => $name) {
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>";
         echo $name;
         echo "</th>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td align='center' colspan='2' style='position: relative'>";
         $pmServicegraph = new PluginMonitoringServicegraph();
         $part = '';
         $width = '950';
         if (isset($_GET['mobile'])) {
             $width = '294';
         }
         $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], $itemtype, $items_id, $timezone, $time, $part, $width);
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
 }
示例#17
0
 function displayGraphs($itemtype, $items_id)
 {
     global $CFG_GLPI, $LANG;
     $pmComponent = new PluginMonitoringComponent();
     $pmConfig = new PluginMonitoringConfig();
     $item = new $itemtype();
     $item->getFromDB($items_id);
     $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>";
     echo $item->getLink(1);
     echo "</th>";
     echo "<th width='200'>";
     echo "<form method='post'>";
     $a_timezones = PluginMonitoringConfig::getTimezones();
     if (!isset($_SESSION['plugin_monitoring_timezone'])) {
         $_SESSION['plugin_monitoring_timezone'] = '0';
     }
     $a_timezones_allowed = array();
     $pmConfig->getFromDB(1);
     $a_temp = importArrayFromDB($pmConfig->fields['timezones']);
     foreach ($a_temp as $key) {
         $a_timezones_allowed[$key] = $a_timezones[$key];
     }
     if (count($a_timezones_allowed) == '0') {
         $a_timezones_allowed['0'] = $a_timezones['0'];
     }
     Dropdown::showFromArray('plugin_monitoring_timezone', $a_timezones_allowed, array('value' => $_SESSION['plugin_monitoring_timezone']));
     echo "&nbsp;<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\" class='submit'>";
     echo "</form>";
     echo "</th>";
     echo "</tr>";
     $a_list = array();
     $a_list[] = "2h";
     $a_list[] = "12h";
     $a_list[] = "1d";
     $a_list[] = "1w";
     $a_list[] = "1m";
     $a_list[] = "0y6m";
     $a_list[] = "1y";
     foreach ($a_list as $time) {
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>";
         echo $time;
         echo "</th>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td align='center' colspan='2'>";
         $img = '';
         $timezone = '0';
         if (isset($_SESSION['plugin_monitoring_timezone'])) {
             $timezone = $_SESSION['plugin_monitoring_timezone'];
         }
         $timezone_file = str_replace("+", ".", $timezone);
         $pmServicegraph = new PluginMonitoringServicegraph();
         $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], $itemtype, $items_id, $timezone, $time);
         $img = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=" . $itemtype . "-" . $items_id . "-" . $time . $timezone_file . ".png'/>";
         echo $img;
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
 }
 function displayItem($data, $config)
 {
     global $CFG_GLPI;
     $itemtype = $data['itemtype'];
     $itemtype2 = '';
     if ($itemtype == 'host' || $itemtype == 'service') {
         $itemtype2 = $itemtype;
         $itemtype = 'PluginMonitoringDisplayview';
     }
     $item = new $itemtype();
     $content = '';
     $title = $item->getTypeName();
     $event = '';
     $width = '';
     if ($itemtype == "PluginMonitoringService") {
         $content = $item->showWidget($data['items_id'], $data['extra_infos']);
         if (!isset($item->fields['plugin_monitoring_components_id'])) {
             return false;
         }
         $title .= " : <a href=\"" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/display.form.php?itemtype=PluginMonitoringService&items_id=" . $data['items_id'] . "\">" . Dropdown::getDropdownName(getTableForItemType('PluginMonitoringComponent'), $item->fields['plugin_monitoring_components_id']);
         $title .= '</a> ' . __('on', 'monitoring') . ' ';
         $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
         $pmComponentscatalog_Host->getFromDB($item->fields["plugin_monitoring_componentscatalogs_hosts_id"]);
         if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') {
             $itemtype2 = $pmComponentscatalog_Host->fields['itemtype'];
             $item2 = new $itemtype2();
             $item2->getFromDB($pmComponentscatalog_Host->fields['items_id']);
             $title .= str_replace("'", "\"", $item2->getLink() . " (" . $item2->getTypeName() . " / " . $data['extra_infos'] . ")");
         }
         $width = "width: 475,";
     } else {
         if ($itemtype == "PluginMonitoringWeathermap") {
             $content = $item->showWidget($data['items_id'], $data['extra_infos']);
             $content = '<div id="weathermap-' . $data['items_id'] . '">' . $content . "</div>";
             $event = ", " . $item->widgetEvent($data['items_id']);
             $title .= " : " . Dropdown::getDropdownName(getTableForItemType('PluginMonitoringWeathermap'), $data['items_id']);
             $item->getFromDB($data['items_id']);
             $width = "width:" . $item->fields['width'] * $data['extra_infos'] / 100 . ",";
         } else {
             if ($itemtype2 != '') {
                 $content = $item->showWidget2($data['id']);
             } else {
                 $content = $item->showWidget($data['items_id']);
             }
             if ($data['itemtype'] == 'PluginMonitoringServicescatalog') {
                 $width = "width: 202,";
             } else {
                 $width = "width: 180,";
             }
         }
     }
     if ($config == 0 && $itemtype != "PluginMonitoringService") {
         $title = '';
     }
     echo "<script>\n         var left = 0;\n         var topd = 0;\n         var obj = document.getElementById('panel');\n         if (obj.offsetParent) {\n           do {\n             left += obj.offsetLeft;\n             topd += obj.offsetTop;\n           } while (obj = obj.offsetParent);\n         }\n\n        var item" . $data['id'] . " = new Ext.Panel({\n             closable: true,           \n             title: '" . $title . "',\n             x: " . $data['x'] . ",\n             y: " . $data['y'] . ",\n             html       : '" . $content . "',\n             baseCls : 'x-panel',\n             layout : 'fit',\n             bodyStyle: 'background:transparent',\n             ";
     if ($config == 0 && $itemtype != "PluginMonitoringService") {
         echo "border: false,";
     }
     echo "renderTo: Ext.getBody(),\n             floating: false,\n             frame: false,\n             " . $width . "\n             autoHeight  : true,\n             layout: 'fit',\n             draggable: {\n                 //Config option of Ext.Panel.DD class.\n                 //It's a floating Panel, so do not show a placeholder proxy in the original position.\n                 insertProxy: false,\n\n                 //Called for each mousemove event while dragging the DD object.\n                 onDrag : function(e){\n                     //Record the x,y position of the drag proxy so that we can\n                     //position the Panel at end of drag.\n                     var el = this.proxy.getEl();\n                     this.x = el.getLeft(true) - left - 5;\n                     this.y = el.getTop(true) - topd - 5;\n\n\n                     //Keep the Shadow aligned if there is one.\n                     var s = this.panel.getEl().shadow;\n                     if (s) {\n                         s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());\n                     }\n                 },\n\n                 //Called on the mouseup event.\n                 endDrag : function(e){\n                     this.panel.setPosition(this.x, this.y);\n";
     if ($config == '1') {
         echo "      Ext.get('updatecoordonates').load({\n                        url: '" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/ajax/displayview_itemcoordinates.php',\n                        scripts: true,\n                        params:'id=" . $data['id'] . "&x=' + (this.x)  + '&y=' + (this.y)\n                     });\n";
         echo "      if (this.x < 1) {\n                        this.panel.destroy();\n                     }\n                     if (this.y < 0) {\n                        this.panel.destroy();\n                     }\n            \n            ";
     }
     echo "      }\n             }\n             " . $event . "\n         });\n     </script>";
     //.show()
     if ($itemtype == "PluginMonitoringService") {
         $pmComponent = new PluginMonitoringComponent();
         $item = new $itemtype();
         $item->getFromDB($data['items_id']);
         $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
         $pmServicegraph = new PluginMonitoringServicegraph();
         $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $data['items_id'], "0", $data['extra_infos'], "js");
     } else {
         if ($itemtype == "PluginMonitoringComponentscatalog") {
             $pmComponentscatalog = new PluginMonitoringComponentscatalog();
             $pmComponentscatalog->ajaxLoad($data['items_id']);
         } else {
             if ($itemtype == "PluginMonitoringServicescatalog") {
                 $pmServicescatalog = new PluginMonitoringServicescatalog();
                 $pmServicescatalog->ajaxLoad($data['items_id']);
             } else {
                 if ($itemtype2 != '') {
                     $pmDisplayview = new PluginMonitoringDisplayview();
                     $pmDisplayview->ajaxLoad2($data['id']);
                 } else {
                     if ($itemtype == "PluginMonitoringDisplayview") {
                         $pmDisplayview = new PluginMonitoringDisplayview();
                         $pmDisplayview->ajaxLoad($data['items_id']);
                     }
                 }
             }
         }
     }
     if ($itemtype == "PluginMonitoringWeathermap") {
         //         echo "<script type='text/javascript'>
         //            function updateimagew".$data['items_id']."() {
         //               var demain=new Date();
         //               document.getElementById('weathermap-".$data['items_id']."').innerHTML = demain.getTime() + '".$content."';
         //            }
         //            setInterval(updateimagew".$data['items_id'].", 50000);
         //         </script>";
         //      }
         echo "<script type='text/javascript'>\n         var mgr = new Ext.UpdateManager('weathermap-" . $data['items_id'] . "');\n         mgr.startAutoRefresh(50, \"" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/widgetWeathermap.php\", \"id=" . $data['items_id'] . "&extra_infos=" . $data['extra_infos'] . "\", \"\", true);\n         </script>";
     }
     return true;
 }
示例#19
0
 } else {
     if (isset($_POST["update"])) {
         if (isset($_POST['arg'])) {
             $_POST['arguments'] = exportArrayToDB($_POST['arg']);
         }
         if (empty($_POST['name']) or empty($_POST['plugin_monitoring_checks_id']) or empty($_POST['plugin_monitoring_commands_id']) or empty($_POST['calendars_id'])) {
             $_SESSION['plugin_monitoring_components'] = $_POST;
             Session::addMessageAfterRedirect("<font class='red'>" . __('Fields with asterisk are required', 'monitoring') . "</font>");
             Html::back();
         }
         if ($_POST['graph_template'] != '') {
             if (!isset($_POST['perfname']) and !isset($_POST['perfnameinvert']) and !isset($_POST['perfnamecolor'])) {
                 $pMonitoringComponent->getFromDB($_POST['id']);
                 if (empty($pMonitoringComponent->fields['perfname']) and empty($pMonitoringComponent->fields['perfnameinvert']) and empty($pMonitoringComponent->fields['perfnamecolor'])) {
                     $a_perfnames = array();
                     $a_perfnames = PluginMonitoringServicegraph::getperfdataNames($_POST['graph_template']);
                     foreach ($a_perfnames as $name) {
                         $a_perfnames[$name] = 1;
                     }
                     $_POST['perfname'] = exportArrayToDB($a_perfnames);
                 }
             }
         }
         $pMonitoringComponent->update($_POST);
         Html::back();
     } else {
         if (isset($_POST["delete"])) {
             $pMonitoringComponent->delete($_POST);
             $pMonitoringComponent->redirectToList();
         } else {
             if (isset($_POST['updateperfdata'])) {
示例#20
0
  (at your option) any later version.

  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", "display");
PluginMonitoringServicegraph::loadLib();
$pmService = new PluginMonitoringService();
$pmService->manageServices($_GET['itemtype'], $_GET['items_id']);
Html::footer();
示例#21
0
 static function preferences($components_id, $loadpreferences = 1, $displayonly = 0)
 {
     if ($loadpreferences == 1) {
         PluginMonitoringServicegraph::loadPreferences($components_id);
     }
     $pmComponent = new PluginMonitoringComponent();
     $pmComponent->getFromDB($components_id);
     echo "<form method='post'>";
     $a_perfnames = array();
     $a_perfnames = PluginMonitoringServicegraph::getperfdataNames($pmComponent->fields['graph_template']);
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<td rowspan='" . ceil(count($a_perfnames) / 7) . "' width='90'>";
     echo "Display&nbsp;:";
     echo "</td>";
     $i = 0;
     $j = 0;
     if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$components_id])) {
         foreach ($a_perfnames as $name) {
             $_SESSION['glpi_plugin_monitoring']['perfname'][$components_id][$name] = 'checked';
         }
     }
     foreach ($a_perfnames as $name) {
         if ($i == 'O' and $j == '1') {
             echo "<tr>";
         }
         echo "<td>";
         $checked = "checked";
         if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$components_id])) {
             $checked = "";
         }
         if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$components_id][$name])) {
             $checked = $_SESSION['glpi_plugin_monitoring']['perfname'][$components_id][$name];
         }
         echo "<input type='checkbox' name='perfname[]' value='" . $name . "' " . $checked . "/> " . $name;
         echo "</td>";
         $i++;
         if ($i == 6) {
             $i = 0;
             echo "</tr>";
         }
         $j = 1;
     }
     if ($i != 6) {
         echo "<td colspan='" . (6 - $i) . "'></td>";
         echo "</tr>";
     }
     echo "</table>";
     if ($displayonly == 1) {
         return;
     }
     // * Invert perfname
     $a_perfnames = array();
     $a_perfnames = PluginMonitoringServicegraph::getperfdataNames($pmComponent->fields['graph_template']);
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<td rowspan='" . ceil(count($a_perfnames) / 7) . "' width='90'>";
     echo "Invert values&nbsp;:";
     echo "</td>";
     $i = 0;
     $j = 0;
     foreach ($a_perfnames as $name) {
         if ($i == 'O' and $j == '1') {
             echo "<tr>";
         }
         echo "<td>";
         $checked = "";
         if (isset($_SESSION['glpi_plugin_monitoring']['perfnameinvert'][$components_id][$name])) {
             $checked = $_SESSION['glpi_plugin_monitoring']['perfnameinvert'][$components_id][$name];
         }
         echo "<input type='checkbox' name='perfnameinvert[]' value='" . $name . "' " . $checked . "/> " . $name;
         echo "</td>";
         $i++;
         if ($i == 6) {
             $i = 0;
             echo "</tr>";
         }
         $j = 1;
     }
     if ($i != 6) {
         echo "<td colspan='" . (6 - $i) . "'></td>";
         echo "</tr>";
     }
     echo "</table>";
     // * Define color of perfname
     $a_perfnames = array();
     $a_perfnames = PluginMonitoringServicegraph::getperfdataNames($pmComponent->fields['graph_template']);
     foreach ($a_perfnames as $key => $name) {
         if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$components_id][$name])) {
             unset($a_perfnames[$key]);
         }
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<td rowspan='" . ceil(count($a_perfnames) / 4) . "' width='90'>";
     echo "Colors&nbsp;:";
     echo "</td>";
     $i = 0;
     $j = 0;
     foreach ($a_perfnames as $name) {
         if ($i == 'O' and $j == '1') {
             echo "<tr>";
         }
         echo "<td>";
         echo $name . "&nbsp;:";
         echo "</td>";
         echo "<td>";
         $a_colors = array();
         if (strstr($name, "warn")) {
             $a_colors = PluginMonitoringServicegraph::colors("warn");
         } else {
             if (strstr($name, "crit")) {
                 $a_colors = PluginMonitoringServicegraph::colors("crit");
             } else {
                 $a_colors = PluginMonitoringServicegraph::colors();
             }
         }
         echo " <select name='perfnamecolor[" . $name . "]' id='color" . $name . "'>";
         echo "<option value=''>" . Dropdown::EMPTY_VALUE . "</option>";
         foreach ($a_colors as $color) {
             $checked = '';
             if (isset($_SESSION['glpi_plugin_monitoring']['perfnamecolor'][$components_id][$name]) and $_SESSION['glpi_plugin_monitoring']['perfnamecolor'][$components_id][$name] == $color) {
                 $checked = 'selected';
             }
             echo "<option value='" . $color . "' style='background-color: #" . $color . ";' " . $checked . ">" . $color . "</option>";
         }
         echo "</select>";
         echo "</td>";
         $i++;
         if ($i == 4) {
             $i = 0;
             echo "</tr>";
         }
         $j = 1;
     }
     if ($i != 4) {
         echo "<td colspan='" . (4 - $i) * 2 . "'></td>";
         echo "</tr>";
     }
     echo "<tr>";
     echo "<td colspan='9' align='center'>";
     echo "<input type='hidden' name='id' value='" . $components_id . "'/>";
     echo "<input type='submit' name='updateperfdata' value=\"" . __('Save') . "\" class='submit'>";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
 }
   function displayGraph($rrdtool_template, $itemtype, $items_id, $timezone, $time='1d', $part='', $width='900') {
      global $CFG_GLPI;

      $pmComponent = new PluginMonitoringComponent();
//      if (isset($_GET['itemtype'])) {
//         $itemtype = $_GET['itemtype'];
//         $items_id = $_GET['items_id'];
//      }
      $item = new $itemtype();
      if ($item->getFromDB($items_id)) {
         $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
         $ident = $items_id.$time;

         if ($part == ''
                 OR $part == 'div') {
            echo '<div id="chart'.$ident.'">'.
                '<svg style="width: '.$width.'px;display: block;"></svg>'.
              '</div>';

            echo "<div id=\"updategraph".$items_id.$time."\"></div>";
         }
         if ($part == ''
                 OR $part == 'js') {
            if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
               PluginMonitoringToolbox::loadPreferences($pmComponent->fields['id']);
            }
            if (! isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']])) {
               $format = '%H:%M';
            } else {
               if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']][''])) {
                  unset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']]['']);
               }
               $pmServicegraph = new PluginMonitoringServicegraph();
               $a_ret = $pmServicegraph->generateData($rrdtool_template,
                                            $itemtype,
                                            $items_id,
                                            $timezone,
                                            $time,
                                            '',
                                            $_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->fields['id']]);
               $format = $a_ret[2];
            }
            echo "<script>";
            $formaty = ".0f";
            echo '

            var data'.$ident.' = [];
            var chart'.$ident.';
            redraw'.$ident.' = function () {
               nv.addGraph(function() {
                  chart'.$ident.' = nv.models.lineChart();

                  chart'.$ident.'.useInteractiveGuideline(true);

                  chart'.$ident.'.xAxis
                     .tickFormat(function(d) { return d3.time.format("'.$format.'")(new Date(d)); });

                  chart'.$ident.'.yAxis
                     .axisLabel("test")
                     .tickFormat(d3.format(\''.$formaty.'\'));

                  chart'.$ident.'.forceY([0]);

                  d3.select("#chart'.$ident.' svg")
                    .attr("height", 300)
                    .datum(data'.$ident.')
                    .transition().duration(50)
                    .call(chart'.$ident.');



                 return chart'.$ident.';
               });
            };';

            echo "
            (function worker".$items_id.$time."() {
              startDate = new Date($('#custom_date').val());
              startTime = Date.parse('04/03/1980 ' + ($('#custom_time').val()) + ':00');
              $.getJSON('".$CFG_GLPI["root_doc"]."/plugins/monitoring/ajax/updateChart.php"
                    ."?rrdtool_template=".$rrdtool_template."&itemtype=".$itemtype.
                          "&items_id=".$items_id.
                          "&timezone=".$timezone.
                          "&time=".$time."&customdate=' + (startDate.getTime()/1000.0) + '".
                          "&customtime=' + (startTime/1000.0) + '".
                          "&components_id=".$pmComponent->fields['id']."', function(data) {
                data".$ident." = data;

                redraw".$ident."();
                setTimeout(worker".$items_id.$time.", 30000);
              });
            })();";
            echo "
            </script>";
         }

                 }
      return;
   }
示例#23
0
 function preferences($components_id)
 {
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>";
     echo __('Settings');
     echo "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_3'>";
     echo "<td>";
     PluginMonitoringServicegraph::preferences($components_id);
     echo "</td>";
     echo "</tr>";
     echo "</table>";
 }