function displayHubConnections($items_id, $background_img) { $NetworkPort = new NetworkPort(); $a_ports = $NetworkPort->find("`itemtype`='PluginFusioninventoryUnmanaged'\n AND `items_id`='" . $items_id . "'"); echo "<table width='100%' class='tab_cadre' cellpadding='5'>"; foreach ($a_ports as $a_port) { if ($a_port['name'] != "Link") { $id = $NetworkPort->getContact($a_port['id']); if ($id) { $NetworkPort->getFromDB($id); $link = ''; $link1 = ''; $link2 = ''; if ($NetworkPort->fields['itemtype'] == 'PluginFusioninventoryUnmanaged') { $classname = $NetworkPort->fields['itemtype']; $item = new $classname(); $item->getFromDB($NetworkPort->fields['items_id']); $link1 = $item->getLink(1); $link = str_replace($item->getName(0), $NetworkPort->fields["mac"], $item->getLink()); // Get ips $a_ips = PluginFusioninventoryToolbox::getIPforDevice('PluginFusioninventoryUnmanaged', $item->getID()); $link2 = str_replace($item->getName(0), implode(", ", $a_ips), $item->getLink()); $icon = $this->getItemtypeIcon($item->fields["item_type"]); if ($item->fields['accepted'] == 1) { echo "<tr>"; echo "<td align='center' style='background:#bfec75'\n class='tab_bg_1_2'>" . $icon . $item->getLink(1); } else { echo "<tr>"; echo "<td align='center' style='background:#cf9b9b'\n class='tab_bg_1_2'>" . $icon . $item->getLink(1); } if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } echo "</td>"; echo "</tr>"; } else { $classname = $NetworkPort->fields['itemtype']; $item = new $classname(); $item->getFromDB($NetworkPort->fields['items_id']); $link1 = $item->getLink(1); $link = str_replace($item->getName(0), $NetworkPort->fields["mac"], $item->getLink()); // $link2 = str_replace($item->getName(0), $NetworkPort->fields["ip"], // $item->getLink()); echo "<tr>"; $icon = $this->getItemtypeIcon($classname); echo "<td align='center' " . $background_img . "\n class='tab_bg_1_2'>" . $icon . $item->getLink(1); if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } echo "</td>"; echo "</tr>"; } } } } echo "</table>"; }
function run($jobstate) { $pfAgent = new PluginFusioninventoryAgent(); $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $pfConfigSecurity = new PluginFusioninventoryConfigSecurity(); $pfToolbox = new PluginFusioninventoryToolbox(); $current = $jobstate; $pfAgent->getFromDB($current->fields['plugin_fusioninventory_agents_id']); $ip = current(PluginFusioninventoryToolbox::getIPforDevice($jobstate->fields['itemtype'], $jobstate->fields['items_id'])); if ($ip == '') { $pfTaskjobstate->changeStatusFinish($jobstate->fields['id'], $jobstate->fields['items_id'], $jobstate->fields['itemtype'], 1, "Device have no ip"); } else { $sxml_option = $this->message->addChild('OPTION'); $sxml_option->addChild('NAME', 'SNMPQUERY'); $sxml_param = $sxml_option->addChild('PARAM'); $sxml_param->addAttribute('THREADS_QUERY', $pfAgent->fields["threads_networkinventory"]); $sxml_param->addAttribute('TIMEOUT', $pfAgent->fields["timeout_networkinventory"]); $sxml_param->addAttribute('PID', $current->fields['id']); $changestate = 0; $taskjobstatedatas = $jobstate->fields; $sxml_device = $sxml_option->addChild('DEVICE'); $a_extended = array('plugin_fusioninventory_configsecurities_id' => 0); if ($jobstate->fields['itemtype'] == 'Printer') { $sxml_device->addAttribute('TYPE', 'PRINTER'); $pfPrinter = new PluginFusioninventoryPrinter(); $a_extended = current($pfPrinter->find("`printers_id`='" . $jobstate->fields['items_id'] . "'", '', 1)); } else { if ($jobstate->fields['itemtype'] == 'NetworkEquipment') { $sxml_device->addAttribute('TYPE', 'NETWORKING'); $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment(); $a_extended = current($pfNetworkEquipment->find("`networkequipments_id`='" . $jobstate->fields['items_id'] . "'", '', 1)); } } $sxml_device->addAttribute('ID', $jobstate->fields['items_id']); $sxml_device->addAttribute('IP', $ip); $sxml_device->addAttribute('AUTHSNMP_ID', $a_extended['plugin_fusioninventory_configsecurities_id']); if ($changestate == '0') { $pfTaskjobstate->changeStatus($taskjobstatedatas['id'], 1); $pfTaskjoblog->addTaskjoblog($taskjobstatedatas['id'], '0', 'PluginFusioninventoryAgent', '1', $pfAgent->fields["threads_networkinventory"] . ' threads', $pfAgent->fields["timeout_networkinventory"] . ' timeout'); $changestate = $pfTaskjobstate->fields['id']; } else { $pfTaskjobstate->changeStatusFinish($taskjobstatedatas['id'], $taskjobstatedatas['items_id'], $taskjobstatedatas['itemtype'], 0, "Merged with " . $changestate); } $snmpauthlist = $pfConfigSecurity->find(); if (count($snmpauthlist)) { foreach ($snmpauthlist as $snmpauth) { $pfToolbox->addAuth($sxml_option, $snmpauth['id']); } } } return $this->message; }
/** * Get all IP of an agent or a computer * * @param $items_id integer ID of the item * @param $type 'Agent' by default to get IP of agent or of a computer if set other text * * @return Every IP addresses registered for this agent or false * **/ function getIPs() { $ip_addresses = array(); $computers_id = 0; if (isset($this->fields['computers_id'])) { if ($this->fields['computers_id'] > 0) { } } else { trigger_error('Agent must be initialized'); } $ip_addresses = PluginFusioninventoryToolbox::getIPforDevice('Computer', $this->fields['computers_id']); return $ip_addresses; }