/** * * @param $items_id integer ID * @param $options array * *@return bool true if form is ok * **/ function showForm($items_id, $itemtype, $options = array()) { global $DB, $CFG_GLPI; $pmComponent = new PluginMonitoringComponent(); $pmRealm = new PluginMonitoringRealm(); $entities_id = 0; if ($itemtype == "Entity") { $entities_id = $items_id; } else { $item = new $itemtype(); $item->getFromDB($items_id); $entities_id = $item->fields['entities_id']; } $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `items_id`='" . $items_id . "'\n AND `itemtype`='" . $itemtype . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $this->getEmpty(); if ($entities_id != '0' or $itemtype != 'Entity') { $this->fields['plugin_monitoring_components_id'] = -1; $this->fields['plugin_monitoring_realms_id'] = -1; $this->fields['jetlag'] = 100; } } else { $data = $DB->fetch_assoc($result); $this->getFromDB($data['id']); } echo "<form name='form' method='post'\n action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/hostconfig.form.php'>"; echo "<table class='tab_cadre_fixe'"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='4'>"; echo __('Hosts configuration', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>"; echo __('Component', 'monitoring') . " :"; echo "</td>"; echo "<td>"; $toadd = array(); if ($entities_id != '0' or $itemtype != 'Entity') { $toadd["-1"] = __('Inheritance of the parent entity'); } Dropdown::show('PluginMonitoringComponent', array('name' => 'plugin_monitoring_components_id', 'value' => $this->fields['plugin_monitoring_components_id'], 'toadd' => $toadd, 'display_emptychoice' => FALSE)); echo "</td>"; echo "<td>" . __('Reaml', 'monitoring') . " :</td>"; echo "<td>"; $toadd = array(); if ($entities_id != '0' or $itemtype != 'Entity') { $toadd["-1"] = __('Inheritance of the parent entity'); } Dropdown::show('PluginMonitoringRealm', array('name' => 'plugin_monitoring_realms_id', 'value' => $this->fields['plugin_monitoring_realms_id'], 'toadd' => $toadd, 'display_emptychoice' => FALSE)); echo "</td>"; echo "</tr>"; // Inheritance if ($this->fields['plugin_monitoring_components_id'] == '-1') { echo "<tr class='tab_bg_1'>"; if ($this->fields['plugin_monitoring_components_id'] == '-1') { echo "<td colspan='2' class='green center'>"; echo __('Inheritance of the parent entity') . " : "; $pmComponent->getFromDB($this->getValueAncestor("plugin_monitoring_components_id", $entities_id)); echo $pmComponent->fields['name']; echo "</td>"; } else { echo "<td colspan='2'>"; echo "</td>"; } if ($this->fields['plugin_monitoring_realms_id'] == '-1') { echo "<td colspan='2' class='green center'>"; echo __('Inheritance of the parent entity') . " : "; $pmRealm->getFromDB($this->getValueAncestor("plugin_monitoring_realms_id", $entities_id)); echo $pmRealm->fields['name']; echo "</td>"; } else { echo "<td colspan='2'>"; echo "</td>"; } echo "</tr>"; } echo "<tr class='tab_bg_1'>"; echo "<td>"; echo __('Jet lag', 'monitoring') . " :"; echo "</td>"; echo "<td>"; $elements = array('-11' => '-11', '-10' => '-10', '-9' => '-9', '-8' => '-8', '-7' => '-7', '-6' => '-6', '-5' => '-5', '-4' => '-4', '-3' => '-3', '-2' => '-2', '-1' => '-1', '0' => '0', '1' => '+1', '2' => '+2', '3' => '+3', '4' => '+4', '5' => '+5', '6' => '+6', '7' => '+7', '8' => '+8', '9' => '+9', '10' => '+10', '11' => '+11', '12' => '+12', '13' => '+13', '14' => '+14'); if ($entities_id != '0' or $itemtype != 'Entity') { $elements["100"] = __('Inheritance of the parent entity'); } Dropdown::showFromArray('jetlag', $elements, array('value' => $this->fields['jetlag'])); echo "</td>"; echo "<td colspan='2'></td>"; echo "</tr>"; // Inheritance if ($this->fields['jetlag'] == '100') { echo "<tr class='tab_bg_1'>"; if ($this->fields['jetlag'] == '100') { echo "<td colspan='2' class='green center'>"; echo __('Inheritance of the parent entity') . " : "; echo $elements[$this->getValueAncestor("jetlag", $entities_id)]; echo "</td>"; } else { echo "<td colspan='2'>"; echo "</td>"; } echo "<td colspan='2'>"; echo "</td>"; echo "</tr>"; } /* if ($itemtype == 'Entity' AND $items_id == '0') { echo "<tr class='tab_bg_1'>"; echo "<td>"; echo __('Shinken Server', 'monitoring')." :"; echo "</td>"; echo "<td>"; Dropdown::show("Computer", array( 'name' => 'computers_id', 'value' => $this->fields['computers_id'] )); echo "</td>"; echo "<td colspan='2'></td>"; echo "</tr>"; } */ if ($this->canCreate()) { echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' align='center'>"; if (isset($this->fields['id']) and $this->fields['id'] != '') { echo "<input type='hidden' name='id' value='" . $this->fields['id'] . "'/>"; } echo "<input type='hidden' name='itemtype' value='" . $itemtype . "'/>"; echo "<input type='hidden' name='items_id' value='" . $items_id . "'/>"; echo "<input type='submit' name='update' value=\"" . __('Save') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; } echo "</table>"; Html::closeForm(); return true; }
function parseToRrdtool($plugin_monitoring_services_id) { global $DB; $pmRrdtool = new PluginMonitoringRrdtool(); $pmCommand = new PluginMonitoringCommand(); $pmService = new PluginMonitoringService(); $pmComponent = new PluginMonitoringComponent(); if ($pmService->getFromDB($plugin_monitoring_services_id)) { $pmComponent->getFromDB($pmService->fields['plugin_monitoring_components_id']); if (!isset($pmComponent->fields['plugin_monitoring_commands_id'])) { return; } if (is_null($pmComponent->fields['graph_template'])) { return; } $pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']); $pmUnavaibility = new PluginMonitoringUnavaibility(); $pmUnavaibility->runUnavaibility($plugin_monitoring_services_id); $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n ORDER BY `date`"; $result = $DB->query($query); $i = 0; $nb_rows = $DB->numrows($result); $rrdtool_value = ''; $last_date = ''; while ($edata = $DB->fetch_array($result)) { $i++; if ($edata['unavailability'] == '0') { if ($last_date != '') { $pmRrdtool->addData($pmComponent->fields['graph_template'], $plugin_monitoring_services_id, 0, '', $rrdtool_value, 1); } break; } $perf_data = $edata['perf_data']; if ($edata['perf_data'] == '') { $perf_data = $edata['output']; } if ($edata['unavailability'] != '2' and $i < $nb_rows) { $rrdtool_value = $pmRrdtool->addData($pmComponent->fields['graph_template'], $plugin_monitoring_services_id, $this->convert_datetime_timestamp($edata['date']), $perf_data, $rrdtool_value, 0); } $last_date = $edata['date']; if ($i == $nb_rows) { if ($edata['unavailability'] != '2') { $input = array(); $input['id'] = $edata['id']; $input['unavailability'] = 2; $this->update($input); $pmRrdtool->addData($pmComponent->fields['graph_template'], $plugin_monitoring_services_id, $this->convert_datetime_timestamp($edata['date']), $perf_data, $rrdtool_value, 1); $queryd = "DELETE FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `date`<'" . $edata['date'] . "'"; $DB->query($queryd); } } } $a_list = array(); $a_list[] = "2h"; $a_list[] = "12h"; $a_list[] = "1d"; $a_list[] = "1w"; $a_list[] = "1m"; $a_list[] = "0y6m"; $a_list[] = "1y"; $pmConfig = new PluginMonitoringConfig(); $pmConfig->getFromDB(1); $a_timezones = importArrayFromDB($pmConfig->fields['timezones']); foreach ($a_list as $time) { foreach ($a_timezones as $timezone) { $pmRrdtool->displayGLPIGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $plugin_monitoring_services_id, $timezone, $time); } } } else { $query = "DELETE FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'"; $DB->query($query); } }
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(); $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>"; }
$_SESSION['glpi_plugin_monitoring']['_refresh'] = $_POST['_refresh']; Html::back(); exit; } if (isset($_POST["plugin_monitoring_timezone"])) { $_SESSION['plugin_monitoring_timezone'] = $_POST["plugin_monitoring_timezone"]; Html::back(); } if (isset($_POST['updateperfdata'])) { $pmComponent = new PluginMonitoringComponent(); if (isset($_POST["perfnameinvert"])) { $itemtype = $_GET['itemtype']; $items_id = $_GET['items_id']; $item = new $itemtype(); $item->getFromDB($items_id); $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']); $_SESSION['glpi_plugin_monitoring']['perfnameinvert'][$pmComponent->fields['id']] = array(); $_POST['perfnameinvert'] = explode("####", $_POST['perfnameinvert']); foreach ($_POST["perfnameinvert"] as $perfname) { $_SESSION['glpi_plugin_monitoring']['perfnameinvert'][$pmComponent->fields['id']][$perfname] = "checked"; } } if (isset($_POST["perfnamecolor"])) { $itemtype = $_GET['itemtype']; $items_id = $_GET['items_id']; $item = new $itemtype(); $item->getFromDB($items_id); $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']); $_SESSION['glpi_plugin_monitoring']['perfnamecolor'][$pmComponent->fields['id']] = array(); foreach ($_POST["perfnamecolor"] as $perfname => $color) { if ($color != '') {
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 generateSyntheseReport($array) { global $DB; $end_date = $array[$array['reporttype'] . 'date_end']; $end_date_timestamp = strtotime($end_date); $number = $array[$array['reporttype'] . 'number']; $period = $array[$array['reporttype'] . 'period']; $componentscatalogs_id = $array['componentscatalogs_id']; $pmComponent = new PluginMonitoringComponent(); $pmUnavaibility = new PluginMonitoringUnavaibility(); $pmServiceevent = new PluginMonitoringServiceevent(); PluginMonitoringReport::beginCapture(); $a_groups = array("avaibility"); foreach ($array['perfname'] as $perfname) { $a_groups[] = $perfname; } $a_groups = array_unique($a_groups); foreach ($a_groups as $groupname) { foreach ($array['components_id'] as $components_id) { $pmComponent->getFromDB($components_id); echo "<table class='tab_cadre_fixe'>"; echo '<tr class="tab_bg_1">'; echo '<th colspan="' . (3 + $number * 2) . '">'; echo $pmComponent->getName() . " / "; if ($groupname == 'avaibility') { echo __('Avaibility', 'monitoring'); } else { echo $groupname; } echo '</th>'; echo '</tr>'; echo '<tr class="tab_bg_1">'; echo '<th>'; echo __('Name'); echo '</th>'; echo '<th>'; echo __('Entity'); echo '</th>'; echo '<th>'; echo __('Itemtype'); echo '</th>'; for ($i = $number; $i >= 1; $i--) { echo '<th colspan="2">'; echo Html::convDate(date('Y-m-d', strtotime("-" . $i . " " . $period, $end_date_timestamp))); echo "<br/>"; echo Html::convDate(date('Y-m-d', strtotime("-" . ($i - 1) . " " . $period, $end_date_timestamp))); echo '</th>'; } echo '</tr>'; $query = "SELECT `glpi_plugin_monitoring_componentscatalogs_hosts`.*, \n `glpi_plugin_monitoring_services`.`id` as sid FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n LEFT JOIN `glpi_plugin_monitoring_services`\n ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`=`plugin_monitoring_componentscatalogs_hosts_id`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'\n AND `plugin_monitoring_components_id`='" . $components_id . "'"; $result = $DB->query($query); $rownb = true; while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); if ($groupname == 'avaibility') { $a_times = $pmUnavaibility->parseEvents($data['id'], '', date('Y-m-d', strtotime("-" . ($number + 1) . " " . $period, $end_date_timestamp)), date('Y-m-d', strtotime("-" . $number . " " . $period, $end_date_timestamp))); $previous_value = round(($a_times[1] - $a_times[0]) / $a_times[1] * 100, 3); } else { $previous_value = 0; } echo '<tr class="tab_bg_1' . (($rownb = !$rownb) ? '_2' : '') . '">'; echo '<td>'; echo $item->getName(); echo '</td>'; echo '<td>'; echo Dropdown::getDropdownName("glpi_entities", $item->fields['entities_id']); echo '</td>'; echo '<td>'; echo $item->getTypeName(); echo '</td>'; for ($i = $number; $i >= 1; $i--) { echo '<td>'; $startdatet = date('Y-m-d', strtotime("-" . $i . " " . $period, $end_date_timestamp)); $enddatet = date('Y-m-d', strtotime("-" . ($i - 1) . " " . $period, $end_date_timestamp)); if ($groupname == 'avaibility') { $a_times = $pmUnavaibility->parseEvents($data['id'], '', $startdatet, $enddatet); $value = round(($a_times[1] - $a_times[0]) / $a_times[1] * 100, 3); echo $value . "%"; } else { $queryevents = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $data['sid'] . "'\n AND `date` >= '" . $startdatet . "'\n AND `date` <= '" . $enddatet . "'\n ORDER BY `date`"; $resultevents = $DB->query($queryevents); $ret = $pmServiceevent->getData($resultevents, $pmComponent->fields['graph_template']); $value = round(array_sum($ret[0][$groupname]) / count($ret[0][$groupname]), 3); echo $value; } echo '</td>'; echo '<td>'; if ($previous_value < $value) { echo '<img src="../pics/arrow-up-right.png" width="16" />'; } else { if ($previous_value == $value) { echo '<img src="../pics/arrow-right.png" width="16" />'; } else { if ($previous_value > $value) { echo '<img src="../pics/arrow-down-right.png" width="16" />'; } } } $previous_value = $value; echo '</td>'; } echo "</tr>"; } echo "</table>"; } echo "<br/><br/>"; } $content = PluginMonitoringReport::endCapture(); PluginMonitoringReport::generatePDF($content, 'L'); }
function showWidget($id, $time) { global $LANG, $DB, $CFG_GLPI; $pmRrdtool = new PluginMonitoringRrdtool(); $pmComponent = new PluginMonitoringComponent(); $this->getFromDB($id); $pmComponent->getFromDB($this->fields['plugin_monitoring_components_id']); $pmRrdtool->displayGLPIGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $id, "0", $time); return '<img src="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/front/send.php?file=PluginMonitoringService-' . $id . '-' . $time . '0.png"/>'; }
PluginMonitoringToolbox::loadPreferences($_GET['components_id']); } if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$_GET['components_id']])) { echo json_encode(array()); // echo __('No data ...', 'monitoring'); exit; } if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$_GET['components_id']][''])) { unset($_SESSION['glpi_plugin_monitoring']['perfname'][$_GET['components_id']]['']); } $a_ret = $pmServicegraph->generateData($_GET['rrdtool_template'], $_GET['itemtype'], $_GET['items_id'], $_GET['timezone'], $_GET['time'], $enddate, $_SESSION['glpi_plugin_monitoring']['perfname'][$_GET['components_id']]); $mydatat = $a_ret[0]; $a_labels = $a_ret[1]; $pmComponent = new PluginMonitoringComponent(); $pmCommand = new PluginMonitoringCommand(); $pmComponent->getFromDB($_GET['components_id']); $pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']); $a_data = array(); $a_values = array(); $lab = ''; $num = 1; $a_names = array(); $formaty = ".0f"; $max = 0; foreach ($mydatat as $name => $data) { if (!isset($a_names[$name])) { $a_names[$name] = $num; $num++; } $display = "checked"; if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$_GET['components_id']])) {
@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); }
static function getTimeBetween2Checks($components_id) { $pmComponent = new PluginMonitoringComponent(); $pmCheck = new PluginMonitoringCheck(); $pmComponent->getFromDB($components_id); $pmCheck->getFromDB($pmComponent->fields['plugin_monitoring_checks_id']); $timeMinutes = $pmCheck->fields['check_interval']; $timeSeconds = $timeMinutes * 60; return $timeSeconds; }
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') . " :"; 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') . " :"; 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') . " :"; 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 . " :"; 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 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>"; }
static function loadPreferences($components_id) { $pmComponent = new PluginMonitoringComponent(); $pmComponent->getFromDB($components_id); $_SESSION['glpi_plugin_monitoring']['perfname'][$components_id] = array(); $a_perfname = importArrayFromDB($pmComponent->fields['perfname']); foreach ($a_perfname as $perfname => $active) { $_SESSION['glpi_plugin_monitoring']['perfname'][$components_id][$perfname] = 'checked'; } $_SESSION['glpi_plugin_monitoring']['perfnameinvert'][$components_id] = array(); $a_perfnameinvert = importArrayFromDB($pmComponent->fields['perfnameinvert']); foreach ($a_perfnameinvert as $perfname => $active) { $_SESSION['glpi_plugin_monitoring']['perfnameinvert'][$components_id][$perfname] = 'checked'; } $_SESSION['glpi_plugin_monitoring']['perfnamecolor'][$components_id] = array(); $a_perfnamecolor = importArrayFromDB($pmComponent->fields['perfnamecolor']); foreach ($a_perfnamecolor as $perfname => $color) { $_SESSION['glpi_plugin_monitoring']['perfnamecolor'][$components_id][$perfname] = $color; } }
function showForm($items_id, $servicescatalogs_id, $options = array()) { global $CFG_GLPI; if ($items_id != '') { $this->getFromDB($items_id); } else { $this->getEmpty(); } $this->showFormHeader($options); $pmBusinessrule_component = new PluginMonitoringBusinessrule_component(); $pmBusinessrule_component->replayDynamicServices($items_id); $pmSC = new PluginMonitoringServicescatalog(); $pmSC->getFromDB($servicescatalogs_id); $rand = mt_rand(); echo "<tr class='tab_bg_1'>"; echo "<td>"; echo "<input type='hidden' name='plugin_monitoring_servicescatalogs_id' value='" . $servicescatalogs_id . "'/>"; echo __('Name') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='name' value='" . $this->fields["name"] . "' size='30'/>"; echo "</td>"; if ($items_id != '') { if (Session::haveRight("plugin_monitoring_servicescatalog", CREATE)) { echo "<th colspan='2' width='60%'>"; echo __('Resources', 'monitoring'); echo " "; echo "<img onClick=\"Ext.get('ressources" . $rand . "').setDisplayed('block')\"\n title=\"" . __('add') . "\" alt=\"" . __('add') . "\"\n class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>"; echo "</th>"; } } echo "</tr>"; echo "<tr>"; echo "<td valign='top'>"; echo __('Logical operator') . " :"; echo "</td>"; echo "<td valign='top'>"; $first_operator = array(); $first_operator['and'] = "and"; $first_operator['or'] = "or"; $first_operator['2 of:'] = __('2 of', 'monitoring'); $first_operator['3 of:'] = __('3 of', 'monitoring'); $first_operator['4 of:'] = __('4 of', 'monitoring'); $first_operator['5 of:'] = __('5 of', 'monitoring'); $first_operator['6 of:'] = __('6 of', 'monitoring'); $first_operator['7 of:'] = __('7 of', 'monitoring'); $first_operator['8 of:'] = __('8 of', 'monitoring'); $first_operator['9 of:'] = __('9 of', 'monitoring'); $first_operator['10 of:'] = __('10 of', 'monitoring'); Dropdown::showFromArray('operator', $first_operator, array("value" => $this->fields['operator'])); echo "</td>"; if ($items_id != '') { echo "<td colspan='2'>"; if (Session::haveRight("plugin_monitoring_servicescatalog", CREATE)) { // ** Dropdown to display echo "<div style='display:none' id='ressources" . $rand . "' >"; // Static (a service for an host) echo "<table>"; echo "<tr class='tab_bg_1'>"; echo "<td>"; echo "<form name='form' method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/businessrule.form.php'>"; echo "<input type='hidden' name='plugin_monitoring_businessrulegroups_id' value='" . $items_id . "' />"; echo "<input type='hidden' name='is_generic' value='" . $pmSC->getField('is_generic') . "' />"; PluginMonitoringBusinessrule::dropdownService(0, array('name' => 'type')); echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "</table>"; echo "<hr>"; // Dynamique (all service of component of component catalog) echo "<table>"; echo "<tr class='tab_bg_1'>"; echo "<td><strong>"; echo __('Components catalog', 'monitoring'); echo ' + '; echo __('Component', 'monitoring'); echo " (" . __('Dynamic', 'monitoring') . ")"; echo " :</strong></td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>"; echo "<form name='form' method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/businessrule_component.form.php'>"; echo "<input type='hidden' name='plugin_monitoring_businessrulegroups_id' value='" . $items_id . "' />"; $options = array('toupdate' => array('value_fieldname' => 'plugin_monitoring_componentscalalog_id', 'to_update' => "componentdropdown" . $rand, 'url' => $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownComponent.php", 'moreparams' => array())); Dropdown::show('PluginMonitoringComponentscatalog', $options); echo '<div id="componentdropdown' . $rand . '"></div>'; //PluginMonitoringBusinessrule::dropdownService(0, array('name' => 'type')); echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "</table>"; echo "<hr>"; echo "</div>"; } $pmBusinessrule = new PluginMonitoringBusinessrule(); $pmService = new PluginMonitoringService(); $a_services = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $items_id . "'" . " AND `is_dynamic`='0'"); if (count($a_services) > 0) { echo "<strong>" . __('Static hosts', 'monitoring') . " :</strong>"; echo "<table width='100%'>"; foreach ($a_services as $gdata) { if ($pmService->getFromDB($gdata['plugin_monitoring_services_id'])) { $shortstate = $pmService->getShortState(); echo "<tr class='tab_bg_1'>"; echo "<td>"; echo "<img src='" . $pmService->getShortState(array('image' => '32')) . "'/>"; echo "</td>"; echo "<td>"; echo $pmService->getLink(); echo "</td>"; echo "<td>"; echo "<input type='submit' name='deletebusinessrules-" . $gdata['id'] . "' value=\"" . _sx('button', 'Delete permanently') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; } else { // resource deleted echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' bgcolor='#ff0000'>"; echo __('Resource deleted', 'monitoring'); echo "</td>"; echo "<td>"; echo "<input type='submit' name='deletebusinessrules-" . $gdata['id'] . "' value=\"" . __('Clean') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; } } echo "</table>"; echo "<hr/>"; } $a_br_components = $pmBusinessrule_component->find("`plugin_monitoring_businessrulegroups_id`='" . $items_id . "'"); $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponent = new PluginMonitoringComponent(); if (count($a_br_components) > 0) { echo "<strong>" . __('Dynamic hosts', 'monitoring') . " :</strong>"; echo "<table width='100%'>"; foreach ($a_br_components as $a_br_component) { echo "<tr class='tab_bg_1'>"; echo "<td>"; $pmComponentscatalog_Component->getFromDB($a_br_component['plugin_monitoring_componentscatalogs_components_id']); $pmComponentscatalog->getFromDB($pmComponentscatalog_Component->fields['plugin_monitoring_componentscalalog_id']); echo $pmComponentscatalog->getLink(); echo ' > '; $pmComponent->getFromDB($pmComponentscatalog_Component->fields['plugin_monitoring_components_id']); echo $pmComponent->getLink(); echo "</td>"; echo "<td>"; echo "<input type='submit' name='deletebrcomponents-" . $a_br_component['id'] . "' value=\"" . _sx('button', 'Delete permanently') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; } echo "</table>"; } if (!($pmSC->fields['is_generic'] && $pmSC->fields['is_recursive'])) { echo "<table width='100%'>"; $a_services = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $items_id . "'" . " AND `is_dynamic`='1'"); foreach ($a_services as $gdata) { $pmService->getFromDB($gdata["plugin_monitoring_services_id"]); $shortstate = $pmService->getShortState(); echo "<tr class='tab_bg_1'>"; echo "<td width='130'> "; echo "</td>"; echo "<td>"; echo "<img src='" . $pmService->getShortState(array('image' => '32')) . "'/>"; echo "</td>"; echo "<td>"; $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmComponentscatalog_Host->getFromDB($pmService->fields['plugin_monitoring_componentscatalogs_hosts_id']); echo $pmService->getLink(); echo "</td>"; echo "</tr>"; } echo "</table>"; } else { echo "<strong>" . __('Dynamic hosts list will be defined during Shinken configuration build.', 'monitoring') . "</strong>"; } } echo "</td>"; echo "</tr>"; $this->showFormButtons($options); return true; }
function generateSyntheseReport($array, $pdf=TRUE) { global $DB; if (count($array) == 0) { return; } $end_date = $array['synthesedate_end']; $end_date_timestamp = strtotime($end_date); $number = $array['synthesenumber']; $period = $array['syntheseperiod']; $componentscatalogs_id = $array['componentscatalogs_id']; $pmComponent = new PluginMonitoringComponent(); $pmUnavailability = new PluginMonitoringUnavailability(); $pmServiceevent = new PluginMonitoringServiceevent(); if ($pdf) { PluginMonitoringReport::beginCapture(); } echo "<table class='tab_cadrehov'>"; foreach ($array['components_id'] as $components_id) { $pmComponent->getFromDB($components_id); array_unshift($array['perfname'][$components_id], 'avaibility'); array_unshift($array['perfname_val'][$components_id], 1); echo '<tr class="tab_bg_1" height="90">'; echo '<th colspan="'.(3 + ($number * 2)).'">'; echo $pmComponent->getName(); echo '</th>'; echo '</tr>'; foreach ($array['perfname'][$components_id] as $num=>$groupname) { echo '<tr class="tab_bg_1">'; echo '<th colspan="'.(3 + ($number * 2)).'">'; if ($groupname == 'avaibility') { echo __('Avaibility', 'monitoring'); } else { echo $groupname; } echo '</th>'; echo '</tr>'; echo '<tr class="tab_bg_1">'; echo '<th rowspan="2">'; echo __('Name'); echo '</th>'; echo '<th rowspan="2">'; echo __('Entity'); echo '</th>'; echo '<th rowspan="2">'; echo __('Itemtype'); echo '</th>'; $a_year = array(); for ($i = $number; $i >= 1;$i--) { $year = date('Y', strtotime("-".$i." ".$period, $end_date_timestamp)); if (!isset($a_year[$year])) { $a_year[$year] = 2; } else { $a_year[$year] += 2; } } foreach ($a_year as $year=>$colspan) { echo '<th colspan="'.$colspan.'">'; echo $year; echo '</th>'; } echo '</tr>'; echo '<tr class="tab_bg_1">'; for ($i = $number; $i >= 1;$i--) { echo '<th colspan="2">'; echo Html::convDate(date('m-d', strtotime("-".$i." ".$period, $end_date_timestamp))); echo "<br/>"; echo Html::convDate(date('m-d', strtotime("-".($i-1)." ".$period, $end_date_timestamp))); echo '</th>'; } echo '</tr>'; $query = "SELECT `glpi_plugin_monitoring_componentscatalogs_hosts`.*, `glpi_plugin_monitoring_services`.`id` as sid FROM `glpi_plugin_monitoring_componentscatalogs_hosts` LEFT JOIN `glpi_plugin_monitoring_services` ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`=`plugin_monitoring_componentscatalogs_hosts_id` WHERE `plugin_monitoring_componentscalalog_id`='".$componentscatalogs_id."' AND `plugin_monitoring_components_id`='".$components_id."'"; $result = $DB->query($query); $rownb = true; while ($data=$DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); if ($groupname == 'avaibility') { $a_times = $pmUnavailability->parseEvents($data['id'], '', date('Y-m-d', strtotime("-".($number + 1)." ".$period, $end_date_timestamp)), date('Y-m-d', strtotime("-".$number." ".$period, $end_date_timestamp))); $previous_value = round(((($a_times[1] - $a_times[0]) / $a_times[1]) * 100), 3); } else { $previous_value = 0; } echo '<tr class="tab_bg'.(($rownb = !$rownb)?'_4':'_1').'">'; echo '<td>'; echo $item->getLink(); echo '</td>'; echo '<td>'; echo Dropdown::getDropdownName("glpi_entities", $item->fields['entities_id']); echo '</td>'; echo '<td>'; echo $item->getTypeName(); echo '</td>'; for ($i = $number; $i >= 1;$i--) { $startdatet = date('Y-m-d', strtotime("-".$i." ".$period, $end_date_timestamp)); $enddatet = date('Y-m-d', strtotime("-".($i-1)." ".$period, $end_date_timestamp)); if ($groupname == 'avaibility') { $a_times = $pmUnavailability->parseEvents($data['id'], '', $startdatet, $enddatet); $value = round(((($a_times[1] - $a_times[0]) / $a_times[1]) * 100), 2); } else { $queryevents = "SELECT * FROM `glpi_plugin_monitoring_serviceevents` WHERE `plugin_monitoring_services_id`='".$data['sid']."' AND `date` >= '".$startdatet."' AND `date` <= '".$enddatet."' ORDER BY `date`"; $resultevents = $DB->query($queryevents); $_SESSION['plugin_monitoring_checkinterval'] = PluginMonitoringComponent::getTimeBetween2Checks($pmComponent->fields['id']); $ret = $pmServiceevent->getData($resultevents, $pmComponent->fields['graph_template'], $startdatet, $enddatet); if (!isset($ret[0][$groupname])) { $value = 0; } else { $value = round(array_sum($ret[0][$groupname]) / count($ret[0][$groupname]), 2); } } $bgcolor = ''; if ($array['perfname_val'][$components_id][$num] == 1) { if ($previous_value < $value) { $bgcolor = 'style="background-color:#d1ffc3"'; } else if ($previous_value > $value) { $bgcolor = 'style="background-color:#ffd1d3"'; } } else { if ($previous_value < $value) { $bgcolor = 'style="background-color:#ffd1d3"'; } else if ($previous_value > $value) { $bgcolor = 'style="background-color:#d1ffc3"'; } } echo '<td '.$bgcolor.'>'; if ($groupname == 'avaibility') { echo $value."%"; } else { if ($value > 3000000000) { echo round($value/1000000000, 2).'T'; } else if ($value > 3000000) { echo round($value/1000000, 2).'M'; } else if ($value > 3000) { echo round($value/1000, 2).'K'; } else { echo $value; } } echo '</td>'; echo '<td '.$bgcolor.'>'; if ($array['perfname_val'][$components_id][$num] == 1) { if ($previous_value < $value) { echo '<img src="../pics/arrow-up-right.png" width="16" />'; } else if ($previous_value == $value) { echo '<img src="../pics/arrow-right.png" width="16" />'; } else if ($previous_value > $value) { echo '<img src="../pics/arrow-down-right.png" width="16" />'; } } else { if ($previous_value < $value) { echo '<img src="../pics/arrow-up-right_inv.png" width="16" />'; } else if ($previous_value == $value) { echo '<img src="../pics/arrow-right.png" width="16" />'; } else if ($previous_value > $value) { echo '<img src="../pics/arrow-down-right_inv.png" width="16" />'; } } $previous_value = $value; echo '</td>'; } echo "</tr>"; } } echo '<tr class="tab_bg_1" height="50">'; echo '<td colspan="'.(3 + ($number * 2)).'">'; echo '</td>'; echo '</tr>'; } echo "</table>"; if ($pdf) { $content = PluginMonitoringReport::endCapture(); PluginMonitoringReport::generatePDF($content, 'L'); } }
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 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>"; }
function showDefineDataOfGauge($components_id, $a_path = array(), $deletebutton = FALSE) { if (!isset($this->fields) || !isset($this->fields['aggregate_items']) || $this->fields['aggregate_items'] == '') { $this->getEmpty(); } $pmComponent = new PluginMonitoringComponent(); $pmComponent->getFromDB($components_id); $perfdetail = getAllDatasFromTable('glpi_plugin_monitoring_perfdatadetails', "`plugin_monitoring_perfdatas_id`='" . $pmComponent->fields['graph_template'] . "'"); $elements = array(); foreach ($perfdetail as $perfdata) { for ($i = 1; $i <= 15; $i++) { if ($perfdata['dsname' . $i] != '') { $elements[$perfdata['id'] . "/" . $i] = $perfdata['dsname' . $i]; } } } echo "<table>"; echo "<tr>"; echo "<td>"; echo __('Value', 'monitoring'); echo " : </td>"; echo "<td>"; $value = ''; if ($this->fields['aggregate_items'] != '') { $aggregate_items = importArrayFromDB($this->fields['aggregate_items']); $value = $aggregate_items[$a_path['a']]["id" . $a_path['b']][$a_path['c']]["id" . $a_path['d']][$a_path['num']]['perfdatadetails_id'] . '/' . $aggregate_items[$a_path['a']]["id" . $a_path['b']][$a_path['c']]["id" . $a_path['d']][$a_path['num']]['perfdatadetails_dsname']; } Dropdown::showFromArray('item', $elements, array('value' => $value)); echo "</td>"; if ($deletebutton) { echo "<td rowspan='4'>"; echo "<form name='form2' method='post' action=''>"; echo "<input type='hidden' name='id' value='" . $a_path['id'] . "' />"; echo "<input type='hidden' name='delete_item' value='" . $a_path['a'] . "|id" . $a_path['b'] . "|" . $a_path['c'] . "|id" . $a_path['d'] . "|" . $a_path['num'] . "' />"; echo "<input type='submit' class='submit' name='delete' value='" . _sx('button', 'Delete permanently') . "' />"; Html::closeForm(); echo "</td>"; } echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Warning', 'monitoring'); echo " : </td>"; echo "<td>"; $used = ''; $other = '75'; if (is_numeric($this->fields['aggregate_warn'])) { $used = $this->fields['aggregate_warn']; $other = $used; } else { if ($this->fields['aggregate_warn'] == '') { $used = ''; } else { $used = $this->fields['aggregate_warn'][$a_path['a']][$a_path['b']][$a_path['c']][$a_path['d']][$a_path['num']]; } } Dropdown::showFromArray('warn', $elements, array('other' => $other, 'used' => $used)); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Critical', 'monitoring'); echo " : </td>"; echo "<td>"; $used = ''; $other = '90'; if (is_numeric($this->fields['aggregate_crit'])) { $used = $this->fields['aggregate_crit']; $other = $used; } else { if ($this->fields['aggregate_crit'] == '') { $used = ''; } else { $used = $this->fields['aggregate_crit'][$a_path['a']][$a_path['b']][$a_path['c']][$a_path['d']][$a_path['num']]; } } Dropdown::showFromArray('crit', $elements, array('other' => $other, 'used' => $used)); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Limit (max)', 'monitoring'); echo " : </td>"; echo "<td>"; $used = ''; $other = '100'; if (is_numeric($this->fields['aggregate_limit'])) { $used = $this->fields['aggregate_limit']; $other = $used; } else { if ($this->fields['aggregate_limit'] == '') { $used = ''; } else { $used = $this->fields['aggregate_limit'][$a_path['a']][$a_path['b']][$a_path['c']][$a_path['d']][$a_path['num']]; } } Dropdown::showFromArray('limit', $elements, array('other' => $other, 'used' => $used)); echo "</td>"; echo "</tr>"; echo "</table>"; }
function showComponents($componentscatalogs_id) { global $DB, $CFG_GLPI; $this->addComponent($componentscatalogs_id); $rand = mt_rand(); $pmComponent = new PluginMonitoringComponent(); $pmCommand = new PluginMonitoringCommand(); $pmCheck = new PluginMonitoringCheck(); $calendar = new Calendar(); echo "<form method='post' name='componentscatalog_component_form{$rand}' id='componentscatalog_component_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/front/componentscatalog_component.form.php\">"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th>"; echo __('Associated components', 'monitoring'); echo "</th>"; echo "</tr>"; echo "</table>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th width='10'> </th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Command name', 'monitoring') . "</th>"; echo "<th>" . __('Check definition', 'monitoring') . "</th>"; echo "<th>" . __('Check period', 'monitoring') . "</th>"; echo "<th>" . __('Remote check', 'monitoring') . "</th>"; echo "</tr>"; $used = array(); $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $used[] = $data['plugin_monitoring_components_id']; $pmComponent->getFromDB($data['plugin_monitoring_components_id']); echo "<tr>"; echo "<td>"; echo "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'>"; echo "</td>"; echo "<td class='center'>"; echo $pmComponent->getLink(1); echo "</td>"; echo "<td class='center'>"; $pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']); echo $pmCommand->getLink(); echo "</td>"; echo "<td class='center'>"; $pmCheck->getFromDB($pmComponent->fields['plugin_monitoring_checks_id']); echo $pmCheck->getLink(); echo "</td>"; echo "<td class='center'>"; $calendar->getFromDB($pmComponent->fields['calendars_id']); echo $calendar->getLink(); echo "</td>"; echo "<td class='center'>"; if ($pmComponent->fields['remotesystem'] == '') { echo "-"; } else { echo $pmComponent->fields['remotesystem']; } echo "</td>"; echo "</tr>"; } Html::openArrowMassives("componentscatalog_host_form{$rand}", true); Html::closeArrowMassives(array('deleteitem' => _sx('button', 'Delete permanently'))); Html::closeForm(); 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>"; }
} $pMonitoringComponent->add($_POST); Html::back(); } 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);
function drawMap($weathermaps_id, $widthw=100, $config=0) { global $DB, $CFG_GLPI; $this->getFromDB($weathermaps_id); PluginMonitoringSecurity::updateSession(); if (countElementsInTable('glpi_plugin_monitoring_weathermapnodes', "`plugin_monitoring_weathermaps_id`='".$weathermaps_id."'") == 0) { return; } $rand = mt_rand(); echo '<svg id="cloud'.$rand.'" width="'.$this->fields['width'].'" ' . 'height="'.$this->fields['height'].'"> <defs> <marker id="arrowhead'.$rand.'" orient="auto" markerWidth="2" markerHeight="4" refX="0.3" refY="0.8"> <path d="M0,0 V1.6 L0.8,0.8 Z" fill="#d0d0d0" /> </marker> <marker id="arrowheadred'.$rand.'" orient="auto" markerWidth="2" markerHeight="4" refX="0.3" refY="0.8"> <path d="M0,0 V1.6 L0.8,0.8 Z" fill="red" /> </marker> <marker id="arrowheadblack'.$rand.'" orient="auto" markerWidth="2" markerHeight="4" refX="0.3" refY="0.8"> <path d="M0,0 V1.6 L0.8,0.8 Z" fill="black" /> </marker> </defs> </svg>'; echo '<script> var width = '.$this->fields['width'].'; var height = '.$this->fields['height'].'; var color = d3.scale.category10(); var force'.$rand.' = d3.layout.force() .charge(-180) .linkDistance(20) .size([width, height]); var svg'.$rand.' = d3.select("#cloud'.$rand.'"); var drag_node = d3.behavior.drag() .on("drag", dragmove)'; if ($config) { echo ' .on("dragend", dragendconfig)'; } echo '; function dragmove(d, i) { d.px += d3.event.dx; d.py += d3.event.dy; d.x += d3.event.dx; d.y += d3.event.dy; tick'.$rand.'(); // this is the key to make it work together with updating both px,py,x,y on d ! } function dragendconfig(d, i) { $.ajax({type: "POST",url: "'.$CFG_GLPI['root_doc'].'/plugins/monitoring/ajax/updateWeathermap.php",data: {id: d.id, x: d.x, y: d.y},success: function(msg) {}}); } '; $a_data = array(); $a_mapping = array(); $i = 0; $query = "SELECT * FROM `".getTableForItemType("PluginMonitoringWeathermapnode")."` WHERE `plugin_monitoring_weathermaps_id`='".$weathermaps_id."' ORDER BY `name`"; $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $name = $data['name']; $url = ''; if ($name == '') { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $item->getName(); $url = $item->getLinkURL(); } $a_mapping[$data['id']] = $i; $i++; $a_textx = array( 'middle' => 0, 'start' => '12', 'end' => '-12'); $texty = 0; if ($data['position'] == 'middle') { $texty = -13; } $a_data['nodes'][] = array( 'name' => $name, 'id' => (int)$data['id'], 'x' => ($widthw * $data['x']) / 100, 'y' => ($widthw * $data['y']) / 100, 'fixed' => TRUE, "group" => 3, "url" => $url, "textposition" => $data['position'], "textx" => $a_textx[$data['position']], "texty" => $texty, "nodeusage" => 'grey' ); } $nodes_upusage = array(); $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $pmWeathermaplink = new PluginMonitoringWeathermaplink(); $pmService = new PluginMonitoringService(); $pmComponent = new PluginMonitoringComponent(); $a_data['links'] = array(); $query = "SELECT `glpi_plugin_monitoring_weathermaplinks`.* FROM `glpi_plugin_monitoring_weathermaplinks` LEFT JOIN `glpi_plugin_monitoring_weathermapnodes` ON `plugin_monitoring_weathermapnodes_id_1` = `glpi_plugin_monitoring_weathermapnodes`.`id` WHERE `plugin_monitoring_weathermaps_id`='".$weathermaps_id."'"; $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { $pmWeathermapnode->getFromDB($data['plugin_monitoring_weathermapnodes_id_2']); if (!$pmService->getFromDB($data['plugin_monitoring_services_id'])) { $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $pmWeathermapnode->getFromDB($data['plugin_monitoring_weathermapnodes_id_1']); $querytt = "SELECT glpi_plugin_monitoring_services.id FROM `glpi_plugin_monitoring_services` LEFT JOIN glpi_plugin_monitoring_componentscatalogs_hosts ON plugin_monitoring_componentscatalogs_hosts_id=glpi_plugin_monitoring_componentscatalogs_hosts.id WHERE networkports_id>0 AND itemtype='".$pmWeathermapnode->fields['itemtype']."' AND items_id='".$pmWeathermapnode->fields['items_id']."'"; $resulttt = $DB->query($querytt); $s_id = 0; if ($DB->numrows($resulttt) == 1) { $datatt = $DB->fetch_assoc($resulttt); $input = array( 'id' => $data['id'], 'plugin_monitoring_services_id' => $datatt['id'] ); $pmWeathermaplink->update($input); $pmWeathermaplink->getFromDB($data['id']); $data = $pmWeathermaplink->fields; } } $queryevent = "SELECT * FROM `glpi_plugin_monitoring_serviceevents` WHERE `plugin_monitoring_services_id`='".$data['plugin_monitoring_services_id']."' ORDER BY `date` DESC LIMIT 1"; $resultevent = $DB->query($queryevent); $in = ''; $out = ''; $service_exist = 0; while ($dataevent=$DB->fetch_array($resultevent)) { if ($pmService->getFromDB($data['plugin_monitoring_services_id'])) { $pmComponent->getFromDB($pmService->fields['plugin_monitoring_components_id']); $matches1 = array(); preg_match("/".$pmComponent->fields['weathermap_regex_in']."/m", $dataevent['perf_data'], $matches1); if (isset($matches1[1])) { $in = $matches1[1]; } $matches1 = array(); preg_match("/".$pmComponent->fields['weathermap_regex_out']."/m", $dataevent['perf_data'], $matches1); if (isset($matches1[1])) { $out = $matches1[1]; } $service_exist = 1; } else { $pmService->getEmpty(); $pmComponent->getEmpty(); } } if ($service_exist) { list($downusage, $downcolor) = $this->getWBandwidth($in, $data['bandwidth_in']); list($upusage, $upcolor) = $this->getWBandwidth($out, $data['bandwidth_out']); } else { $upusage = 100; $downusage = 100; $upcolor = 'black'; $downcolor = 'black'; } $a_data['links'][] = array( 'source' => $a_mapping[$data['plugin_monitoring_weathermapnodes_id_1']], 'target' => $a_mapping[$data['plugin_monitoring_weathermapnodes_id_2']], 'up' => $upcolor, 'down' => $downcolor, 'upusage' => $upusage, 'downusage' => $downusage, 'info' => '', 'value' => 1, 'services_id' => $data['plugin_monitoring_services_id'], 'components_id' => $pmService->fields['plugin_monitoring_components_id'], 'rrdtool_template' => $pmComponent->fields['graph_template'] ); if (!isset($nodes_upusage[$a_mapping[$data['plugin_monitoring_weathermapnodes_id_1']]])) { $nodes_upusage[$a_mapping[$data['plugin_monitoring_weathermapnodes_id_1']]] = array(); } if (!isset($nodes_upusage[$a_mapping[$data['plugin_monitoring_weathermapnodes_id_2']]])) { $nodes_upusage[$a_mapping[$data['plugin_monitoring_weathermapnodes_id_2']]] = array(); } array_push($nodes_upusage[$a_mapping[$data['plugin_monitoring_weathermapnodes_id_1']]], $upusage); array_push($nodes_upusage[$a_mapping[$data['plugin_monitoring_weathermapnodes_id_2']]], $downusage); } foreach ($nodes_upusage as $nodes_num=>$datausage) { $moyusage = array_sum($datausage)/count($datausage); list($usage, $color) = $this->getWBandwidth(array_sum($datausage)/count($datausage), 100); if ($moyusage == 0) { $color = 'grey'; } $a_data['nodes'][$nodes_num]['nodeusage'] = $color; } echo 'var jsonstr'.$rand.' = \''.json_encode($a_data).'\';'; echo 'var json'.$rand.' = JSON.parse(jsonstr'.$rand.'); force'.$rand.' .nodes(json'.$rand.'.nodes) .links(json'.$rand.'.links) .start(); '; $this->d3jsLink('up', 'usage', $rand); $this->d3jsLink('up', 'notusage', $rand); $this->d3jsLink('down', 'usage', $rand); $this->d3jsLink('down', 'notusage', $rand); echo ' var nodes'.$rand.' = svg'.$rand.'.selectAll(".node") .data(force'.$rand.'.nodes()) .enter().append("g") .attr("class", "node") .call(drag_node) .append("a") .attr("xlink:href", function (d) { return d.url; }) .attr("target", "_blank"); // .on("dragend", function(d){$.ajax({url: "toto",success: function(data) {}})}); //d3.select(this).style("fill", "white");} nodes'.$rand.'.append("circle") .attr("r", 5) .attr("class", function(d) { return "circle" + d.nodeusage; }); nodes'.$rand.'.append("text") .attr("text-anchor", function(d) { return d.textposition; }) .attr("x", function(d) { return d.textx; }) .attr("y", function(d) { return d.texty; }) .attr("dy", ".35em") .attr("class", "linklabel") .text(function(d) { return d.name; }); var textdown'.$rand.' = svg'.$rand.'.selectAll("line.link") .data(force'.$rand.'.links()) .enter().append("text") .attr("dy", ".25em") .attr("text-anchor", "middle") .style("pointer-events", "none") .attr("class", function(d) { return "linklabel" + d.down;}) .text(function(d) { return d.downusage + "%";}) var textup'.$rand.' = svg'.$rand.'.selectAll("line.link") .data(force'.$rand.'.links()) .enter().append("text") .attr("dy", ".25em") .attr("text-anchor", "middle") .style("pointer-events", "none") .attr("class", function(d) { return "linklabel" + d.up;}) .text(function(d) { return d.upusage + "%";}) force'.$rand.'.on("tick", tick'.$rand.'); function tick'.$rand.'() { linksupusage'.$rand.'.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.source.x + (((d.target.x - d.source.x) / 200) * ((d.upusage * 97) / 100)); }) .attr("y2", function(d) { return d.source.y + (((d.target.y - d.source.y) / 200) * ((d.upusage * 97) / 100)); }); linksupnotusage'.$rand.'.attr("x1", function(d) { return d.source.x + (((d.target.x - d.source.x) / 200) * ((d.upusage * 97) / 100)); }) .attr("y1", function(d) { return d.source.y + (((d.target.y - d.source.y) / 200) * ((d.upusage * 97) / 100)); }) .attr("x2", function(d) { return d.source.x + (((d.target.x - d.source.x) / 200) * 97); }) .attr("y2", function(d) { return d.source.y + (((d.target.y - d.source.y) / 200) * 97); }); linksdownusage'.$rand.'.attr("x1", function(d) { return d.target.x; }) .attr("y1", function(d) { return d.target.y; }) .attr("x2", function(d) { return d.source.x + Math.round(((d.target.x - d.source.x) / 200) * (200 - ((d.downusage * 97) / 100))); }) .attr("y2", function(d) { return d.source.y + Math.round(((d.target.y - d.source.y) / 200) * (200 - ((d.downusage * 97) / 100))); }); linksdownnotusage'.$rand.'.attr("x1", function(d) { return d.source.x + Math.round(((d.target.x - d.source.x) / 200) * (200 - ((d.downusage * 97) / 100))); }) .attr("y1", function(d) { return d.source.y + Math.round(((d.target.y - d.source.y) / 200) * (200 - ((d.downusage * 97) / 100))); }) .attr("x2", function(d) { return d.source.x + Math.round(((d.target.x - d.source.x) / 200) * 103); }) .attr("y2", function(d) { return d.source.y + Math.round(((d.target.y - d.source.y) / 200) * 103); }); nodes'.$rand.' .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); '; echo ' textdown'.$rand.'.attr("x", function(d) { return d.source.x + (((d.target.x - d.source.x) / 200) * 130); }) .attr("y", function(d) { return d.source.y + (((d.target.y - d.source.y) / 200) * 130); }); textup'.$rand.'.attr("x", function(d) { return d.source.x + (((d.target.x - d.source.x) / 200) * 70); }) .attr("y", function(d) { return d.source.y + (((d.target.y - d.source.y) / 200) * 70); }); }; '; echo ' </script>'; }
function generateAllGraphs($weathermaps_id) { global $DB; $pmServicegraph = new PluginMonitoringServicegraph(); $pmComponent = new PluginMonitoringComponent(); $cache = array(); $query = "SELECT * FROM `glpi_plugin_monitoring_weathermaplinks`\n LEFT JOIN `glpi_plugin_monitoring_weathermapnodes` \n ON `glpi_plugin_monitoring_weathermapnodes`.`id`=`plugin_monitoring_weathermapnodes_id_1`\n LEFT JOIN `glpi_plugin_monitoring_services` \n ON `glpi_plugin_monitoring_services`.`id`=`plugin_monitoring_services_id`\n WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $graph_template = ''; 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 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; }
function showComponents($componentscatalogs_id) { global $DB, $LANG, $CFG_GLPI; $this->addComponent($componentscatalogs_id); $rand = mt_rand(); $pmComponent = new PluginMonitoringComponent(); $pmCommand = new PluginMonitoringCommand(); $pmCheck = new PluginMonitoringCheck(); $calendar = new Calendar(); echo "<form method='post' name='componentscatalog_component_form{$rand}' id='componentscatalog_component_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/front/componentscatalog_component.form.php\">"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th>"; echo $LANG['plugin_monitoring']['component'][2]; echo "</th>"; echo "</tr>"; echo "</table>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th width='10'> </th>"; echo "<th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['plugin_monitoring']['command'][2] . "</th>"; echo "<th>" . $LANG['plugin_monitoring']['check'][0] . "</th>"; echo "<th>" . $LANG['plugin_monitoring']['host'][9] . "</th>"; echo "<th>" . $LANG['plugin_monitoring']['service'][8] . "</th>"; echo "</tr>"; $used = array(); $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $used[] = $data['plugin_monitoring_components_id']; $pmComponent->getFromDB($data['plugin_monitoring_components_id']); echo "<tr>"; echo "<td>"; echo "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'>"; echo "</td>"; echo "<td class='center'>"; echo $pmComponent->getLink(1); echo "</td>"; echo "<td class='center'>"; $pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']); echo $pmCommand->getLink(); echo "</td>"; echo "<td class='center'>"; $pmCheck->getFromDB($pmComponent->fields['plugin_monitoring_checks_id']); echo $pmCheck->getLink(); echo "</td>"; echo "<td class='center'>"; $calendar->getFromDB($pmComponent->fields['calendars_id']); echo $calendar->getLink(); echo "</td>"; echo "<td class='center'>"; if ($pmComponent->fields['remotesystem'] == '') { echo "-"; } else { echo $pmComponent->fields['remotesystem']; } echo "</td>"; echo "</tr>"; } openArrowMassive("componentscatalog_host_form{$rand}", true); closeArrowMassive('deleteitem', $LANG['buttons'][6]); echo "</table>"; }
function generateHostsCfg($file=0, $tag='') { global $DB; // Log Shinken restart event with Tag information ... $pmLog = new PluginMonitoringLog(); if (isset($_SERVER['HTTP_USER_AGENT']) AND strstr($_SERVER['HTTP_USER_AGENT'], 'xmlrpclib.py')) { if (!isset($_SESSION['glpi_currenttime'])) { $_SESSION['glpi_currenttime'] = date("Y-m-d H:i:s"); } $input = array(); $input['user_name'] = "Shinken"; $input['action'] = "restart"; $input['date_mod'] = date("Y-m-d H:i:s"); $input['value'] = $tag; $pmLog->add($input); } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Starting generateHostsCfg ($tag) ...\n" ); $pmCommand = new PluginMonitoringCommand(); $pmCheck = new PluginMonitoringCheck(); $pmComponent = new PluginMonitoringComponent(); $pmEntity = new PluginMonitoringEntity(); $pmHostconfig = new PluginMonitoringHostconfig(); $pmHost = new PluginMonitoringHost(); $calendar = new Calendar(); $pmRealm = new PluginMonitoringRealm(); $networkEquipment = new NetworkEquipment(); $pmContact_Item = new PluginMonitoringContact_Item(); $profile_User = new Profile_User(); $pmEventhandler = new PluginMonitoringEventhandler(); $user = new User(); $a_hosts = array(); $i=0; $a_parents_found = array(); $a_hosts_found = array(); $a_entities_allowed = $pmEntity->getEntitiesByTag($tag); $a_entities_list = array(); foreach ($a_entities_allowed as $entity) { $a_entities_list = getSonsOf("glpi_entities", $entity); } $where = ''; if (! isset($a_entities_allowed['-1'])) { $where = getEntitiesRestrictRequest("WHERE", "glpi_entities", '', $a_entities_list); } // * Prepare contacts $a_contacts_entities = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog' AND `users_id`>0"); foreach ($a_list_contact as $data) { $contactentities = getSonsOf('glpi_entities', $data['entities_id']); if (isset($a_contacts_entities[$data['items_id']][$data['users_id']])) { $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$data['users_id']]); } $a_contacts_entities[$data['items_id']][$data['users_id']] = $contactentities; } // $query = "SELECT * // FROM `glpi_plugin_monitoring_componentscatalogs_hosts` // GROUP BY `itemtype`, `items_id`"; $query = "SELECT `glpi_plugin_monitoring_componentscatalogs_hosts`.*, `glpi_computers`.`id`, `glpi_entities`.`id` AS entityId, `glpi_entities`.`name` AS entityName, `glpi_entities`.`completename` AS entityFullName, `glpi_locations`.`id`, `glpi_locations`.`completename` AS locationName, `glpi_locations`.`comment` AS locationComment, `glpi_locations`.`building` AS locationGPS, `glpi_plugin_monitoring_services`.`networkports_id` FROM `glpi_plugin_monitoring_componentscatalogs_hosts` LEFT JOIN `glpi_computers` ON `glpi_computers`.`id` = `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id` LEFT JOIN `glpi_entities` ON `glpi_computers`.`entities_id` = `glpi_entities`.`id` LEFT JOIN `glpi_locations` ON `glpi_locations`.`id` = `glpi_computers`.`locations_id` LEFT JOIN `glpi_plugin_monitoring_services` ON `glpi_plugin_monitoring_services`.`plugin_monitoring_componentscatalogs_hosts_id` = `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` $where GROUP BY `itemtype`, `items_id`"; PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Hosts: $query\n" ); $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { // Toolbox::logInFile("pm-shinken", " - fetch host ".$data['itemtype']." / ".$data['items_id']."\n"); $classname = $data['itemtype']; $class = new $classname; if ($class->getFromDB($data['items_id'])) { // if (isset($a_entities_allowed['-1']) // OR isset($a_entities_allowed[$class->fields['entities_id']])) { $pmHost->getFromDBByQuery("WHERE `glpi_plugin_monitoring_hosts`.`itemtype` = '" . $data['itemtype'] . "' AND `glpi_plugin_monitoring_hosts`.`items_id` = '" . $data['items_id'] . "' LIMIT 1"); $a_hosts[$i]['host_name'] = preg_replace("/[^A-Za-z0-9\-_]/","",$class->fields['name']); // Fix if hostname is not defined ... if (empty($a_hosts[$i]['host_name'])) { continue; } $a_hosts_found[$a_hosts[$i]['host_name']] = 1; PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - add host ".$a_hosts[$i]['host_name']."\n" ); $a_hosts[$i]['_HOSTID'] = $pmHost->getField('id'); if (isset(self::$shinkenParameters['glpi']['entityId'])) { $a_hosts[$i][self::$shinkenParameters['glpi']['entityId']] = $data['entityId']; } if (isset(self::$shinkenParameters['glpi']['itemType'])) { $a_hosts[$i][self::$shinkenParameters['glpi']['itemType']] = $classname; } if (isset(self::$shinkenParameters['glpi']['itemId'])) { $a_hosts[$i][self::$shinkenParameters['glpi']['itemId']] = $data['items_id']; } if (isset(self::$shinkenParameters['glpi']['entityName'])) { $a_hosts[$i][self::$shinkenParameters['glpi']['entityName']] = strtolower(preg_replace("/[^A-Za-z0-9\-_]/","",$data['entityName'])); } $data['entityFullName'] = preg_replace("/ > /","#",$data['entityFullName']); $data['entityFullName'] = preg_replace("/". self::$shinkenParameters['glpi']['rootEntity'] ."#/","",$data['entityFullName']); $data['entityFullName'] = preg_replace("/#/","_",$data['entityFullName']); if (isset(self::$shinkenParameters['glpi']['entityComplete'])) { $a_hosts[$i][self::$shinkenParameters['glpi']['entityComplete']] = strtolower(preg_replace("/[^A-Za-z0-9\-_]/","",$data['entityFullName'])); } $data['entityFullName'] = preg_replace("/_/",".",$data['entityFullName']); if (isset(self::$shinkenParameters['glpi']['location'])) { if (! empty($data['locationName'])) { // Toolbox::logInFile("pm-shinken", " - location: ".$data['locationName']."\n"); $string = utf8_decode(strip_tags(trim($data['locationName']))); // $string = Toolbox::decodeFromUtf8($data['locationName']); $string = preg_replace("/[\r\n]/",".",$data['locationName']); $string = preg_replace("/[^A-Za-z0-9\-_ <>\',;.:!?%*()éèàù]/",'',$string); // Toolbox::logInFile("pm-shinken", " - location: ".$string."\n"); $a_hosts[$i][self::$shinkenParameters['glpi']['location']] = $string; } } if (isset(self::$shinkenParameters['graphite']['prefix']['name'])) { $a_hosts[$i][self::$shinkenParameters['graphite']['prefix']['name']] = strtolower(self::$shinkenParameters['graphite']['prefix']['value'] . preg_replace("/[^A-Za-z0-9\-_.]/","",$data['entityFullName'])); } if (isset(self::$shinkenParameters['glpi']['lat'])) { if (! empty($data['locationGPS'])) { $split = explode(',', $data['locationGPS']); if (count($split) > 2) { // At least 3 elements, let us consider as GPS coordinates with altitude ... $a_hosts[$i][self::$shinkenParameters['glpi']['lat']] = $split[0]; $a_hosts[$i][self::$shinkenParameters['glpi']['lng']] = $split[1]; $a_hosts[$i][self::$shinkenParameters['glpi']['alt']] = $split[2]; } else if (count($split) > 1) { // At least 2 elements, let us consider as GPS coordinates ... $a_hosts[$i][self::$shinkenParameters['glpi']['lat']] = $split[0]; $a_hosts[$i][self::$shinkenParameters['glpi']['lng']] = $split[1]; // } else { // $a_hosts[$i]['_LOC_BUILDING'] = preg_replace("/[\r\n]/",".",$data['locationGPS']); // $a_hosts[$i]['_LOC_BUILDING'] = preg_replace("/[^A-Za-z0-9\-_]/"," / ",$a_hosts[$i]['_LOC_BUILDING']); } } } // Hostgroup name $a_hosts[$i]['hostgroups'] = strtolower(preg_replace("/[^A-Za-z0-9\-_ ]/","",$data['entityName'])); $a_hosts[$i]['hostgroups'] = preg_replace("/[ ]/","_",$a_hosts[$i]['hostgroups']); // Alias $a_hosts[$i]['alias'] = $data['entityName']." / ". $a_hosts[$i]['host_name']; if (isset($class->fields['networkequipmenttypes_id'])) { if ($class->fields['networkequipmenttypes_id'] > 0) { $a_hosts[$i]['alias'] .= " (".Dropdown::getDropdownName("glpi_networkequipmenttypes", $class->fields['networkequipmenttypes_id']).")"; } } else if (isset($class->fields['computertypes_id'])) { if ($class->fields['computertypes_id'] > 0) { $a_hosts[$i]['alias'] .= " (".Dropdown::getDropdownName("glpi_computertypes", $class->fields['computertypes_id']).")"; } } else if (isset($class->fields['printertypes_id'])) { if ($class->fields['printertypes_id'] > 0) { $a_hosts[$i]['alias'] .= " (".Dropdown::getDropdownName("glpi_printertypes", $class->fields['printertypes_id']).")"; } } // WebUI user interface ... if (isset(self::$shinkenParameters['webui']['hostIcons']['name'])) { $a_hosts[$i][self::$shinkenParameters['webui']['hostIcons']['name']] = self::$shinkenParameters['webui']['hostIcons']['value']; } if (isset(self::$shinkenParameters['webui']['hostView']['name'])) { $a_hosts[$i][self::$shinkenParameters['webui']['hostView']['name']] = self::$shinkenParameters['webui']['hostView']['value']; } // IP address $ip = PluginMonitoringHostaddress::getIp($data['items_id'], $data['itemtype'], $class->fields['name']); $a_hosts[$i]['address'] = $ip; // Manage dependencies $parent = ''; if ($data['itemtype'] != 'NetworkEquipment') { $networkPort = new NetworkPort(); $a_networkports = $networkPort->find("`itemtype`='".$data['itemtype']."' AND `items_id`='".$data['items_id']."'"); foreach ($a_networkports as $data_n) { $networkports_id = $networkPort->getContact($data_n['id']); if ($networkports_id) { $networkPort->getFromDB($networkports_id); if ($networkPort->fields['itemtype'] == 'NetworkEquipment') { $networkEquipment->getFromDB($networkPort->fields['items_id']); $parent = preg_replace("/[^A-Za-z0-9\-_]/","",$networkEquipment->fields['name']); $a_parents_found[$parent] = 1; $pmHost->updateDependencies($classname, $data['items_id'], 'NetworkEquipment-'.$networkPort->fields['items_id']); } } } if (empty($parent)) { if (self::$shinkenParameters['shinken']['hosts']['parents'] == 'entity') { $parent = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . $a_hosts[$i]['hostgroups']; } else { $parent = self::$shinkenParameters['shinken']['hosts']['parents']; } } } $a_hosts[$i]['parents'] = $parent; $a_fields = array(); $pmComponent->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_components_id', $class->fields['entities_id'], $classname, $class->getID())); $pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']); $a_fields = $pmComponent->fields; // Manage host check_command arguments // Toolbox::logInFile("pm-shinken", "Command line : ".$pmCommand->fields['command_line']."\n"); // Toolbox::logInFile("pm-shinken", "Arguments : ".$a_fields['arguments']."\n"); // Toolbox::logInFile("pm-shinken", "Arguments : ".$pmCommand->fields['arguments']."\n"); $array = array(); preg_match_all("/\\$(ARG\d+)\\$/", $pmCommand->fields['command_line'], $array); sort($array[0]); $a_arguments = importArrayFromDB($pmCommand->fields['arguments']); $a_argumentscustom = importArrayFromDB($pmComponent->fields['arguments']); foreach ($a_argumentscustom as $key=>$value) { $a_arguments[$key] = $value; } foreach ($a_arguments as $key=>$value) { $a_arguments[$key] = str_replace('!', '\!', html_entity_decode($value)); } $args = ''; foreach ($array[0] as $arg) { if ($arg != '$PLUGINSDIR$' AND $arg != '$NAGIOSPLUGINSDIR$' AND $arg != '$HOSTADDRESS$' AND $arg != '$MYSQLUSER$' AND $arg != '$MYSQLPASSWORD$') { $arg = str_replace('$', '', $arg); if (!isset($a_arguments[$arg])) { $args .= '!'; } else { if (strstr($a_arguments[$arg], "[[HOSTNAME]]")) { $a_arguments[$arg] = str_replace("[[HOSTNAME]]", $hostname, $a_arguments[$arg]); } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTDESCR]]")){ if (class_exists("PluginFusioninventoryNetworkPort")) { $pfNetworkPort = new PluginFusioninventoryNetworkPort(); $pfNetworkPort->loadNetworkport($data['networkports_id']); $descr = $pfNetworkPort->getValue("ifdescr"); $a_arguments[$arg] = str_replace("[[NETWORKPORTDESCR]]", $descr, $a_arguments[$arg]); } } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTNUM]]")){ $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $logicalnum = $pfNetworkPort->fields['logical_number']; $a_arguments[$arg] = str_replace("[[NETWORKPORTNUM]]", $logicalnum, $a_arguments[$arg]); } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTNAME]]")) { if (isset($data['networkports_id']) && $data['networkports_id'] > 0) { $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $portname = $pfNetworkPort->fields['name']; $a_arguments[$arg] = str_replace("[[NETWORKPORTNAME]]", $portname, $a_arguments[$arg]); } else if ($classname == 'Computer') { // Get networkportname of networkcard defined $pmHostaddress = new PluginMonitoringHostaddress(); $a_hostaddresses = $pmHostaddress->find("`itemtype`='Computer'" . " AND `items_id`='".$class->fields['id']."'", '', 1); if (count($a_hostaddresses) == 1) { $a_hostaddress = current($a_hostaddresses); if ($a_hostaddress['networkports_id'] > 0) { $networkPort = new NetworkPort(); $networkPort->getFromDB($a_hostaddress['networkports_id']); $a_arguments[$arg] = str_replace("[[NETWORKPORTNAME]]", $networkPort->fields['name'], $a_arguments[$arg]); } } } } else if (strstr($a_arguments[$arg], "[")) { $a_arguments[$arg] = PluginMonitoringService::convertArgument($data['id'], $a_arguments[$arg]); } if ($a_arguments == '') { $notadd = 1; if ($notadddescription != '') { $notadddescription .= ", "; } $notadddescription .= "Argument ".$a_arguments[$arg]." Not have value"; } $args .= '!'.$a_arguments[$arg]; if ($a_arguments[$arg] == '' AND $a_component['alias_command'] != '') { $args .= $a_component['alias_command']; } } } } $a_hosts[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . $pmCommand->fields['command_name'].$args; // Toolbox::logInFile("pm", "check_command : ".$a_hosts[$i]['check_command']."\n"); $pmCheck->getFromDB($pmComponent->fields['plugin_monitoring_checks_id']); $a_hosts[$i]['check_interval'] = $pmCheck->fields['check_interval']; $a_hosts[$i]['retry_interval'] = $pmCheck->fields['retry_interval']; $a_hosts[$i]['max_check_attempts'] = $pmCheck->fields['max_check_attempts']; if ($calendar->getFromDB($pmComponent->fields['calendars_id'])) { $a_hosts[$i]['check_period'] = $calendar->fields['name']; } else { $a_hosts[$i]['check_period'] = self::$shinkenParameters['shinken']['hosts']['check_period']; } $a_hosts[$i]['active_checks_enabled'] = $a_fields['active_checks_enabled']; $a_hosts[$i]['passive_checks_enabled'] = $a_fields['passive_checks_enabled']; // Manage freshness if ($a_fields['freshness_count'] == 0) { $a_hosts[$i]['check_freshness'] = '0'; $a_hosts[$i]['freshness_threshold'] = '0'; } else { $multiple = 1; if ($a_fields['freshness_type'] == 'seconds') { $multiple = 1; } else if ($a_fields['freshness_type'] == 'minutes') { $multiple = 60; } else if ($a_fields['freshness_type'] == 'hours') { $multiple = 3600; } else if ($a_fields['freshness_type'] == 'days') { $multiple = 86400; } $a_hosts[$i]['check_freshness'] = '1'; $a_hosts[$i]['freshness_threshold'] = (string)($a_fields['freshness_count'] * $multiple); } // Manage event handler if ($a_fields['plugin_monitoring_eventhandlers_id'] > 0) { if ($a_fields->getFromDB($a_fields['plugin_monitoring_eventhandlers_id'])) { $a_hosts[$i]['event_handler'] = $pmEventhandler->fields['command_name']; } } // Realm $pmRealm->getFromDB($pmHostconfig->getValueAncestor('plugin_monitoring_realms_id', $class->fields['entities_id'], $classname, $class->getID())); $a_hosts[$i]['realm'] = $pmRealm->fields['name']; if (! empty(self::$shinkenParameters['shinken']['hosts']['use'])) $a_hosts[$i]['use'] = self::$shinkenParameters['shinken']['hosts']['use']; if (! empty(self::$shinkenParameters['shinken']['hosts']['process_perf_data'])) $a_hosts[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['hosts']['process_perf_data']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_period'])) $a_hosts[$i]['notification_period'] = self::$shinkenParameters['shinken']['hosts']['notification_period']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_options'])) $a_hosts[$i]['notification_options'] = self::$shinkenParameters['shinken']['hosts']['notification_options']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_interval'])) $a_hosts[$i]['notification_interval'] = self::$shinkenParameters['shinken']['hosts']['notification_interval']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes'])) $a_hosts[$i]['notes'] = self::$shinkenParameters['shinken']['hosts']['notes']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes_url'])) $a_hosts[$i]['notes_url'] = self::$shinkenParameters['shinken']['hosts']['notes_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['action_url'])) $a_hosts[$i]['action_url'] = self::$shinkenParameters['shinken']['hosts']['action_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image'])) $a_hosts[$i]['icon_image'] = self::$shinkenParameters['shinken']['hosts']['icon_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image_alt'])) $a_hosts[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['hosts']['icon_image_alt']; if (! empty(self::$shinkenParameters['shinken']['hosts']['vrml_image'])) $a_hosts[$i]['vrml_image'] = self::$shinkenParameters['shinken']['hosts']['vrml_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['statusmap_image'])) $a_hosts[$i]['statusmap_image'] = self::$shinkenParameters['shinken']['hosts']['statusmap_image']; // For contacts, check if a component catalog contains the host associated component ... $a_hosts[$i]['contacts'] = ''; if (($a_fields['passive_checks_enabled'] == '1') and ($a_fields['active_checks_enabled'] == '0')) { // Specific query if host is only passively checked ... // Find the first component catalog in which the host is used ... $querycont = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts` LEFT JOIN `glpi_plugin_monitoring_services` ON `plugin_monitoring_componentscatalogs_hosts_id` = `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` WHERE `items_id`='".$data['items_id']."' AND `itemtype`='".$data['itemtype']."' LIMIT 1"; } else { // Find component catalog which contains the host associated component ... $querycont = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts` LEFT JOIN `glpi_plugin_monitoring_services` ON `plugin_monitoring_componentscatalogs_hosts_id` = `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` WHERE `plugin_monitoring_components_id`='".$pmComponent->fields['id']."' AND `items_id`='".$data['items_id']."' AND `itemtype`='".$data['itemtype']."' LIMIT 1"; } $resultcont = $DB->query($querycont); if ($DB->numrows($resultcont) != 0) { $a_componentscatalogs_hosts = $DB->fetch_assoc($resultcont); // Notification interval $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponentscatalog->getFromDB($a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']); $a_hosts[$i]['notification_interval'] = $pmComponentscatalog->fields['notification_interval']; $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog' AND `items_id`='".$a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']."'"); foreach ($a_list_contact as $data_contact) { if (isset($a_contacts_entities[$a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']][$data_contact['users_id']])) { if (in_array($class->fields['entities_id'], $a_contacts_entities[$a_componentscatalogs_hosts['plugin_monitoring_componentscalalog_id']][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } if (count($a_contacts) > 0) { $a_contacts_unique = array_unique($a_contacts); $a_hosts[$i]['contacts'] = implode(',', $a_contacts_unique); } } $i++; // } } } // Fake host for business rules PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - add host_for_bp\n" ); $a_hosts[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['bp_host']; $a_hosts[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . 'check_dummy!0'; $a_hosts[$i]['alias'] = 'Fake host for business rules'; $a_hosts[$i]['_HOSTID'] = '0'; $a_hosts[$i]['_ITEMSID'] = '0'; $a_hosts[$i]['_ITEMTYPE'] = 'Computer'; $a_hosts[$i]['address'] = '127.0.0.1'; $a_hosts[$i]['parents'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['root_parent']; $a_hosts[$i]['hostgroups'] = self::$shinkenParameters['shinken']['fake_hosts']['hostgroup_name']; $a_hosts[$i]['check_interval'] = '60'; $a_hosts[$i]['retry_interval'] = '1'; $a_hosts[$i]['max_check_attempts'] = '1'; $a_hosts[$i]['check_period'] = '24x7'; if (self::$shinkenParameters['shinken']['fake_contacts']['build']) { $a_hosts[$i]['contacts'] = self::$shinkenParameters['shinken']['fake_contacts']['contact_name']; } else { $a_hosts[$i]['contacts'] = ''; } if (! empty(self::$shinkenParameters['shinken']['fake_hosts']['use'])) $a_hosts[$i]['use'] = self::$shinkenParameters['shinken']['fake_hosts']['use']; if (! empty(self::$shinkenParameters['shinken']['hosts']['process_perf_data'])) $a_hosts[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['hosts']['process_perf_data']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_period'])) $a_hosts[$i]['notification_period'] = self::$shinkenParameters['shinken']['hosts']['notification_period']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_options'])) $a_hosts[$i]['notification_options'] = self::$shinkenParameters['shinken']['hosts']['notification_options']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_interval'])) $a_hosts[$i]['notification_interval'] = self::$shinkenParameters['shinken']['hosts']['notification_interval']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes'])) $a_hosts[$i]['notes'] = self::$shinkenParameters['shinken']['hosts']['notes']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes_url'])) $a_hosts[$i]['notes_url'] = self::$shinkenParameters['shinken']['hosts']['notes_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['action_url'])) $a_hosts[$i]['action_url'] = self::$shinkenParameters['shinken']['hosts']['action_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image'])) $a_hosts[$i]['icon_image'] = self::$shinkenParameters['shinken']['hosts']['icon_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image_alt'])) $a_hosts[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['hosts']['icon_image_alt']; if (! empty(self::$shinkenParameters['shinken']['hosts']['vrml_image'])) $a_hosts[$i]['vrml_image'] = self::$shinkenParameters['shinken']['hosts']['vrml_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['statusmap_image'])) $a_hosts[$i]['statusmap_image'] = self::$shinkenParameters['shinken']['hosts']['statusmap_image']; $i++; // Add one fake host for each entity if (self::$shinkenParameters['shinken']['fake_hosts']['build']) { PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - add fake hosts for parents relationship\n" ); // Main root parent $a_hosts[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['root_parent']; $a_hosts[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . 'check_dummy!0'; $a_hosts[$i]['alias'] = 'Main root parent'; $a_hosts[$i]['_HOSTID'] = '0'; $a_hosts[$i]['_ITEMSID'] = '0'; $a_hosts[$i]['_ITEMTYPE'] = 'Computer'; $a_hosts[$i]['address'] = '127.0.0.1'; $a_hosts[$i]['parents'] = ''; $a_hosts[$i]['hostgroups'] = self::$shinkenParameters['shinken']['fake_hosts']['hostgroup_name']; $a_hosts[$i]['check_interval'] = '60'; $a_hosts[$i]['retry_interval'] = '1'; $a_hosts[$i]['max_check_attempts'] = '1'; $a_hosts[$i]['check_period'] = '24x7'; if (self::$shinkenParameters['shinken']['fake_contacts']['build']) { $a_hosts[$i]['contacts'] = self::$shinkenParameters['shinken']['fake_contacts']['contact_name']; } else { $a_hosts[$i]['contacts'] = ''; } if (! empty(self::$shinkenParameters['shinken']['fake_hosts']['use'])) $a_hosts[$i]['use'] = self::$shinkenParameters['shinken']['fake_hosts']['use']; if (! empty(self::$shinkenParameters['shinken']['hosts']['process_perf_data'])) $a_hosts[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['hosts']['process_perf_data']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_period'])) $a_hosts[$i]['notification_period'] = self::$shinkenParameters['shinken']['hosts']['notification_period']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_options'])) $a_hosts[$i]['notification_options'] = self::$shinkenParameters['shinken']['hosts']['notification_options']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_interval'])) $a_hosts[$i]['notification_interval'] = self::$shinkenParameters['shinken']['hosts']['notification_interval']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes'])) $a_hosts[$i]['notes'] = self::$shinkenParameters['shinken']['hosts']['notes']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes_url'])) $a_hosts[$i]['notes_url'] = self::$shinkenParameters['shinken']['hosts']['notes_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['action_url'])) $a_hosts[$i]['action_url'] = self::$shinkenParameters['shinken']['hosts']['action_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image'])) $a_hosts[$i]['icon_image'] = self::$shinkenParameters['shinken']['hosts']['icon_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image_alt'])) $a_hosts[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['hosts']['icon_image_alt']; if (! empty(self::$shinkenParameters['shinken']['hosts']['vrml_image'])) $a_hosts[$i]['vrml_image'] = self::$shinkenParameters['shinken']['hosts']['vrml_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['statusmap_image'])) $a_hosts[$i]['statusmap_image'] = self::$shinkenParameters['shinken']['hosts']['statusmap_image']; $i++; $a_entities_allowed = $pmEntity->getEntitiesByTag($tag); $a_entities_list = array(); foreach ($a_entities_allowed as $entity) { $a_entities_list = getSonsOf("glpi_entities", $entity); } $where = ''; if (! isset($a_entities_allowed['-1'])) { $where = getEntitiesRestrictRequest("WHERE", "glpi_entities", '', $a_entities_list); } $query = "SELECT `glpi_entities`.`id` AS entityId, `glpi_entities`.`name` AS entityName FROM `glpi_entities` $where"; $result = $DB->query($query); while ($dataEntity=$DB->fetch_array($result)) { // Hostgroup name : used as host name for parents ... $fake_host_name = strtolower(preg_replace("/[^A-Za-z0-9\-_ ]/","",$dataEntity['entityName'])); $fake_host_name = preg_replace("/[ ]/","_",$fake_host_name); $a_hosts[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . $fake_host_name; $a_hosts[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . 'check_dummy!0'; $a_hosts[$i]['alias'] = $dataEntity['entityName']; $a_hosts[$i]['_HOSTID'] = '0'; $a_hosts[$i]['_ITEMSID'] = '0'; $a_hosts[$i]['_ITEMTYPE'] = 'Computer'; $a_hosts[$i]['address'] = '127.0.0.1'; $a_hosts[$i]['parents'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['root_parent']; $a_hosts[$i]['hostgroups'] = self::$shinkenParameters['shinken']['fake_hosts']['hostgroup_name']; $a_hosts[$i]['check_interval'] = '60'; $a_hosts[$i]['retry_interval'] = '1'; $a_hosts[$i]['max_check_attempts'] = '1'; $a_hosts[$i]['check_period'] = '24x7'; if (self::$shinkenParameters['shinken']['fake_contacts']['build']) { $a_hosts[$i]['contacts'] = self::$shinkenParameters['shinken']['fake_contacts']['contact_name']; } else { $a_hosts[$i]['contacts'] = ''; } if (! empty(self::$shinkenParameters['shinken']['fake_hosts']['use'])) $a_hosts[$i]['use'] = self::$shinkenParameters['shinken']['fake_hosts']['use']; if (! empty(self::$shinkenParameters['shinken']['hosts']['process_perf_data'])) $a_hosts[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['hosts']['process_perf_data']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_period'])) $a_hosts[$i]['notification_period'] = self::$shinkenParameters['shinken']['hosts']['notification_period']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_options'])) $a_hosts[$i]['notification_options'] = self::$shinkenParameters['shinken']['hosts']['notification_options']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notification_interval'])) $a_hosts[$i]['notification_interval'] = self::$shinkenParameters['shinken']['hosts']['notification_interval']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes'])) $a_hosts[$i]['notes'] = self::$shinkenParameters['shinken']['hosts']['notes']; if (! empty(self::$shinkenParameters['shinken']['hosts']['notes_url'])) $a_hosts[$i]['notes_url'] = self::$shinkenParameters['shinken']['hosts']['notes_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['action_url'])) $a_hosts[$i]['action_url'] = self::$shinkenParameters['shinken']['hosts']['action_url']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image'])) $a_hosts[$i]['icon_image'] = self::$shinkenParameters['shinken']['hosts']['icon_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['icon_image_alt'])) $a_hosts[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['hosts']['icon_image_alt']; if (! empty(self::$shinkenParameters['shinken']['hosts']['vrml_image'])) $a_hosts[$i]['vrml_image'] = self::$shinkenParameters['shinken']['hosts']['vrml_image']; if (! empty(self::$shinkenParameters['shinken']['hosts']['statusmap_image'])) $a_hosts[$i]['statusmap_image'] = self::$shinkenParameters['shinken']['hosts']['statusmap_image']; $i++; } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateHostgroupsCfg\n" ); } // Check if parents all exist in hosts config foreach ($a_parents_found as $host => $num) { if (!isset($a_hosts_found[$host])) { // Delete parents not added in hosts config foreach ($a_hosts as $id=>$data) { if ($data['parents'] == $host) { $a_hosts[$id]['parents'] = ''; } } } } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateHostsCfg\n" ); if ($file == "1") { $config = "# Generated by plugin monitoring for GLPI\n# on ".date("Y-m-d H:i:s")."\n\n"; foreach ($a_hosts as $data) { $config .= $this->writeFile("host", $data); } return array('hosts.cfg', $config); } else { return $a_hosts; } }
function parseToDB($plugin_monitoring_services_id) { global $DB; $pmService = new PluginMonitoringService(); $pmComponent = new PluginMonitoringComponent(); if ($pmService->getFromDB($plugin_monitoring_services_id)) { $pmComponent->getFromDB($pmService->fields['plugin_monitoring_components_id']); if (!isset($pmComponent->fields['plugin_monitoring_commands_id'])) { return; } if (is_null($pmComponent->fields['graph_template'])) { return; } $pmUnavaibility = new PluginMonitoringUnavaibility(); $pmUnavaibility->runUnavaibility($plugin_monitoring_services_id); $a_dateold = array(); // *** 1 day (x 30 min) $dateold = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m'), date('d') - 1, date('Y'))); $a_dateold['30m'] = $dateold; // Gest last value, and see if we must calculate new values $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `type`='30m'\n ORDER BY `date` DESC\n LIMIT 1"; $result = $DB->query($query); $lastdate = $dateold; $new_date = ''; if ($DB->numrows($result) == '1') { $data = $DB->fetch_assoc($result); $new_date = PluginMonitoringServiceevent::convert_datetime_timestamp($data['date']); $new_date += 30 * 60; } else { $split = explode(" ", $lastdate); $a_time = explode(":", $split[1]); $a_date = explode("-", $split[0]); $new_date = date('U', mktime($a_time[0], '0', '0', $a_date[1], $a_date[2], $a_date[0])); } //get data in serviceevents for each 30 minutes from this date to now while ($new_date + 15 * 60 < date('U')) { $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `date` >= '" . date('Y-m-d H:i:m', $new_date - 15 * 60) . "'\n AND`date` <= '" . date('Y-m-d H:i:m', $new_date + 15 * 60) . "'\n ORDER BY `date`"; $result = $DB->query($query); // get data $mydatat = array(); $pmServiceevent = new PluginMonitoringServiceevent(); $pmService = new PluginMonitoringService(); $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template']); if (is_array($ret)) { $mydatat = $ret[0]; } $array_data = array(); foreach ($mydatat as $name => $a_values) { $array_data[$name] = round(array_sum($a_values) / count($a_values)); } $input = array(); $input['plugin_monitoring_services_id'] = $plugin_monitoring_services_id; $input['date'] = date('Y-m-d H:i:s', $new_date); $input['data'] = exportArrayToDB($array_data); $input['type'] = '30m'; $this->add($input); $new_date = $new_date + 30 * 60; } // *** 1w (x 6 hours) $dateold = date('Y-m-d H:i:s', date('U') - 7 * 24 * 3600); $a_dateold['6h'] = $dateold; // Gest last value, and see if we must calculate new values $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `type`='6h'\n ORDER BY `date` DESC\n LIMIT 1"; $result = $DB->query($query); $lastdate = $dateold; $new_date = ''; if ($DB->numrows($result) == '1') { $data = $DB->fetch_assoc($result); $new_date = PluginMonitoringServiceevent::convert_datetime_timestamp($data['date']); $new_date += 6 * 3600; } else { $split = explode(" ", $lastdate); $a_time = explode(":", $split[1]); $a_date = explode("-", $split[0]); $hour = '0'; $addtime = 0; if ($a_time[0] > 18) { $hour = 0; $addtime = 24 * 3600; } else { if ($a_time[0] > 12) { $hour = 18; } else { if ($a_time[0] > 6) { $hour = 12; } else { $hour = 6; } } } $new_date = date('U', mktime($hour, '0', '0', $a_date[1], $a_date[2], $a_date[0])) + $addtime; } //get data in serviceevents for each 6 hours from this date to now while ($new_date + 3 * 3600 < date('U')) { $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `date` >= '" . date('Y-m-d H:i:m', $new_date - 3 * 3600) . "'\n AND`date` <= '" . date('Y-m-d H:i:m', $new_date + 3 * 3600) . "'\n ORDER BY `date`"; $result = $DB->query($query); // get data $mydatat = array(); $pmServiceevent = new PluginMonitoringServiceevent(); $pmService = new PluginMonitoringService(); $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template']); if (is_array($ret)) { $mydatat = $ret[0]; } $array_data = array(); foreach ($mydatat as $name => $a_values) { $array_data[$name] = round(array_sum($a_values) / count($a_values)); } $input = array(); $input['plugin_monitoring_services_id'] = $plugin_monitoring_services_id; $input['date'] = date('Y-m-d H:i:s', $new_date); $input['data'] = exportArrayToDB($array_data); $input['type'] = '6h'; $this->add($input); $new_date = $new_date + 6 * 3600; } // *** 1m (x 1 day) $dateold = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m') - 1, date('d'), date('Y'))); // $a_dateold['1d'] = $dateold; //NOTE to keep data for each day (if we want use it in future) // Gest last value, and see if we must calculate new values $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `type`='1d'\n ORDER BY `date` DESC\n LIMIT 1"; $result = $DB->query($query); $lastdate = $dateold; $new_date = ''; if ($DB->numrows($result) == '1') { $data = $DB->fetch_assoc($result); $new_date = PluginMonitoringServiceevent::convert_datetime_timestamp($data['date']); $new_date += 24 * 3600; } else { $split = explode(" ", $lastdate); $a_date = explode("-", $split[0]); $new_date = date('U', mktime('0', '0', '0', $a_date[1], $a_date[2], $a_date[0])); } //get data in serviceevents for each 6 hours from this date to now while ($new_date + 12 * 3600 < date('U')) { $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `date` >= '" . date('Y-m-d H:i:m', $new_date - 12 * 3600) . "'\n AND`date` <= '" . date('Y-m-d H:i:m', $new_date + 12 * 3600) . "'\n ORDER BY `date`"; $result = $DB->query($query); // get data $mydatat = array(); $pmServiceevent = new PluginMonitoringServiceevent(); $pmService = new PluginMonitoringService(); $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template']); if (is_array($ret)) { $mydatat = $ret[0]; } $array_data = array(); foreach ($mydatat as $name => $a_values) { $array_data[$name] = round(array_sum($a_values) / count($a_values)); } $input = array(); $input['plugin_monitoring_services_id'] = $plugin_monitoring_services_id; $input['date'] = date('Y-m-d H:i:s', $new_date); $input['data'] = exportArrayToDB($array_data); $input['type'] = '1d'; $this->add($input); $new_date = $new_date + 24 * 3600; } // *** 6m (x 5 days) $dateold = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m') - 6, date('d'), date('Y'))); $a_dateold['5d'] = $dateold; // Gest last value, and see if we must calculate new values $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `type`='5d'\n ORDER BY `date` DESC\n LIMIT 1"; $result = $DB->query($query); $lastdate = $dateold; $new_date = ''; if ($DB->numrows($result) == '1') { $data = $DB->fetch_assoc($result); $new_date = PluginMonitoringServiceevent::convert_datetime_timestamp($data['date']); $new_date += 5 * 24 * 3600; } else { $split = explode(" ", $lastdate); $a_date = explode("-", $split[0]); $new_date = date('U', mktime('0', '0', '0', $a_date[1], $a_date[2], $a_date[0])); } //get data in serviceevents for each 6 hours from this date to now while ($new_date + 5 * 24 * 3600 / 2 < date('U')) { $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `date` >= '" . date('Y-m-d H:i:m', $new_date - 5 * 24 * 3600 / 2) . "'\n AND`date` <= '" . date('Y-m-d H:i:m', $new_date + 5 * 24 * 3600 / 2) . "'\n ORDER BY `date`"; $result = $DB->query($query); // get data $mydatat = array(); $pmServiceevent = new PluginMonitoringServiceevent(); $pmService = new PluginMonitoringService(); $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template']); if (is_array($ret)) { $mydatat = $ret[0]; } $array_data = array(); foreach ($mydatat as $name => $a_values) { $array_data[$name] = round(array_sum($a_values) / count($a_values)); } $input = array(); $input['plugin_monitoring_services_id'] = $plugin_monitoring_services_id; $input['date'] = date('Y-m-d H:i:s', $new_date); $input['data'] = exportArrayToDB($array_data); $input['type'] = '5d'; $this->add($input); $new_date = $new_date + 5 * 24 * 3600; } // *** 1y (x 10 days) $dateold = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m') - 10, date('d'), date('Y'))); $a_dateold['5d'] = $dateold; // Gest last value, and see if we must calculate new values $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `type`='10d'\n ORDER BY `date` DESC\n LIMIT 1"; $result = $DB->query($query); $lastdate = $dateold; $new_date = ''; if ($DB->numrows($result) == '1') { $data = $DB->fetch_assoc($result); $new_date = PluginMonitoringServiceevent::convert_datetime_timestamp($data['date']); $new_date += 10 * 24 * 3600; } else { $split = explode(" ", $lastdate); $a_date = explode("-", $split[0]); $new_date = date('U', mktime('0', '0', '0', $a_date[1], $a_date[2], $a_date[0])); } //get data in serviceevents for each 6 hours from this date to now while ($new_date + 5 * 24 * 3600 < date('U')) { $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `date` >= '" . date('Y-m-d H:i:m', $new_date - 5 * 24 * 3600) . "'\n AND`date` <= '" . date('Y-m-d H:i:m', $new_date + 5 * 24 * 3600) . "'\n ORDER BY `date`"; $result = $DB->query($query); // get data $mydatat = array(); $pmServiceevent = new PluginMonitoringServiceevent(); $pmService = new PluginMonitoringService(); $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template']); if (is_array($ret)) { $mydatat = $ret[0]; } $array_data = array(); foreach ($mydatat as $name => $a_values) { $array_data[$name] = round(array_sum($a_values) / count($a_values)); } $input = array(); $input['plugin_monitoring_services_id'] = $plugin_monitoring_services_id; $input['date'] = date('Y-m-d H:i:s', $new_date); $input['data'] = exportArrayToDB($array_data); $input['type'] = '10d'; $this->add($input); $new_date = $new_date + 10 * 24 * 3600; } // *** Delete old values foreach ($a_dateold as $name => $date) { $query = "DELETE FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $plugin_monitoring_services_id . "'\n AND `type`='" . $name . "'\n AND `date` < '" . $date . "'"; $result = $DB->query($query); } } }