@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 2012 ------------------------------------------------------------------------ */ include "../../../inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $pmWeathermapnode->getFromDB($_POST['items_id']); echo "<br/>"; echo __('Host', 'monitoring') . " : "; $itemtype = $pmWeathermapnode->fields['itemtype']; $item = new $itemtype(); $item->getFromDB($pmWeathermapnode->fields['items_id']); echo $item->getLink(1); echo "<br/>"; echo __('Name') . " : "; echo "<input type='text' name='nameupdate' value='" . $pmWeathermapnode->fields['name'] . "' /><br/>"; $positions = array('middle' => __('Center', 'monitoring'), 'start' => __('Right', 'monitoring'), 'end' => __('Left', 'monitoring')); echo __('Position of label', 'monitoring') . " : "; Dropdown::showFromArray('position', $positions, array('value' => $pmWeathermapnode->fields['position'])); echo "<script language='JavaScript'>\ndocument.pointform.x.value = " . $pmWeathermapnode->fields['x'] . ";\ndocument.pointform.y.value = " . $pmWeathermapnode->fields['y'] . ";\n</script>";
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 configureNodesLinks($weathermaps_id) { global $DB, $CFG_GLPI; $networkPort = new NetworkPort(); $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $this->getFromDB($weathermaps_id); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='2'>"; echo __('Nodes and links', 'monitoring'); echo "</th>"; echo "</tr>"; $this->generateWeathermap($weathermaps_id, 1, 1); $map = "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=weathermap-" . $weathermaps_id . ".png'/>"; echo "<tr class='tab_bg_1'>"; echo "<td valign='top' width='10'>"; if ($this->fields['background'] == '') { echo '<script language="JavaScript" type="text/JavaScript"> function FindPosition(oElement) { if(typeof( oElement.offsetParent ) != "undefined") { for(var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) { posX += oElement.offsetLeft; posY += oElement.offsetTop; } return [ posX, posY ]; } else { return [ oElement.x, oElement.y ]; } } function GetCoordinates(e) { var PosX = 0; var PosY = 0; var ImgPos; ImgPos = FindPosition(myImg); if (!e) var e = window.event; if (e.pageX || e.pageY) { PosX = e.pageX; PosY = e.pageY; } else if (e.clientX || e.clientY) { PosX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; PosY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } PosX = PosX - ImgPos[0]; PosY = PosY - ImgPos[1]; document.pointform.x.value = PosX; document.pointform.y.value = PosY; } var myImg = document.getElementById("myImgId"); myImg.onmousedown = GetCoordinates; </script>'; echo "<div><img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=weathermap-" . $weathermaps_id . ".png'/>"; echo "<div style='position: absolute; top:40px;' id='myImgId' >\n <table class='gridweathermap' width='" . $this->fields['width'] . "' \n height='" . $this->fields['height'] . "'>"; $line = ''; $nbcol = ceil($this->fields['width'] / 15); for ($num = 0; $num < $nbcol; $num++) { $line .= "<td></td>"; } $line = '<tr>' . $line . '</tr>'; $nbline = ceil($this->fields['height'] / 15); for ($num = 0; $num < $nbline; $num++) { echo $line; } echo "</table></div></div>"; } else { echo '<div id="pointer_div" onclick="point_it(event)" style = "background-image:url(\'' . $this->fields['background'] . '\');"> <img id="cross" style="position:relative;visibility:hidden;z-index:2;"> ' . $map . '</div>'; echo '<script language="JavaScript"> function point_it(event){ pos_x = event.offsetX?(event.offsetX):event.pageX; pos_y = event.offsetY?(event.offsetY):event.pageY; document.getElementById("cross").style.left = (pos_x-1) ; document.getElementById("cross").style.top = (pos_y-15) ; var topValue= 0; var leftValue= 0; var obj = document.getElementById("pointer_div"); while(obj){ leftValue+= obj.offsetLeft; topValue+= obj.offsetTop; obj= obj.offsetParent; } document.pointform.x.value = pos_x-leftValue; document.pointform.y.value = pos_y-topValue; } </script>'; } echo "</td>"; echo "<td valign='top'>"; echo "<div style='position: fixed;top: 30px;right: 0;z-index:999;' >"; echo "<table class='tab_cadre' width='100%'>"; echo "<tr>"; echo "<td>"; echo "<a onClick='Ext.get(\"weathermapform\").toggle();'>\n <img src='" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png' /> \n " . __('Display weathermap form', 'monitoring') . "\n <img src='" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png' /></a>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; echo "<div style='position: fixed;top: 50px;right: 0;z-index:1000;' id='weathermapform' >"; echo '<form name="pointform" method="post" action="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/front/weathermapnode.form.php">'; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<table class='tab_cadre' width='100%'>"; echo "<tr>"; echo "<th colspan='2'>"; echo "x : "; echo '<input type="text" name="x" size="4" />'; echo " "; echo "y : "; echo '<input type="text" name="y" size="4" />'; echo "</th>"; echo "</tr>"; // * Add node echo "<tr>"; echo "<th colspan='2'>"; echo "<input type='hidden' name='plugin_monitoring_weathermaps_id' value='" . $weathermaps_id . "' />"; echo __('Add a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Node', 'monitoring') . " :"; echo "</td>"; echo "<td>"; Dropdown::showAllItems("items_id"); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Name') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='name' value='' />"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Change node position echo "<tr>"; echo "<th colspan='2'>"; echo __('Edit a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2' align='center'>"; $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; if ($itemtype == '0') { $pmWeathermapnode->delete($data); } else { $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } } $rand = Dropdown::showFromArray('id_update', $elements); $params = array('items_id' => '__VALUE__', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_id_update{$rand}", "show_updatenode{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownWnode.php", $params, false); echo "<span id='show_updatenode{$rand}'></span>\n"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='update' value=\"" . __('Save') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Delete node echo "<tr>"; echo "<th colspan='2'>"; echo __('Delete a node', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "</td>"; echo "<td>"; $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } Dropdown::showFromArray('id', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='purge' value=\"" . __('Delete permanently') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo '<form name="formlink" method="post" action="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/front/weathermaplink.form.php">'; echo "<table class='tab_cadre' width='100%'>"; // *Add Link echo "<tr>"; echo "<th colspan='2'>"; echo __('Add a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Source', 'monitoring') . "* :"; echo "</td>"; echo "<td>"; $query = "SELECT `glpi_plugin_monitoring_weathermapnodes`.`id` as `id`,\n `glpi_plugin_monitoring_weathermapnodes`.`name` as `name`,\n `glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`, \n `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id`,\n `glpi_plugin_monitoring_services`.`id` as `services_id`,\n `glpi_plugin_monitoring_components`.`name` as `components_name`,\n `plugin_monitoring_commands_id`, `glpi_plugin_monitoring_components`.`arguments`,\n `glpi_plugin_monitoring_services`.`networkports_id`\n FROM `glpi_plugin_monitoring_weathermapnodes`\n \n LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`\n ON (`glpi_plugin_monitoring_weathermapnodes`.`items_id`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id`\n AND `glpi_plugin_monitoring_weathermapnodes`.`itemtype`=`glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`)\n \n LEFT JOIN `glpi_plugin_monitoring_services` \n ON `plugin_monitoring_componentscatalogs_hosts_id`= `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`\n\n LEFT JOIN `glpi_plugin_monitoring_components` \n ON `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`\n \n\n WHERE `is_weathermap` = '1'\n AND `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `itemtype`,`items_id`,`glpi_plugin_monitoring_components`.`name`"; $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $elements2 = array(); $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } // Try to get device/node connected on this port $device_connected = ''; if ($data['arguments'] != '') { $arguments = importArrayFromDB($data['arguments']); foreach ($arguments as $argument) { if (!is_numeric($argument)) { if (strstr($argument, "[[NETWORKPORTDESCR]]")) { if (class_exists("PluginFusinvsnmpNetworkPort")) { $pfNetworkPort = new PluginFusinvsnmpNetworkPort(); $pfNetworkPort->loadNetworkport($data['networkports_id']); $argument = $pfNetworkPort->getValue("ifdescr"); } } elseif (strstr($argument, "[[NETWORKPORTNUM]]")) { $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $argument = $pfNetworkPort->fields['logical_number']; } elseif (strstr($argument, "[[NETWORKPORTNAME]]")) { $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $argument = $pfNetworkPort->fields['name']; } // Search networkport have this name or description $a_ports = $networkPort->find("`itemtype`='" . $itemtype . "'\n AND `items_id`='" . $data['items_id'] . "'\n AND `name`='" . $argument . "'"); foreach ($a_ports as $pdata) { if ($device_connected == '') { $oppositeports_id = $networkPort->getContact($pdata['id']); if ($oppositeports_id) { $networkPort->getFromDB($oppositeports_id); $a_nodes = $pmWeathermapnode->find("\n `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n AND `itemtype`='" . $networkPort->fields['itemtype'] . "'\n AND `items_id`='" . $networkPort->fields['items_id'] . "'", "", 1); if (count($a_nodes) > 0) { $a_node = current($a_nodes); $device_connected = $pmWeathermapnode->getNodeName($a_node['id']); } } } } if ($device_connected == '' and class_exists("PluginFusinvsnmpNetworkPort")) { $queryn = "SELECT `glpi_networkports`.`id` FROM `glpi_plugin_fusinvsnmp_networkports`\n \n LEFT JOIN `glpi_networkports`\n ON `glpi_networkports`.`id`=`networkports_id`\n \n WHERE `itemtype`='" . $itemtype . "'\n AND `items_id`='" . $data['items_id'] . "'\n AND `ifdescr`='" . $argument . "'"; $resultn = $DB->query($queryn); while ($pdata = $DB->fetch_array($resultn)) { if ($device_connected == '') { $oppositeports_id = $networkPort->getContact($pdata['id']); if ($oppositeports_id) { $networkPort->getFromDB($oppositeports_id); $a_nodes = $pmWeathermapnode->find("\n `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n AND `itemtype`='" . $networkPort->fields['itemtype'] . "'\n AND `items_id`='" . $networkPort->fields['items_id'] . "'", "", 1); if (count($a_nodes) > 0) { $a_node = current($a_nodes); $queryl = "SELECT `plugin_monitoring_weathermapnodes_id_1`\n FROM `glpi_plugin_monitoring_weathermaplinks`\n\n LEFT JOIN `glpi_plugin_monitoring_weathermapnodes`\n ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1`\n\n WHERE ((`plugin_monitoring_weathermapnodes_id_1`='" . $data['id'] . "'\n AND `plugin_monitoring_weathermapnodes_id_2`='" . $a_node['id'] . "')\n OR (`plugin_monitoring_weathermapnodes_id_1`='" . $a_node['id'] . "'\n AND `plugin_monitoring_weathermapnodes_id_2`='" . $data['id'] . "'))\n AND `plugin_monitoring_weathermaps_id` = '" . $weathermaps_id . "'"; $resultl = $DB->query($queryl); if ($DB->numrows($resultl) == '0') { $device_connected = $pmWeathermapnode->getNodeName($a_node['id']); } } } } } } } } } if ($device_connected == '') { $networkPort->getFromDB($data['networkports_id']); $elements2[$data['id'] . "-" . $data['services_id']] = $name . " [" . $networkPort->getfield('name') . "] (" . $data['components_name'] . ")"; } else { $networkPort->getFromDB($data['networkports_id']); $elements[$data['id'] . "-" . $data['services_id']] = $name . " [" . $networkPort->getfield('name') . "] (" . $data['components_name'] . ") > " . $device_connected; } } if (count($elements) > 1 and count($elements2) > 0) { $elements = array_merge($elements, array('0' => Dropdown::EMPTY_VALUE)); $elements = array_merge($elements, $elements2); } else { $elements = array_merge($elements, $elements2); } Dropdown::showFromArray('linksource', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Destination', 'monitoring') . " :"; echo "</td>"; echo "<td>"; echo "<div id='nodedestination'>"; $query = "SELECT * FROM `" . getTableForItemType("PluginMonitoringWeathermapnode") . "`\n WHERE `plugin_monitoring_weathermaps_id`='" . $weathermaps_id . "'\n ORDER BY `name`"; $result = $DB->query($query); $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name = $data['name']; if ($name == '') { $name = $item->getName(); } $elements[$data['id']] = $name; } Dropdown::showFromArray('plugin_monitoring_weathermapnodes_id_2', $elements); echo "</div>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Max bandwidth input', 'monitoring') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='bandwidth_in' value=''/>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo __('Max bandwidth output', 'monitoring') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='bandwidth_out' value=''/>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; // * Edit link echo "<tr>"; echo "<th colspan='2'>"; echo __('Edit a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2' align='center'>"; $pmWeathermapnode = new PluginMonitoringWeathermapnode(); $query = "SELECT `glpi_plugin_monitoring_weathermaplinks`.`id` as `id`,\n `itemtype`, `items_id`, `name`, `plugin_monitoring_weathermapnodes_id_2`\n FROM `glpi_plugin_monitoring_weathermaplinks`\n \n LEFT JOIN `glpi_plugin_monitoring_weathermapnodes`\n ON `glpi_plugin_monitoring_weathermapnodes`.`id` = `plugin_monitoring_weathermapnodes_id_1`\n\n WHERE `plugin_monitoring_weathermaps_id` = '" . $weathermaps_id . "'"; $elements = array(); $elements[0] = Dropdown::EMPTY_VALUE; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); $name1 = $data['name']; if ($name1 == '') { $name1 = $item->getName(); } $pmWeathermapnode->getFromDB($data['plugin_monitoring_weathermapnodes_id_2']); $itemtype = $pmWeathermapnode->fields['itemtype']; $item = new $itemtype(); $item->getFromDB($pmWeathermapnode->fields['items_id']); $name2 = $pmWeathermapnode->fields['name']; if ($name2 == '') { $name2 = $item->getName(); } $elements[$data['id']] = $name1 . " - " . $name2; } $rand = Dropdown::showFromArray('id_update', $elements); $params = array('items_id' => '__VALUE__', 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown_id_update{$rand}", "show_updatelink{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownWlink.php", $params, false); echo "<span id='show_updatelink{$rand}'></span>\n"; echo "</td>"; echo "</tr>"; // * Delete link echo "<tr>"; echo "<th colspan='2'>"; echo __('Delete a link', 'monitoring'); echo "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "Link :"; echo "</td>"; echo "<td>"; Dropdown::showFromArray('id', $elements); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='2'>"; echo "<input type='submit' name='purge' value=\"" . __('Delete permanently') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>"; echo "</table>"; echo "</div>"; echo "</td>"; echo "</tr>"; }
@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::checkRight("plugin_monitoring_weathermap", READ); Html::header(__('Monitoring', 'monitoring'), $_SERVER["PHP_SELF"], "plugins", "monitoring", "weathermapnode"); $pmWeathermapnode = new PluginMonitoringWeathermapnode(); if (isset($_POST["add"])) { if ($_POST['x'] == '') { Html::back(); exit; } $pmWeathermapnode->add($_POST); Html::back(); } else { if (isset($_POST["update"])) { if ($_POST['x'] == '') { Html::back(); exit; } unset($_POST['name']); $_POST['name'] = $_POST['nameupdate'];
the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -------------------------------------------------------------------------- */ // ---------------------------------------------------------------------- // Original Author of file: David DURIEUX // Purpose of file: // ---------------------------------------------------------------------- // Direct access to file if (strpos($_SERVER['PHP_SELF'], "updateWeathermap.php")) { include "../../../inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); } if (!defined('GLPI_ROOT')) { die("Can not acces directly to this file"); } $pmWeathermapnode = new PluginMonitoringWeathermapnode(); if (isset($_POST['id'])) { $pmWeathermapnode->update($_POST); } Html::ajaxFooter();