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'); } }
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 " <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 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 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; }
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 " <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>"; }
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; } }
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 " <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>"; }
@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); }
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>"; }