public function testPHPlogs() { global $CFG_GLPI, $PLUGIN_HOOKS; $_SESSION['glpi_use_mode'] = 2; $_SESSION["glpiID"] = 2; $_SESSION["glpiactiveentities_string"] = 0; $PLUGIN_HOOKS = plugin_init_monitoring(); plugin::load("monitoring"); $CFG_GLPI['root_doc'] = "http://127.0.0.1/fusion0.80/"; loadLanguage("en_GB"); $pmComponent = new PluginMonitoringComponent(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmService = new PluginMonitoringService(); $computer = new Computer(); // Add components $input = array(); $input['name'] = 'Host alive'; $input['plugin_monitoring_commands_id '] = '21'; $input['plugin_monitoring_checks_id'] = '1'; $input['calendars_id'] = '1'; $components_id = $pmComponent->add($input); // Add components catalog $input = array(); $input['name'] = 'linux servers'; $catalogs_id = $pmComponentscatalog->add($input); $input = array(); $input['plugin_monitoring_componentscalalog_id'] = $catalogs_id; $input['plugin_monitoring_components_id'] = $components_id; $pmComponentscatalog_Component->add($input); // Add Computer $input = array(); $input['name'] = 'pc1'; $input['entities_id'] = 0; $pc1 = $computer->add($input); // Check computer pc1 not added in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '0', '[f1] Computer in component cataglog and may not be'); $input = array(); $input['plugin_monitoring_componentscalalog_id'] = $catalogs_id; $input['name'] = 'all have name'; $input['itemtype'] = 'Computer'; $input['condition'] = '{"field":["1"],"searchtype":["contains"],"contains":["pc"],"itemtype":"Computer","start":"0"}'; $rules_id = $pmComponentscatalog_rule->add($input); // Check computer pc1 not added in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '1', '[f2] Computer may be in component catalog'); // Check service of this computer created $a_services = $pmService->find(); $this->assertEquals(count($a_services), '1', '[s2] One service may be created'); // Add Computer $input = array(); $input['name'] = 'pc2'; $input['entities_id'] = 0; $pc2 = $computer->add($input); // Check computer pc1 not added in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '2', '[f3] 2 computers may be in component catalog'); // Check service of this computer created $a_services = $pmService->find(); $this->assertEquals(count($a_services), '2', '[s3] 2 services may be created'); // Remove pc2 $computer->delete(array('id' => $pc2), 1); // Check computer pc1 added in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '1', '[f4] Computer may be unique in component catalog'); // Check service of this computer created $a_services = $pmService->find(); $this->assertEquals(count($a_services), '1', '[s4] One service may be created'); // Modify rule $input['id'] = $rules_id; $input['condition'] = '{"field":["1"],"searchtype":["contains"],"contains":["tc"],"itemtype":"Computer","start":"0"}'; $pmComponentscatalog_rule->update($input); // Check no computer in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '0', '[f5] Computer may be deleted on rule update'); // Check service $a_services = $pmService->find(); $this->assertEquals(count($a_services), '0', '[s5] No service may be created'); // Modify rule $input['id'] = $rules_id; $input['condition'] = '{"field":["1"],"searchtype":["contains"],"contains":["pc"],"itemtype":"Computer","start":"0"}'; $pmComponentscatalog_rule->update($input); // Check computer pc1 added in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '1', '[f6] Computer may be unique in component catalog'); // Delete rule $pmComponentscatalog_rule->delete(array('id' => $rules_id), 1); // Check not have computer in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '0', '[f7] must have no computer in component catalog'); // Check service $a_services = $pmService->find(); $this->assertEquals(count($a_services), '0', '[s7] No service may be created'); }
function linkComponentsToItem($componentscatalogs_id, $componentscatalogs_hosts_id, $networkports_id = 0) { global $DB; $pmService = new PluginMonitoringService(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmComponentscatalog_Host->getFromDB($componentscatalogs_hosts_id); $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_components`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $input = array(); $itemtype = $pmComponentscatalog_Host->fields['itemtype']; $item = new $itemtype(); $item->getFromDB($pmComponentscatalog_Host->fields['items_id']); if ($networkports_id == 0) { $input['entities_id'] = $item->fields['entities_id']; $input['plugin_monitoring_componentscatalogs_hosts_id'] = $componentscatalogs_hosts_id; $input['plugin_monitoring_components_id'] = $data['plugin_monitoring_components_id']; $input['name'] = Dropdown::getDropdownName("glpi_plugin_monitoring_components", $data['plugin_monitoring_components_id']); $input['state'] = 'WARNING'; $input['state_type'] = 'HARD'; $pmService->add($input); } else { if ($networkports_id > 0) { $a_services = $pmService->find("`plugin_monitoring_components_id`='" . $data['plugin_monitoring_components_id'] . "'\n AND `plugin_monitoring_componentscatalogs_hosts_id`='" . $componentscatalogs_hosts_id . "'\n AND `networkports_id`='" . $networkports_id . "'", "", 1); $item = new NetworkPort(); $item->getFromDB($networkports_id); if (count($a_services) == 0) { $input = array(); $input['networkports_id'] = $networkports_id; $input['entities_id'] = $item->fields['entities_id']; $input['plugin_monitoring_componentscatalogs_hosts_id'] = $componentscatalogs_hosts_id; $input['plugin_monitoring_components_id'] = $data['plugin_monitoring_components_id']; $input['name'] = Dropdown::getDropdownName("glpi_plugin_monitoring_components", $data['plugin_monitoring_components_id']); $input['state'] = 'WARNING'; $input['state_type'] = 'HARD'; $pmService->add($input); } else { $a_service = current($a_services); $queryu = "UPDATE `glpi_plugin_monitoring_services`\n SET `entities_id`='" . $item->fields['entities_id'] . "'\n WHERE `id`='" . $a_service['id'] . "'"; $DB->query($queryu); } } } } }
------------------------------------------------------------------------ @package Plugin Monitoring for GLPI @author David Durieux @co-author @comment @copyright Copyright (c) 2011-2012 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 ------------------------------------------------------------------------ */ define('GLPI_ROOT', '../..'); include GLPI_ROOT . "/inc/includes.php"; $a_services = array(); $pmService = new PluginMonitoringService(); $a_services = $pmService->find("`plugin_monitoring_components_id`='12'"); for ($i = 0; $i < 1000000000; $i++) { foreach ($a_services as $id => $data) { $perf = "inUsage=0.00%;85;98 outUsage=0.00%;85;98 " . "inBandwidth=" . rand(1, 100000) . ".00bps outBandwidth=" . rand(1, 100000) . ".00bps inAbsolut=0 outAbsolut=12665653"; $ins = "INSERT INTO `glpi_plugin_monitoring_serviceevents`\n (`plugin_monitoring_services_id`, `date`, `perf_data`, `state`, `state_type`)\n VALUES('" . $id . "', '" . date('Y-m-d H:i:s') . "', '" . $perf . "', 'OK', 'HARD')"; $DB->query($ins); $rand = rand(0, 100); if ($rand < 40) { sleep(1); } } } commonFooter();
static function cronUpdaterrd() { ini_set("max_execution_time", "0"); // $pmServiceevent = new PluginMonitoringServiceevent(); $pmService = new PluginMonitoringService(); $pmServicegraph = new PluginMonitoringServicegraph(); $a_lisths = $pmService->find(); foreach ($a_lisths as $data) { $pmServicegraph->parseToDB($data['id']); } return true; }