/** * Display graphs of services associated with host * * @param $itemtype value type of item * @param $items_id integer id of the object * **/ function showGraphsByHost($itemtype, $items_id) { global $CFG_GLPI,$DB; PluginMonitoringToolbox::loadLib(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponent = new PluginMonitoringComponent(); $pmServicegraph = new PluginMonitoringServicegraph(); $networkPort = new NetworkPort(); $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts` WHERE `items_id`='".$items_id."' AND `itemtype`='".$itemtype."'"; $result = $DB->query($query); 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 "<table class='tab_cadre_fixe'>"; while ($data=$DB->fetch_array($result)) { $pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']); $querys = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services` LEFT JOIN `glpi_plugin_monitoring_components` on `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id` WHERE `plugin_monitoring_componentscatalogs_hosts_id`='".$data['id']."' ORDER BY `name`"; $results = $DB->query($querys); while ($datas=$DB->fetch_array($results)) { $pmComponent->getFromDB($datas['plugin_monitoring_components_id']); if ($pmComponent->fields['graph_template'] != 0) { echo "<tr>"; echo "<td>"; echo "<table class='tab_cadre'>"; echo "<tr class='tab_bg_3'>"; echo "<th>"; echo "<a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/display.form.php?itemtype=PluginMonitoringService&items_id=".$datas['id']."'>"; echo $pmComponent->fields['name']; echo "</a>"; if (!is_null($datas['networkports_id']) && $datas['networkports_id'] > 0) { $networkPort->getFromDB($datas['networkports_id']); echo " [".$networkPort->getLink()."]"; } echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td style='position: relative'>"; $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $datas['id'], "0", "2h", "", 920); echo "</td>"; echo "</tr>"; echo "</table>"; echo "</td>"; echo "</tr>"; } } } echo "</tr>"; echo "</table>"; }
/** * Display services associated with host * * @param $itemtype value type of item * @param $items_id integer id of the object * **/ function listByHost($itemtype, $items_id) { global $LANG, $CFG_GLPI, $DB; $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `items_id`='" . $items_id . "'\n AND `itemtype`='" . $itemtype . "'"; $result = $DB->query($query); // echo "<form name='form' method='post' // action='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/service.form.php'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='5'>"; echo $LANG['plugin_monitoring']['service'][0]; // echo " <a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/service.form.php?services_id=".$a_hosts['id']."'> // <img src='".$CFG_GLPI['root_doc']."/pics/menu_add.png' /></a>"; // // echo " <a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/servicedef.form.php?add_template=1'> // <img src='".$CFG_GLPI['root_doc']."/pics/menu_addtemplate.png' /></a>"; echo "</th>"; echo "</tr>"; echo "<table>"; while ($data = $DB->fetch_array($result)) { $pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='12'>" . $pmComponentscatalog->getTypeName() . " : " . $pmComponentscatalog->getLink() . "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>"; echo $LANG['joblist'][0]; echo "</th>"; echo "<th>"; echo $LANG['entity'][0]; echo "</th>"; echo "<th>"; echo $LANG['stats'][7]; echo "</th>"; echo "<th>"; echo $LANG['plugin_monitoring']['component'][0]; echo "</th>"; echo "<th>"; echo $LANG['state'][0]; echo "</th>"; echo "<th>"; echo $LANG['plugin_monitoring']['service'][18]; echo "</th>"; echo "<th>"; echo $LANG['rulesengine'][82]; echo "</th>"; echo "<th>"; echo $LANG['plugin_monitoring']['host'][9]; echo "</th>"; echo "<th>" . $LANG['plugin_monitoring']['availability'][1] . " " . showToolTip($LANG['plugin_monitoring']['availability'][0], array('display' => false)) . "</th>"; echo "<th>" . $LANG['plugin_monitoring']['availability'][2] . " " . showToolTip($LANG['plugin_monitoring']['availability'][0], array('display' => false)) . "</th>"; echo "<th>" . $LANG['plugin_monitoring']['availability'][3] . " " . showToolTip($LANG['plugin_monitoring']['availability'][0], array('display' => false)) . "</th>"; echo "<th>"; echo $LANG['plugin_monitoring']['service'][4]; echo "</th>"; echo "</tr>"; $querys = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services`\n LEFT JOIN `glpi_plugin_monitoring_components`\n on `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`\n WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $data['id'] . "'\n ORDER BY `name`"; $results = $DB->query($querys); while ($datas = $DB->fetch_array($results)) { $this->getFromDB($datas['id']); echo "<tr class='tab_bg_1'>"; PluginMonitoringDisplay::displayLine($datas, 0); echo "</tr>"; } echo "</table>"; } // echo "<tr class='tab_bg_1'>"; // echo "<td colspan='8' align='center'>"; // echo "<input type='submit' class='submit' name='update' value='".$LANG['buttons'][7]."'>"; // echo "</td>"; // echo "</tr>"; echo "</table>"; echo "</form>"; }
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Monitoring. If not, see <http://www.gnu.org/licenses/>. ------------------------------------------------------------------------ @package Plugin Monitoring for GLPI @author David Durieux @co-author @comment @copyright Copyright (c) 2011-2013 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"; PluginMonitoringProfile::checkRight("componentscatalog", "w"); // //Html::header(__('Monitoring', 'monitoring'),$_SERVER["PHP_SELF"], "plugins", // "monitoring", "reports"); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); if ($_POST['reporttype'] == 'simplereport') { $pmComponentscatalog->generateReport($_POST); } else { $pmComponentscatalog->generateSyntheseReport($_POST); }
function generateServicesCfg($file=0, $tag='') { global $DB; PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Starting generateServicesCfg services ($tag) ...\n" ); $pMonitoringCommand = new PluginMonitoringCommand(); $pmEventhandler = new PluginMonitoringEventhandler(); $pMonitoringCheck = new PluginMonitoringCheck(); $pmComponent = new PluginMonitoringComponent(); $pmEntity = new PluginMonitoringEntity(); $pmContact_Item = new PluginMonitoringContact_Item(); $networkPort = new NetworkPort(); $pmService = new PluginMonitoringService(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmHostconfig = new PluginMonitoringHostconfig(); $calendar = new Calendar(); $user = new User(); $profile_User = new Profile_User(); $a_services = array(); $i=0; // TODO: only contacts in allowed entities ... // Prepare individual 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; } // Prepare groups contacts $group = new Group(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog' AND `groups_id`>0"); foreach ($a_list_contact as $data) { $group->getFromDB($data['groups_id']); if ($group->fields['is_recursive'] == 1) { $contactentities = getSonsOf('glpi_entities', $group->fields['entities_id']); } else { $contactentities = array($group->fields['entities_id'] => $group->fields['entities_id']); } $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if (isset($a_contacts_entities[$data['items_id']][$datag['users_id']])) { $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$datag['users_id']]); } $a_contacts_entities[$data['items_id']][$datag['users_id']] = $contactentities; } } $a_entities_allowed = $pmEntity->getEntitiesByTag($tag); // Toolbox::logInFile("pm-shinken", " Allowed entities:\n"); $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_plugin_monitoring_services", '', $a_entities_list); } // -------------------------------------------------- // "Normal" services .... $query = "SELECT * FROM `glpi_plugin_monitoring_services` $where"; PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Services: $query\n" ); $result = $DB->query($query); while ($data=$DB->fetch_array($result)) { // Toolbox::logInFile("pm-shinken", " - fetch service ".$data['id']."\n"); // if (isset($a_entities_allowed['-1']) // OR isset($a_entities_allowed[$item->fields['entities_id']])) { $notadd = 0; $notadddescription = ''; $a_component = current($pmComponent->find("`id`='".$data['plugin_monitoring_components_id']."'", "", 1)); if (empty($a_component)) { continue; } $a_hostname = array(); $a_hostname_type = array(); $a_hostname_id = array(); $queryh = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts` WHERE `id` = '".$data['plugin_monitoring_componentscatalogs_hosts_id']."' LIMIT 1"; $resulth = $DB->query($queryh); $hostname = ''; $plugin_monitoring_componentscatalogs_id = 0; while ($datah=$DB->fetch_array($resulth)) { $itemtype = $datah['itemtype']; $item = new $itemtype(); if ($item->getFromDB($datah['items_id'])) { // if (isset($a_entities_allowed['-1']) // OR isset($a_entities_allowed[$item->fields['entities_id']])) { // Fix if hostname is not defined ... if (! empty($item->fields['name'])) { $a_hostname[] = preg_replace("/[^A-Za-z0-9\-_]/","",$item->fields['name']); $a_hostname_type[] = $datah['itemtype']; $a_hostname_id[] = $datah['items_id']; $hostname = $item->fields['name']; $plugin_monitoring_componentscatalogs_id = $datah['plugin_monitoring_componentscalalog_id']; } // } } } if (count($a_hostname) > 0) { if (isset($_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']])) { $a_services[$i]['use'] = $_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']]; } $a_services[$i]['host_name'] = implode(",", array_unique($a_hostname)); $a_services[$i]['_HOSTITEMSID'] = implode(",", array_unique($a_hostname_id)); $a_services[$i]['_HOSTITEMTYPE'] = implode(",", array_unique($a_hostname_type)); // Define display_name / service_description $a_services[$i]['service_description'] = (! empty($a_component['description'])) ? $a_component['description'] : preg_replace("/[^A-Za-z0-9\-_]/","",$a_component['name']); // In case have multiple networkt port, may have description different, else be dropped by shinken if ($data['networkports_id'] > 0) { $networkPort->getFromDB($data['networkports_id']); $a_services[$i]['service_description'] .= '-'.preg_replace("/[^A-Za-z0-9\-_]/", "", $networkPort->fields['name']); } $a_services[$i]['display_name'] = $a_component['name']; // $a_services[$i]['_ENTITIESID'] = $item->fields['entities_id']; // $a_services[$i]['_ITEMSID'] = $data['id']; // $a_services[$i]['_ITEMTYPE'] = 'Service'; PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - add service ".$a_services[$i]['service_description']." on ".$a_services[$i]['host_name']."\n" ); if (isset(self::$shinkenParameters['glpi']['entityId'])) { $a_services[$i][self::$shinkenParameters['glpi']['entityId']] = $item->fields['entities_id']; } if (isset(self::$shinkenParameters['glpi']['itemType'])) { $a_services[$i][self::$shinkenParameters['glpi']['itemType']] = 'Service'; } if (isset(self::$shinkenParameters['glpi']['itemId'])) { $a_services[$i][self::$shinkenParameters['glpi']['itemId']] = $data['id']; } // Manage freshness if ($a_component['freshness_count'] == 0) { $a_services[$i]['check_freshness'] = '0'; $a_services[$i]['freshness_threshold'] = '3600'; } else { $multiple = 1; if ($a_component['freshness_type'] == 'seconds') { $multiple = 1; } else if ($a_component['freshness_type'] == 'minutes') { $multiple = 60; } else if ($a_component['freshness_type'] == 'hours') { $multiple = 3600; } else if ($a_component['freshness_type'] == 'days') { $multiple = 86400; } $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = (string)($a_component['freshness_count'] * $multiple); } $pMonitoringCommand->getFromDB($a_component['plugin_monitoring_commands_id']); // Manage arguments $array = array(); preg_match_all("/\\$(ARG\d+)\\$/", $pMonitoringCommand->fields['command_line'], $array); sort($array[0]); $a_arguments = importArrayFromDB($a_component['arguments']); $a_argumentscustom = importArrayFromDB($data['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 ($a_services[$i]['_HOSTITEMTYPE'] == 'Computer') { // Get networkportname of networkcard defined $pmHostaddress = new PluginMonitoringHostaddress(); $a_hostaddresses = $pmHostaddress->find("`itemtype`='Computer'" . " AND `items_id`='".$a_services[$i]['_HOSTITEMSID']."'", '', 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]." do not have value"; } $args .= '!'.$a_arguments[$arg]; if ($a_arguments[$arg] == '' AND $a_component['alias_command'] != '') { $args .= $a_component['alias_command']; } } } } // End manage arguments if ($a_component['remotesystem'] == 'nrpe') { if ($a_component['alias_command'] != '') { $alias_command = $a_component['alias_command']; if (strstr($alias_command, '[[IP]]')) { $split = explode('-', current($a_hostname)); $ip = PluginMonitoringHostaddress::getIp($split[1], $split[0], ''); $alias_command = str_replace("[[IP]]", $ip, $alias_command); } $a_services[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . "check_nrpe!".$alias_command; } else { $a_services[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . "check_nrpe!".$pMonitoringCommand->fields['command_name']; } } else { $a_services[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . $pMonitoringCommand->fields['command_name'].$args; } // * Manage event handler if ($a_component['plugin_monitoring_eventhandlers_id'] > 0) { if ($pmEventhandler->getFromDB($a_component['plugin_monitoring_eventhandlers_id'])) { $a_services[$i]['event_handler'] = $pmEventhandler->fields['command_name']; } } if (! empty(self::$shinkenParameters['shinken']['services']['process_perf_data'])) $a_services[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['services']['process_perf_data']; if (! empty(self::$shinkenParameters['shinken']['services']['notes'])) $a_services[$i]['notes'] = self::$shinkenParameters['shinken']['services']['notes']; if (! empty(self::$shinkenParameters['shinken']['services']['notes_url'])) $a_services[$i]['notes_url'] = self::$shinkenParameters['shinken']['services']['notes_url']; if (! empty(self::$shinkenParameters['shinken']['services']['action_url'])) $a_services[$i]['action_url'] = self::$shinkenParameters['shinken']['services']['action_url']; if (! empty(self::$shinkenParameters['shinken']['services']['icon_image'])) $a_services[$i]['icon_image'] = self::$shinkenParameters['shinken']['services']['icon_image']; if (! empty(self::$shinkenParameters['shinken']['services']['icon_image_alt'])) $a_services[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['services']['icon_image_alt']; // * Contacts $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog' AND `items_id`='".$plugin_monitoring_componentscatalogs_id."'"); foreach ($a_list_contact as $data_contact) { if ($data_contact['users_id'] > 0) { if (isset($a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$data_contact['users_id']])) { if (in_array($data['entities_id'], $a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } else if ($data_contact['groups_id'] > 0) { $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data_contact['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if (in_array($data['entities_id'], $a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$datag['users_id']])) { $user->getFromDB($datag['users_id']); $a_contacts[] = $user->fields['name']; } } } } $a_contacts_unique = array_unique($a_contacts); $a_services[$i]['contacts'] = implode(',', $a_contacts_unique); // ** If shinken not use templates or template not defined : if (!isset($_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']])) { $pMonitoringCheck->getFromDB($a_component['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; if ($calendar->getFromDB($a_component['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } $a_services[$i]['notification_interval'] = '30'; $a_services[$i]['notification_period'] = "24x7"; $a_services[$i]['notification_options'] = 'w,u,c,r,f,s'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '3600'; $a_services[$i]['notifications_enabled'] = '1'; if (isset($a_services[$i]['event_handler'])) { $a_services[$i]['event_handler_enabled'] = '1'; } else { $a_services[$i]['event_handler_enabled'] = '0'; // $a_services[$i]['event_handler_enabled'] = ''; } $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; // $a_services[$i]['_httpstink'] = 'NO'; } else { // Notification options $a_services[$i]['notification_interval'] = '30'; $pmComponentscatalog->getFromDB($plugin_monitoring_componentscatalogs_id); if ($pmComponentscatalog->fields['notification_interval'] != '30') { $a_services[$i]['notification_interval'] = $pmComponentscatalog->fields['notification_interval']; } $a_services[$i]['notification_period'] = '24x7'; $a_services[$i]['check_period'] = '24x7'; if ($calendar->getFromDB($a_component['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } } // WebUI user interface ... if (isset(self::$shinkenParameters['webui']['serviceIcons']['name'])) { $a_services[$i][self::$shinkenParameters['webui']['serviceIcons']['name']] = self::$shinkenParameters['webui']['serviceIcons']['value']; } if ($notadd == '1') { unset($a_services[$i]); $input = array(); $input['id'] = $data['id']; $input['event'] = $notadddescription; $input['state'] = "CRITICAL"; $input['state_type'] = "HARD"; $pmService->update($input); } else { $i++; } } // } } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateServicesCfg services\n" ); PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Starting generateServicesCfg business rules ...\n" ); // -------------------------------------------------- // Business rules services ... $pmService = new PluginMonitoringService(); $pmServicescatalog = new PluginMonitoringServicescatalog(); $pmBusinessrulegroup = new PluginMonitoringBusinessrulegroup(); $pmBusinessrule = new PluginMonitoringBusinessrule(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmBusinessrule_component = new PluginMonitoringBusinessrule_component(); // Prepare individual contacts $a_contacts_entities = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog' 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; } // Prepare groups contacts $group = new Group(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog' AND `groups_id`>0"); foreach ($a_list_contact as $data) { $group->getFromDB($data['groups_id']); if ($group->fields['is_recursive'] == 1) { $contactentities = getSonsOf('glpi_entities', $group->fields['entities_id']); } else { $contactentities = array($group->fields['entities_id'] => $group->fields['entities_id']); } $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if (isset($a_contacts_entities[$data['items_id']][$datag['users_id']])) { $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$datag['users_id']]); } $a_contacts_entities[$data['items_id']][$datag['users_id']] = $contactentities; } } // Services catalogs $a_listBA = $pmServicescatalog->find("`is_generic`='0'"); foreach ($a_listBA as $dataBA) { if (isset($a_entities_allowed['-1']) OR isset($a_entities_allowed[$dataBA['entities_id']])) { $a_grouplist = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='".$dataBA['id']."'"); $a_group = array(); foreach ($a_grouplist as $gdata) { $pmBusinessrule_component->replayDynamicServices($gdata['id']); $a_listBR = $pmBusinessrule->find( "`plugin_monitoring_businessrulegroups_id`='".$gdata['id']."'"); foreach ($a_listBR as $dataBR) { if ($pmService->getFromDB($dataBR['plugin_monitoring_services_id'])) { if ($pmService->getHostName() != '') { $hostname = preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getHostName()); if ($gdata['operator'] == 'and' OR $gdata['operator'] == 'or' OR strstr($gdata['operator'], ' of:')) { $operator = '|'; if ($gdata['operator'] == 'and') { $operator = '&'; } if (!isset($a_group[$gdata['id']])) { $a_group[$gdata['id']] = ''; if (strstr($gdata['operator'], ' of:')) { $a_group[$gdata['id']] = $gdata['operator']; } $a_group[$gdata['id']] .= $hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getName(array('shinken'=>true))); } else { $a_group[$gdata['id']] .= $operator.$hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getName(array('shinken'=>true))); } } else { $a_group[$gdata['id']] = $gdata['operator']." ".$hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$item->getName()); } } } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - SC group : ".$a_group[$gdata['id']]."\n" ); } } if (count($a_group) > 0) { $pMonitoringCheck->getFromDB($dataBA['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; if ($calendar->getFromDB($dataBA['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } $a_services[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['bp_host']; $a_services[$i]['business_impact'] = $dataBA['business_priority']; $a_services[$i]['service_description'] = preg_replace("/[^A-Za-z0-9\-_]/","",$dataBA['name']); $a_services[$i]['_ENTITIESID'] = $dataBA['id']; $a_services[$i]['_ITEMSID'] = $dataBA['id']; $a_services[$i]['_ITEMTYPE'] = 'ServiceCatalog'; $command = "bp_rule!"; foreach ($a_group as $key=>$value) { if (!strstr($value, "&") AND !strstr($value, "|")) { $a_group[$key] = trim($value); } else { $a_group[$key] = "(".trim($value).")"; } } $a_services[$i]['check_command'] = $command.implode("&", $a_group); if ($dataBA['notification_interval'] != '30') { $a_services[$i]['notification_interval'] = $dataBA['notification_interval']; } else { $a_services[$i]['notification_interval'] = '30'; } $a_services[$i]['notification_period'] = "24x7"; $a_services[$i]['notification_options'] = 'w,u,c,r,f,s'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '3600'; $a_services[$i]['notifications_enabled'] = '1'; $a_services[$i]['event_handler_enabled'] = '0'; //$a_services[$i]['event_handler'] = 'super_event_kill_everyone!DIE'; $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; // $a_services[$i]['_httpstink'] = 'NO'; // * Contacts $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog' AND `items_id`='".$dataBA['id']."'"); foreach ($a_list_contact as $data_contact) { if ($data_contact['users_id'] > 0) { if (isset($a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } else if ($data_contact['groups_id'] > 0) { $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data_contact['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$datag['users_id']])) { $user->getFromDB($datag['users_id']); $a_contacts[] = $user->fields['name']; } } } } $a_contacts_unique = array_unique($a_contacts); $a_services[$i]['contacts'] = implode(',', $a_contacts_unique); $i++; } } } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateServicesCfg business rules\n" ); PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "Starting generateServicesCfg business rules templates ...\n" ); // Services catalogs templates // TODO : correctly test and improve it ! $a_listBA = $pmServicescatalog->find("`is_generic`='1'"); foreach ($a_listBA as $dataBA) { PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - SC : ".$dataBA['id']."\n" ); if (isset($a_entities_allowed['-1']) OR isset($a_entities_allowed[$dataBA['entities_id']])) { $pmServicescatalog->getFromDB($dataBA['id']); $a_entitiesServices = $pmServicescatalog->getGenericServicesEntities(); foreach ($a_entitiesServices as $idEntity=>$a_entityServices) { // New entity ... so new business rule ! PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - SC templated services for an entity : ".$idEntity."\n" ); $pmDerivatedSC = new PluginMonitoringServicescatalog(); $a_derivatedSC = $pmDerivatedSC->find("`entities_id`='$idEntity' AND `name` LIKE '".$dataBA['name']."%'"); foreach ($a_derivatedSC as $a_derivated) { PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', " - a_derivated : ".$a_derivated['name']."\n" ); $a_derivatedSC = $a_derivated; } $a_group = array(); foreach ($a_entityServices as $services) { if ($pmService->getFromDB($services['serviceId'])) { // Toolbox::logInFile("pm-shinken", " - SC templated service entity : ".$services['entityId'].", service : ".$pmService->getName(true)." on ".$pmService->getHostName()."\n"); if ($pmService->getHostName() != '') { $hostname = preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getHostName()); $serviceFakeId = $services['entityId']; $pmBusinessrulegroup->getFromDB($services['BRgroupId']); $BRoperator = $pmBusinessrulegroup->getField('operator'); if ($BRoperator == 'and' OR $BRoperator == 'or' OR strstr($BRoperator, ' of:')) { $operator = '|'; if ($BRoperator == 'and') { $operator = '&'; } if (!isset($a_group[$serviceFakeId])) { $a_group[$serviceFakeId] = ''; if (strstr($BRoperator, ' of:')) { $a_group[$serviceFakeId] = $BRoperator; } $a_group[$serviceFakeId] .= $hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getName(array('shinken'=>true))); } else { $a_group[$serviceFakeId] .= $operator.$hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getName(array('shinken'=>true))); } } else { $a_group[$serviceFakeId] = $BRoperator." ".$hostname.",".preg_replace("/[^A-Za-z0-9\-_]/","",$pmService->getHostName()); } // Toolbox::logInFile("pm-shinken", " - SCT group : ".$a_group[$serviceFakeId]."\n"); } } } if (count($a_group) > 0) { $pMonitoringCheck->getFromDB($a_derivatedSC['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; if ($calendar->getFromDB($a_derivatedSC['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } $a_services[$i]['host_name'] = preg_replace("/[^A-Za-z0-9\-_]/","",$a_derivatedSC['name']); $a_services[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['bp_host']; $a_services[$i]['business_impact'] = $a_derivatedSC['business_priority']; $a_services[$i]['service_description'] = preg_replace("/[^A-Za-z0-9\-_]/","",$a_derivatedSC['name']); $a_services[$i]['_ENTITIESID'] = $a_derivatedSC['entities_id']; $a_services[$i]['_ITEMSID'] = $a_derivatedSC['id']; $a_services[$i]['_ITEMTYPE'] = 'ServiceCatalog'; $command = "bp_rule!"; foreach ($a_group as $key=>$value) { if (!strstr($value, "&") AND !strstr($value, "|")) { $a_group[$key] = trim($value); } else { $a_group[$key] = "(".trim($value).")"; } } $a_services[$i]['check_command'] = $command.implode("&", $a_group); if ($a_derivatedSC['notification_interval'] != '30') { $a_services[$i]['notification_interval'] = $a_derivatedSC['notification_interval']; } else { $a_services[$i]['notification_interval'] = '30'; } $a_services[$i]['notification_period'] = "24x7"; $a_services[$i]['notification_options'] = 'w,u,c,r,f,s'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '3600'; $a_services[$i]['notifications_enabled'] = '1'; $a_services[$i]['event_handler_enabled'] = '0'; //$a_services[$i]['event_handler'] = 'super_event_kill_everyone!DIE'; $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; // $a_services[$i]['_httpstink'] = 'NO'; // * Contacts $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog' AND `items_id`='".$dataBA['id']."'"); foreach ($a_list_contact as $data_contact) { if ($data_contact['users_id'] > 0) { if (isset($a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } else if ($data_contact['groups_id'] > 0) { $queryg = "SELECT * FROM `glpi_groups_users` WHERE `groups_id`='".$data_contact['groups_id']."'"; $resultg = $DB->query($queryg); while ($datag=$DB->fetch_array($resultg)) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$datag['users_id']])) { $user->getFromDB($datag['users_id']); $a_contacts[] = $user->fields['name']; } } } } $a_contacts_unique = array_unique($a_contacts); $a_services[$i]['contacts'] = implode(',', $a_contacts_unique); $i++; } } } } PluginMonitoringToolbox::logIfExtradebug( 'pm-shinken', "End generateServicesCfg business rules templates\n" ); if ($file == "1") { $config = "# Generated by plugin monitoring for GLPI\n# on ".date("Y-m-d H:i:s")."\n\n"; foreach ($a_services as $data) { $config .= $this->writeFile("service", $data); } return array('services.cfg', $config); } else { return $a_services; } }
static function isThisItemCheckRule($parm) { global $DB; $itemtype = get_class($parm); $items_id = $parm->fields['id']; $session_glpisearch = array(); if (isset($_SESSION['glpisearch'])) { $session_glpisearch = $_SESSION['glpisearch']; } $session_glpisearchcount = array(); if (isset($_SESSION['glpisearchcount'])) { $session_glpisearchcount = $_SESSION['glpisearchcount']; } $session_glpisearchcount2 = array(); if (isset($_SESSION['glpisearchcount2'])) { $session_glpisearchcount2 = $_SESSION['glpisearchcount2']; } $a_find = array(); $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $query = "SELECT * FROM `" . $pmComponentscatalog_rule->getTable() . "`\n WHERE `itemtype`='" . $itemtype . "'"; $result = $DB->query($query); $get_tmp = array(); if (isset($_GET)) { $get_tmp = $_GET; } while ($data = $DB->fetch_array($result)) { if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = $parm->fields['entities_id']; } // Load right entity $pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']); $default_entity = 0; if (isset($_SESSION['glpiactive_entity'])) { $default_entity = $_SESSION['glpiactive_entity']; } $entities_isrecursive = 0; if (isset($_SESSION['glpiactiveentities']) and count($_SESSION['glpiactiveentities']) > 1) { $entities_isrecursive = 1; } if (!isset($_SESSION['glpiactiveprofile']['entities'])) { $_SESSION['glpiactiveprofile']['entities'] = array($pmComponentscatalog->fields['entities_id'] => array('id' => $pmComponentscatalog->fields['entities_id'], 'name' => '', 'is_recursive' => $pmComponentscatalog->fields['is_recursive'])); } Session::changeActiveEntities($pmComponentscatalog->fields['entities_id'], $pmComponentscatalog->fields['is_recursive']); $itemtype = $data['itemtype']; $condition = importArrayFromDB($data['condition']); $params = Search::manageParams($itemtype, $condition, FALSE); $datar = Search::prepareDatasForSearch($itemtype, $params); Search::constructSQL($datar); $DBread = DBConnection::getReadConnection(); $DBread->query("SET SESSION group_concat_max_len = 16384;"); $resultr = $DBread->query($datar['sql']['search']); /// Check group concat limit : if warning : increase limit if ($result2 = $DBread->query('SHOW WARNINGS')) { if ($DBread->numrows($result2) > 0) { $res = $DBread->fetch_assoc($result2); if ($res['Code'] == 1260) { $DBread->query("SET SESSION group_concat_max_len = 4194304;"); $resultr = $DBread->query($datar['sql']['search']); } } } $find = 0; while ($datar = $DB->fetch_array($resultr)) { if ($datar['id'] == $items_id) { $find = 1; break; } } if ($find == 1) { $a_find[$data['plugin_monitoring_componentscalalog_id']] = 1; } else { if (!isset($a_find[$data['plugin_monitoring_componentscalalog_id']])) { $a_find[$data['plugin_monitoring_componentscalalog_id']] = 0; } } // Reload current entity Session::changeActiveEntities($default_entity, $entities_isrecursive); } if (count($get_tmp) > 0) { $_GET = $get_tmp; } $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); foreach ($a_find as $componentscalalog_id => $is_present) { if ($is_present == '0') { // * Remove from dynamic if present $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscalalog_id . "'\n AND `itemtype`='" . $itemtype . "'\n AND `items_id`='" . $items_id . "'\n AND`is_static`='0'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $pmComponentscatalog_Host->delete(array('id' => $data['id'])); } } else { // add if not present $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscalalog_id . "'\n AND `itemtype`='" . $itemtype . "'\n AND `items_id`='" . $items_id . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $input = array(); $input['plugin_monitoring_componentscalalog_id'] = $componentscalalog_id; $input['is_static'] = '0'; $input['items_id'] = $items_id; $input['itemtype'] = $itemtype; $pmComponentscatalog_Host->add($input); } else { $data2 = $DB->fetch_assoc($result); // modify entity of services (if entity of device is changed) $item = new $itemtype(); $item->getFromDB($items_id); $queryu = "UPDATE `glpi_plugin_monitoring_services`\n SET `entities_id`='" . $item->fields['entities_id'] . "'\n WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $data2['id'] . "'"; $DB->query($queryu); } } } if ($itemtype == 'NetworkEquipment') { //Get networkports $pmComponentscatalog_rule->isThisItemCheckRuleNetworkport($parm); } $_SESSION['glpisearch'] = $session_glpisearch; $_SESSION['glpisearchcount'] = $session_glpisearchcount; $_SESSION['glpisearchcount2'] = $session_glpisearchcount2; }
------------------------------------------------------------------------ */ include ("../../../inc/includes.php"); Session::checkRight("plugin_monitoring_componentscatalog", READ); Html::header(__('Monitoring', 'monitoring'),$_SERVER["PHP_SELF"], "plugins", "monitoring", "checks"); if (isset($_POST['itemtypen'])) { $_POST['itemtype'] = $_POST['itemtypen']; } $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); if (isset($_GET['addrule'])) { if (!isset($_GET['criteria'])) { // $_SESSION['plugin_monitoring_rules'] = $_POST; } else { $_POST = $_GET; $input = array(); $pmComponentscatalog->getFromDB($_POST['plugin_monitoring_componentscalalog_id']); $input['entities_id'] = $pmComponentscatalog->fields['entities_id']; $input['is_recursive'] = $pmComponentscatalog->fields['is_recursive']; $input['name'] = $_POST['name']; $input['itemtype'] = $_POST['itemtype']; $input['plugin_monitoring_componentscalalog_id'] = $_POST['plugin_monitoring_componentscalalog_id']; unset($_POST['entities_id']);
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>"; }
exit; } $pmDisplay = new PluginMonitoringDisplay(); $pmBusinessrule = new PluginMonitoringBusinessrule(); $pmDisplayview = new PluginMonitoringDisplayview(); $a_views = $pmDisplayview->getViews(); switch ($_REQUEST['glpi_tab']) { case -1: break; case 1: $pmServicescatalog = new PluginMonitoringServicescatalog(); $pmDisplay->displayCounters("Businessrules"); $pmServicescatalog->showBAChecks(); break; case 2: $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmDisplay->displayCounters("Componentscatalog"); $pmComponentscatalog->showChecks(); break; case 3: $pmDisplay->displayCounters("Ressources"); // Manage search $_GET = $_SESSION['plugin_monitoring']['service']; if (isset($_GET['reset'])) { unset($_SESSION['glpisearch']['PluginMonitoringService']); } if (isset($_GET['glpi_tab'])) { unset($_GET['glpi_tab']); } Search::manageGetValues("PluginMonitoringService"); Search::showGenericSearch("PluginMonitoringService", $_GET);
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; }
Plugin Monitoring for 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Monitoring. If not, see <http://www.gnu.org/licenses/>. ------------------------------------------------------------------------ @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_componentscatalog", READ); $_SESSION['glpi_plugin_monitoring'][$_POST['reporttype']][$_POST['componentscatalogs_id']] = $_POST; if (isset($_POST['generatepdf'])) { $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponentscatalog->generateSyntheseReport($_SESSION['glpi_plugin_monitoring'][$_POST['reporttype']][$_POST['componentscatalogs_id']]); } else { Html::back(); }
GLPI is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by 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'], "updateWidgetComponentscatalog.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"); } Session::checkLoginUser(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponentscatalog->showWidgetFrame($_POST['id']);
function generateServicesCfg($file = 0, $tag = '') { global $DB; $pMonitoringCommand = new PluginMonitoringCommand(); $pMonitoringCheck = new PluginMonitoringCheck(); $pmComponent = new PluginMonitoringComponent(); $pmEntity = new PluginMonitoringEntity(); $pmContact_Item = new PluginMonitoringContact_Item(); $pmService = new PluginMonitoringService(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $calendar = new Calendar(); $user = new User(); $pmLog = new PluginMonitoringLog(); $profile_User = new Profile_User(); 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"); $pmLog->add($input); } $hostnamebp = ''; $a_services = array(); $i = 0; // * Prepare contacts $a_contacts_entities = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog'\n 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; } $a_entities_allowed = $pmEntity->getEntitiesByTag($tag); $query = "SELECT * FROM `glpi_plugin_monitoring_services`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $notadd = 0; $notadddescription = ''; $a_component = current($pmComponent->find("`id`='" . $data['plugin_monitoring_components_id'] . "'", "", 1)); $a_hostname = array(); $queryh = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts` \n WHERE `id` = '" . $data['plugin_monitoring_componentscatalogs_hosts_id'] . "'\n LIMIT 1"; $resulth = $DB->query($queryh); $hostname = ''; $plugin_monitoring_componentscatalogs_id = 0; while ($datah = $DB->fetch_array($resulth)) { $itemtype = $datah['itemtype']; $item = new $itemtype(); if ($item->getFromDB($datah['items_id'])) { if (isset($a_entities_allowed['-1']) or isset($a_entities_allowed[$item->fields['entities_id']])) { $a_hostname[] = $itemtype . "-" . $datah['items_id'] . "-" . preg_replace("/[^A-Za-z0-9]/", "", $item->fields['name']); $hostname = $item->fields['name']; $plugin_monitoring_componentscatalogs_id = $datah['plugin_monitoring_componentscalalog_id']; } } } if (count($a_hostname) > 0) { if (isset($_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']])) { $a_services[$i]['use'] = $_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']]; } $a_services[$i]['host_name'] = implode(",", array_unique($a_hostname)); $hostnamebp = $a_services[$i]['host_name']; // For business rules $a_services[$i]['service_description'] = preg_replace("/[^A-Za-z0-9]/", "", $a_component['name']) . "-" . $data['id']; $pMonitoringCommand->getFromDB($a_component['plugin_monitoring_commands_id']); // Manage arguments $array = array(); preg_match_all("/\\\$(ARG\\d+)\\\$/", $pMonitoringCommand->fields['command_line'], $array); sort($array[0]); $a_arguments = importArrayFromDB($a_component['arguments']); $a_argumentscustom = importArrayFromDB($data['arguments']); foreach ($a_argumentscustom as $key => $value) { $a_arguments[$key] = $value; } $args = ''; foreach ($array[0] as $arg) { if ($arg != '$PLUGINSDIR$' 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("PluginFusinvsnmpNetworkPort")) { $pfNetworkPort = new PluginFusinvsnmpNetworkPort(); $pfNetworkPort->loadNetworkport($data['networkports_id']); $descr = ''; $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]]")) { $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $portname = $pfNetworkPort->fields['name']; $a_arguments[$arg] = str_replace("[[NETWORKPORTNAME]]", $portname, $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']; } } } } // End manage arguments if ($a_component['remotesystem'] == 'nrpe') { if ($a_component['alias_command'] != '') { $a_services[$i]['check_command'] = "check_nrpe!" . $a_component['alias_command']; } else { $a_services[$i]['check_command'] = "check_nrpe!" . $pMonitoringCommand->fields['command_name']; } } else { $a_services[$i]['check_command'] = $pMonitoringCommand->fields['command_name'] . $args; } // * Contacts $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog'\n AND `items_id`='" . $plugin_monitoring_componentscatalogs_id . "'"); foreach ($a_list_contact as $data_contact) { if (isset($a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$data_contact['users_id']])) { if (in_array($data['entities_id'], $a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$data_contact['users_id']])) { // $pmContact->getFromDB($data_contact['plugin_monitoring_contacts_id']); $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } $a_contacts_unique = array_unique($a_contacts); $a_services[$i]['contacts'] = implode(',', $a_contacts_unique); // ** If shinken not use templates or template not defined : if (!isset($_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']])) { $pMonitoringCheck->getFromDB($a_component['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; if ($calendar->getFromDB($a_component['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } $a_services[$i]['notification_interval'] = '30'; if ($calendar->getFromDB($a_component['calendars_id'])) { $a_services[$i]['notification_period'] = $calendar->fields['name']; } else { $a_services[$i]['notification_period'] = "24x7"; } $a_services[$i]['notification_options'] = 'w,c,r'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '1'; $a_services[$i]['notifications_enabled'] = '1'; $a_services[$i]['event_handler_enabled'] = '0'; //$a_services[$i]['event_handler'] = 'super_event_kill_everyone!DIE'; $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; $a_services[$i]['_httpstink'] = 'NO'; } $pmComponentscatalog->getFromDB($plugin_monitoring_componentscatalogs_id); if ($pmComponentscatalog->fields['notification_interval'] != '30') { $a_services[$i]['notification_interval'] = $pmComponentscatalog->fields['notification_interval']; } if ($notadd == '1') { unset($a_services[$i]); $input = array(); $input['id'] = $data['id']; $input['event'] = $notadddescription; $input['state'] = "CRITICAL"; $input['state_type'] = "HARD"; $pmService->update($input); } else { $i++; } } } // // Business rules.... $pmService = new PluginMonitoringService(); $pmServicescatalog = new PluginMonitoringServicescatalog(); $pMonitoringBusinessrulegroup = new PluginMonitoringBusinessrulegroup(); $pmBusinessrule = new PluginMonitoringBusinessrule(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $a_listBA = $pmServicescatalog->find(); foreach ($a_listBA as $dataBA) { if (isset($a_entities_allowed['-1']) or isset($a_entities_allowed[$dataBA['entities_id']])) { $a_grouplist = $pMonitoringBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $dataBA['id'] . "'"); $a_group = array(); foreach ($a_grouplist as $gdata) { $a_listBR = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $gdata['id'] . "'"); foreach ($a_listBR as $dataBR) { if ($pmService->getFromDB($dataBR['plugin_monitoring_services_id'])) { $pmComponentscatalog_Host->getFromDB($pmService->fields['plugin_monitoring_componentscatalogs_hosts_id']); $itemtype = $pmComponentscatalog_Host->fields['itemtype']; $item = new $itemtype(); if ($item->getFromDB($pmComponentscatalog_Host->fields['items_id'])) { $hostname = $itemtype . "-" . $pmComponentscatalog_Host->fields['items_id'] . "-" . preg_replace("/[^A-Za-z0-9]/", "", $item->fields['name']); if ($gdata['operator'] == 'and' or $gdata['operator'] == 'or' or strstr($gdata['operator'], ' of:')) { $operator = '|'; if ($gdata['operator'] == 'and') { $operator = '&'; } if (!isset($a_group[$gdata['id']])) { $a_group[$gdata['id']] = ''; if (strstr($gdata['operator'], ' of:')) { $a_group[$gdata['id']] = $gdata['operator']; } $a_group[$gdata['id']] .= $hostname . "," . preg_replace("/[^A-Za-z0-9]/", "", $pmService->fields['name']) . "-" . $pmService->fields['id']; } else { $a_group[$gdata['id']] .= $operator . $hostname . "," . preg_replace("/[^A-Za-z0-9]/", "", $pmService->fields['name']) . "-" . $pmService->fields['id']; } } else { $a_group[$gdata['id']] = $gdata['operator'] . " " . $hostname . "," . preg_replace("/[^A-Za-z0-9]/", "", $item->getName()) . "-" . $item->fields['id']; } } } } } if (count($a_group) > 0) { $pMonitoringCheck->getFromDB($dataBA['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; if ($calendar->getFromDB($dataBA['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } $a_services[$i]['host_name'] = $hostnamebp; $a_services[$i]['service_description'] = preg_replace("/[^A-Za-z0-9]/", "", $dataBA['name']) . "-" . $dataBA['id'] . "-businessrules"; $command = "bp_rule!"; foreach ($a_group as $key => $value) { if (!strstr($value, "&") and !strstr($value, "|")) { $a_group[$key] = trim($value); } else { $a_group[$key] = "(" . trim($value) . ")"; } } $a_services[$i]['check_command'] = $command . implode("&", $a_group); $a_services[$i]['notification_interval'] = '30'; if ($calendar->getFromDB($dataBA['calendars_id'])) { $a_services[$i]['notification_period'] = $calendar->fields['name']; } else { $a_services[$i]['notification_period'] = "24x7"; } $a_services[$i]['notification_options'] = 'w,c,r'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '1'; $a_services[$i]['notifications_enabled'] = '1'; $a_services[$i]['event_handler_enabled'] = '0'; //$a_services[$i]['event_handler'] = 'super_event_kill_everyone!DIE'; $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; $a_services[$i]['_httpstink'] = 'NO'; $a_services[$i]['contacts'] = ''; $i++; } } } if ($file == "1") { $config = "# Generated by plugin monitoring for GLPI\n# on " . date("Y-m-d H:i:s") . "\n\n"; foreach ($a_services as $data) { $config .= $this->constructFile("service", $data); } return array('services.cfg', $config); } else { return $a_services; } }
static function getItemsDynamicly($parm) { global $DB; $pmCc_Rule = new PluginMonitoringComponentscatalog_rule(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $devices_present = array(); if ($pmCc_Rule->getFromDB($parm->fields['id'])) { // Load right entity $pmComponentscatalog->getFromDB($pmCc_Rule->fields['plugin_monitoring_componentscalalog_id']); $default_entity = 0; if (isset($_SESSION['glpiactive_entity'])) { $default_entity = $_SESSION['glpiactive_entity']; } $entities_isrecursive = 0; if (isset($_SESSION['glpiactiveentities']) and count($_SESSION['glpiactiveentities']) > 1) { $entities_isrecursive = 1; } changeActiveEntities($pmComponentscatalog->fields['entities_id'], $pmComponentscatalog->fields['is_recursive']); $get_tmp = ''; $itemtype = $pmCc_Rule->fields['itemtype']; if (isset($_GET)) { $get_tmp = $_GET; } if (isset($_SESSION["glpisearchcount"][$pmCc_Rule->fields['itemtype']])) { unset($_SESSION["glpisearchcount"][$pmCc_Rule->fields['itemtype']]); } if (isset($_SESSION["glpisearchcount2"][$pmCc_Rule->fields['itemtype']])) { unset($_SESSION["glpisearchcount2"][$pmCc_Rule->fields['itemtype']]); } $_GET = importArrayFromDB($pmCc_Rule->fields['condition']); $_GET["glpisearchcount"] = count($_GET['field']); if (isset($_GET['field2'])) { $_GET["glpisearchcount2"] = count($_GET['field2']); } Search::manageGetValues($pmCc_Rule->fields['itemtype']); $queryd = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"] . "'\n AND `itemtype`='" . $pmCc_Rule->fields['itemtype'] . "'\n AND `is_static`='0'"; $result = $DB->query($queryd); while ($data = $DB->fetch_array($result)) { $devices_present[$data['id']] = 1; } $glpilist_limit = $_SESSION['glpilist_limit']; $_SESSION['glpilist_limit'] = 500000; $result = $pmCc_Rule->constructSQL($itemtype, $_GET); $_SESSION['glpilist_limit'] = $glpilist_limit; while ($data = $DB->fetch_array($result)) { $networkports_id = 0; $itemtype_device = $pmCc_Rule->fields['itemtype']; $items_id_device = $data['id']; if ($itemtype_device == 'PluginMonitoringNetworkport') { $pmNetworkport = new PluginMonitoringNetworkport(); $pmNetworkport->getFromDB($data['id']); $itemtype_device = $pmNetworkport->fields['itemtype']; $items_id_device = $pmNetworkport->fields['items_id']; $networkports_id = $pmNetworkport->fields['networkports_id']; } $queryh = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"] . "'\n AND `itemtype`='" . $itemtype_device . "'\n AND `items_id`='" . $items_id_device . "'\n LIMIT 1"; $resulth = $DB->query($queryh); if ($DB->numrows($resulth) == '0') { $input = array(); $input['plugin_monitoring_componentscalalog_id'] = $pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"]; $input['is_static'] = '0'; $input['items_id'] = $items_id_device; $input['itemtype'] = $itemtype_device; $componentscatalogs_hosts_id = $pmComponentscatalog_Host->add($input); $pmComponentscatalog_Host->linkComponentsToItem($pmCc_Rule->fields["plugin_monitoring_componentscalalog_id"], $componentscatalogs_hosts_id, $networkports_id); } else { $data2 = $DB->fetch_assoc($resulth); // modify entity of services (if entity of device is changed) $itemtype = $data2['itemtype']; $item = new $itemtype(); $item->getFromDB($data2['items_id']); $queryu = "UPDATE `glpi_plugin_monitoring_services`\n SET `entities_id`='" . $item->fields['entities_id'] . "'\n WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $data2['id'] . "'"; $DB->query($queryu); unset($devices_present[$data2['id']]); } } // Reload current entity changeActiveEntities($default_entity, $entities_isrecursive); } else { // Purge $queryd = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $parm->fields["plugin_monitoring_componentscalalog_id"] . "'\n AND `itemtype`='" . $parm->fields['itemtype'] . "'\n AND `is_static`='0'"; $result = $DB->query($queryd); while ($data = $DB->fetch_array($result)) { $devices_present[$data['id']] = 1; } } foreach ($devices_present as $id => $num) { $pmComponentscatalog_Host->delete(array('id' => $id)); } }
include GLPI_ROOT . "/inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); header_nocache(); if (!isset($_POST["id"])) { exit; } if (!isset($_POST["sort"])) { $_POST["sort"] = ""; } if (!isset($_POST["order"])) { $_POST["order"] = ""; } if (!isset($_POST["withtemplate"])) { $_POST["withtemplate"] = ""; } $pmComponentscatalog = new PluginMonitoringComponentscatalog(); if ($_POST["id"] > 0 && $pmComponentscatalog->can($_POST["id"], 'r')) { switch ($_POST['glpi_tab']) { case -1: break; case 1: $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); $pmComponentscatalog_Component->showComponents($_POST['id']); break; case 2: $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmComponentscatalog_Host->showHosts($_POST['id'], 1); break; case 3: $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule(); $pmComponentscatalog_rule->showRules($_POST['id']);
static function isThisItemCheckRule($parm) { global $DB; $itemtype = get_class($parm); $items_id = $parm->fields['id']; $a_find = array(); $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmSearch = new PluginMonitoringSearch(); $query = "SELECT * FROM `" . $pmComponentscatalog_rule->getTable() . "`\n WHERE `itemtype`='" . $itemtype . "'"; $result = $DB->query($query); $get_tmp = array(); if (isset($_GET)) { $get_tmp = $_GET; } while ($data = $DB->fetch_array($result)) { if (isset($_SESSION["glpisearchcount"][$data['itemtype']])) { unset($_SESSION["glpisearchcount"][$data['itemtype']]); } if (isset($_SESSION["glpisearchcount2"][$data['itemtype']])) { unset($_SESSION["glpisearchcount2"][$data['itemtype']]); } $_GET = importArrayFromDB($data['condition']); $_GET["glpisearchcount"] = count($_GET['field']); if (isset($_GET['field2'])) { $_GET["glpisearchcount2"] = count($_GET['field2']); } if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = $parm->fields['entities_id']; } // Load right entity $pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']); $default_entity = 0; if (isset($_SESSION['glpiactive_entity'])) { $default_entity = $_SESSION['glpiactive_entity']; } $entities_isrecursive = 0; if (isset($_SESSION['glpiactiveentities']) and count($_SESSION['glpiactiveentities']) > 1) { $entities_isrecursive = 1; } if (!isset($_SESSION['glpiactiveprofile']['entities'])) { $_SESSION['glpiactiveprofile']['entities'] = array($pmComponentscatalog->fields['entities_id'] => array('id' => $pmComponentscatalog->fields['entities_id'], 'name' => '', 'is_recursive' => $pmComponentscatalog->fields['is_recursive'])); } Session::changeActiveEntities($pmComponentscatalog->fields['entities_id'], $pmComponentscatalog->fields['is_recursive']); Search::manageGetValues($data['itemtype']); $resultr = $pmSearch->constructSQL($itemtype, $_GET, $items_id); if ($DB->numrows($resultr) > 0) { $a_find[$data['plugin_monitoring_componentscalalog_id']] = 1; } else { if (!isset($a_find[$data['plugin_monitoring_componentscalalog_id']])) { $a_find[$data['plugin_monitoring_componentscalalog_id']] = 0; } } // Reload current entity Session::changeActiveEntities($default_entity, $entities_isrecursive); } if (count($get_tmp) > 0) { $_GET = $get_tmp; } $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); foreach ($a_find as $componentscalalog_id => $is_present) { if ($is_present == '0') { // * Remove from dynamic if present $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscalalog_id . "'\n AND `itemtype`='" . $itemtype . "'\n AND `items_id`='" . $items_id . "'\n AND`is_static`='0'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $pmComponentscatalog_Host->delete(array('id' => $data['id'])); } } else { // add if not present $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscalalog_id . "'\n AND `itemtype`='" . $itemtype . "'\n AND `items_id`='" . $items_id . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == '0') { $input = array(); $input['plugin_monitoring_componentscalalog_id'] = $componentscalalog_id; $input['is_static'] = '0'; $input['items_id'] = $items_id; $input['itemtype'] = $itemtype; $componentscatalogs_hosts_id = $pmComponentscatalog_Host->add($input); $pmComponentscatalog_Host->linkComponentsToItem($componentscalalog_id, $componentscatalogs_hosts_id); } else { $data2 = $DB->fetch_assoc($result); // modify entity of services (if entity of device is changed) $item = new $itemtype(); $item->getFromDB($items_id); $queryu = "UPDATE `glpi_plugin_monitoring_services`\n SET `entities_id`='" . $item->fields['entities_id'] . "'\n WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $data2['id'] . "'"; $DB->query($queryu); } } } if ($itemtype == 'NetworkEquipment') { //Get networkports $pmComponentscatalog_rule->isThisItemCheckRuleNetworkport($parm); } }
$_SESSION['plugin_monitoring_reduced_interface'] = false; } // echo " // <script> // function toggleEntity(idEntity) { // Ext.select('#'+idEntity).each(function(el) { // var displayed = false; // el.select('tr.services').each(function(elTr) { // elTr.setDisplayed(! elTr.isDisplayed()); // displayed = elTr.isDisplayed(); // }); // // if (! displayed) { // // el.select('tr.header').each(function(elTr) { // // elTr.applyStyles({'height':'10px'}); // // elTr.select('th').each(function(elTd) { // // elTd.applyStyles({'height':'10px'}); // // }); // // }); // // } // el.select('tr.header').each(function(elTr) { // elTr.applyStyles(displayed ? {'height':'50px'} : {'height':'10px'}); // elTr.select('th').each(function(elTd) { // elTd.applyStyles(displayed ? {'height':'50px'} : {'height':'10px'}); // }); // }); // }); // }; // </script> // "; $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponentscatalog->showWidgetFrame($_GET['id'], $_SESSION['plugin_monitoring_reduced_interface'], $_GET['is_minemap']);
function type_other($type = 'average') { global $DB; $pmService = new PluginMonitoringService(); $pmServiceevent = new PluginMonitoringServiceevent(); $pmComponent = new PluginMonitoringComponent(); $pmPerfdataDetail = new PluginMonitoringPerfdataDetail(); $a_date = PluginMonitoringCustomitem_Common::getTimeRange($this->fields); $val = 0; $a_val = array(); $nb_val = 0; $a_tocheck = array('warn' => 0, 'crit' => 0, 'limit' => 0); $a_types = array('warn', 'crit', 'limit'); for ($i = 0; $i < count($a_types); $i++) { if (is_numeric($this->fields['aggregate_' . $a_types[$i]])) { $a_ret[$a_types[$i]] = $this->fields['aggregate_' . $a_types[$i]]; } else { $a_ret[$a_types[$i]] = 0; $a_tocheck[$a_types[$i]] = 1; } } $items = importArrayFromDB($this->fields['aggregate_items']); foreach ($items as $itemtype => $data) { switch ($itemtype) { case 'PluginMonitoringService': foreach ($data as $items_id => $data2) { $pmService->getFromDB($items_id); $_SESSION['plugin_monitoring_checkinterval'] = PluginMonitoringComponent::getTimeBetween2Checks($pmService->fields['plugin_monitoring_components_id']); $pmComponent->getFromDB($pmService->fields['plugin_monitoring_components_id']); $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n AND `date` >= '" . $a_date['begin'] . "'\n ORDER BY `date`"; $result = $DB->query($query); $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template'], $a_date['begin'], $a_date['end']); foreach ($data2 as $a_perfdatadetails) { $pmPerfdataDetail->getFromDB($a_perfdatadetails['perfdatadetails_id']); $nb_val += count($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); $val += array_sum($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); $a_val = array_merge($a_val, $ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); } // for manage warn, crit and limit foreach ($a_tocheck as $other_type => $num_type) { if ($num_type == 1) { $other_items = importArrayFromDB($this->fields['aggregate_' . $other_type]); foreach ($other_items[$itemtype][$items_id] as $a_perfdatadetails) { $pmPerfdataDetail->getFromDB($a_perfdatadetails['perfdatadetails_id']); $a_ret[$other_type] += array_sum($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); } } } } break; case 'PluginMonitoringComponentscatalog': $pmComponentscatalog = new PluginMonitoringComponentscatalog(); foreach ($data as $items_id => $data2) { $ret = $pmComponentscatalog->getInfoOfCatalog(str_replace('id', '', $items_id)); $a_hosts = $ret[6]; foreach ($data2['PluginMonitoringComponent'] as $items_id_components => $data4) { $query = "SELECT * FROM `glpi_plugin_monitoring_services`\n WHERE `plugin_monitoring_components_id`='" . str_replace('id', '', $items_id_components) . "'\n AND `plugin_monitoring_componentscatalogs_hosts_id` IN\n ('" . implode("','", $a_hosts) . "')\n AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")"; $result = $DB->query($query); while ($dataq = $DB->fetch_array($result)) { $pmService->getFromDB($dataq['id']); $_SESSION['plugin_monitoring_checkinterval'] = PluginMonitoringComponent::getTimeBetween2Checks($pmService->fields['plugin_monitoring_components_id']); $pmComponent->getFromDB($dataq['plugin_monitoring_components_id']); $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $dataq['id'] . "'\n AND `date` >= '" . $a_date['begin'] . "'\n ORDER BY `date`"; $result = $DB->query($query); $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template'], $a_date['begin'], $a_date['end']); foreach ($data4 as $a_perfdatadetails) { $pmPerfdataDetail->getFromDB($a_perfdatadetails['perfdatadetails_id']); $nb_val += count($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); $val += array_sum($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); $a_val = array_merge($a_val, $ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); } // for manage warn, crit and limit foreach ($a_tocheck as $other_type => $num_type) { if ($num_type == 1) { $other_items = importArrayFromDB($this->fields['aggregate_' . $other_type]); foreach ($other_items[$itemtype][$items_id]['PluginMonitoringComponent'][$items_id_components] as $a_perfdatadetails) { $pmPerfdataDetail->getFromDB($a_perfdatadetails['perfdatadetails_id']); $a_ret[$other_type] += array_sum($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); } } } } } } break; } } if ($nb_val != 0) { if ($type == 'average') { $val = $val / $nb_val; } else { if ($type == 'median') { sort($a_val); $count = count($a_val); //total numbers in array $middleval = floor(($count - 1) / 2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $a_val[$middleval]; } else { // even number, calculate avg of 2 medians $low = $arr[$middleval]; $high = $arr[$middleval + 1]; $median = ($low + $high) / 2; } $val = $median; } } } foreach ($a_tocheck as $other_type => $num_type) { if ($num_type == 1) { $a_ret[$other_type] = $a_ret[$other_type] / $nb_val; } } $a_ret['val'] = $val; return $a_ret; }
static function listForComponents($components_id) { global $DB; $pmComponentscatalog = new PluginMonitoringComponentscatalog(); echo "<table class='tab_cadre' width='400'>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Components catalog', 'monitoring') . "</th>"; echo "</tr>"; $query = "SELECT `glpi_plugin_monitoring_componentscatalogs`.* FROM `glpi_plugin_monitoring_componentscatalogs_components`\n LEFT JOIN `glpi_plugin_monitoring_componentscatalogs`\n ON `plugin_monitoring_componentscalalog_id` =\n `glpi_plugin_monitoring_componentscatalogs`.`id`\n WHERE `plugin_monitoring_components_id`='" . $components_id . "'\n ORDER BY `glpi_plugin_monitoring_componentscatalogs`.`name`"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { echo "<tr class='tab_bg_1'>"; echo "<td>"; $pmComponentscatalog->getFromDB($data['id']); echo $pmComponentscatalog->getLink(1); echo "</td>"; echo "</tr>"; } echo "</table>"; }
@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::checkCentralAccess(); Html::header(__('Monitoring - dashboard (components catalogs)', 'monitoring'), $_SERVER["PHP_SELF"], "plugins", "PluginMonitoringDashboard", "dashboard"); // Display ressources perfdata ? if (isset($_SESSION['plugin_monitoring']['ressources_perfdata'])) { unset($_SESSION['plugin_monitoring']['ressources_perfdata']); } // Reduced or normal interface ? if (!isset($_SESSION['plugin_monitoring_reduced_interface'])) { $_SESSION['plugin_monitoring_reduced_interface'] = false; } if (isset($_POST['reduced_interface'])) { $_SESSION['plugin_monitoring_reduced_interface'] = $_POST['reduced_interface']; } $pmDisplay = new PluginMonitoringDisplay(); $pmMessage = new PluginMonitoringMessage(); $pmMessage->getMessages(); $pmDisplay->menu(); $pmDisplay->refreshPage(TRUE); $pmDisplay->showCounters("Componentscatalog"); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponentscatalog->showChecks($_SESSION['plugin_monitoring_reduced_interface']); Html::footer();
static function getAdditionalMenuOptions() { global $CFG_GLPI; $main_menu = '<img src="' . $CFG_GLPI["root_doc"] . '/plugins/monitoring/pics/main_menu.png" alt="' . __('Main menu', 'monitoring') . '" title="' . __('Main menu', 'monitoring') . '"\\>'; return array('componentscatalog' => array('title' => PluginMonitoringComponentscatalog::getTypeName(), 'page' => PluginMonitoringComponentscatalog::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/componentscatalog.php', 'add' => '/plugins/monitoring/front/componentscatalog.form.php')), 'command' => array('title' => PluginMonitoringCommand::getTypeName(), 'page' => PluginMonitoringCommand::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/command.php', 'add' => '/plugins/monitoring/front/command.form.php')), 'check' => array('title' => PluginMonitoringCheck::getTypeName(), 'page' => PluginMonitoringCheck::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/check.php', 'add' => '/plugins/monitoring/front/check.form.php')), 'eventhandler' => array('title' => PluginMonitoringEventhandler::getTypeName(), 'page' => PluginMonitoringEventhandler::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/eventhandler.php', 'add' => '/plugins/monitoring/front/eventhandler.form.php')), 'perfdata' => array('title' => PluginMonitoringPerfdata::getTypeName(), 'page' => PluginMonitoringPerfdata::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/perfdata.php', 'add' => '/plugins/monitoring/front/perfdata.form.php')), 'component' => array('title' => PluginMonitoringComponent::getTypeName(), 'page' => PluginMonitoringComponent::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/component.php', 'add' => '/plugins/monitoring/front/component.form.php')), 'contacttemplate' => array('title' => PluginMonitoringContacttemplate::getTypeName(), 'page' => PluginMonitoringContacttemplate::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/contacttemplate.php', 'add' => '/plugins/monitoring/front/contacttemplate.form.php')), 'notificationcommand' => array('title' => PluginMonitoringNotificationcommand::getTypeName(), 'page' => PluginMonitoringNotificationcommand::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/notificationcommand.php', 'add' => '/plugins/monitoring/front/notificationcommand.form.php')), 'realm' => array('title' => PluginMonitoringRealm::getTypeName(), 'page' => PluginMonitoringRealm::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/realm.php', 'add' => '/plugins/monitoring/front/realm.form.php')), 'tag' => array('title' => PluginMonitoringTag::getTypeName(), 'page' => PluginMonitoringTag::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/tag.php')), 'servicescatalog' => array('title' => PluginMonitoringServicescatalog::getTypeName(), 'page' => PluginMonitoringServicescatalog::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/servicescatalog.php', 'add' => '/plugins/monitoring/front/servicescatalog.form.php')), 'weathermap' => array('title' => PluginMonitoringWeathermap::getTypeName(), 'page' => PluginMonitoringWeathermap::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/weathermap.php', 'add' => '/plugins/monitoring/front/weathermap.form.php')), 'displayview' => array('title' => PluginMonitoringDisplayview::getTypeName(), 'page' => PluginMonitoringDisplayview::getSearchURL(false), 'links' => array('search' => '/plugins/monitoring/front/displayview.php', 'add' => '/plugins/monitoring/front/displayview.form.php')), 'slider' => array('title' => PluginMonitoringSlider::getTypeName(), 'page' => PluginMonitoringSlider::getSearchURL(false), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'search' => '/plugins/monitoring/front/slider.php', 'add' => '/plugins/monitoring/front/slider.form.php')), 'downtime' => array('title' => PluginMonitoringDowntime::getTypeName(), 'page' => PluginMonitoringDowntime::getSearchURL(false), 'links' => array('search' => '/plugins/monitoring/front/downtime.php')), 'acknowledge' => array('title' => PluginMonitoringAcknowledge::getTypeName(), 'page' => PluginMonitoringAcknowledge::getSearchURL(false), 'links' => array('search' => '/plugins/monitoring/front/acknowledge.php')), 'menu' => array('title' => PluginMonitoringMenu::getTypeName(), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'config' => '/plugins/monitoring/front/config.form.php')), 'dashboard' => array('title' => PluginMonitoringDisplay::getTypeName(), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php', 'config' => '/plugins/monitoring/front/config.form.php')), 'config' => array('title' => PluginMonitoringConfig::getTypeName(), 'links' => array($main_menu => '/plugins/monitoring/front/menu.php'))); }
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; }
/** * Display content of tab * * @param CommonGLPI $item * @param integer $tabnum * @param interger $withtemplate * * @return boolean true */ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { switch ($item->getType()) { case 'Central' : $pmDisplay = new PluginMonitoringDisplay(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); // $pmDisplay->showCounters("Componentscatalog"); $pmComponentscatalog->showChecks(); return true; } if ($item->getID() > 0) { switch($tabnum) { case 1: $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); $pmComponentscatalog_Component->showComponents($item->getID()); break; case 2 : $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmComponentscatalog_Host->showHosts($item->getID(), 1); break; case 3 : $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule(); $pmComponentscatalog_rule->showRules($item->getID()); break; case 4 : $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmComponentscatalog_Host->showHosts($item->getID(), 0); break; case 5 : $pmContact_Item = new PluginMonitoringContact_Item(); $pmContact_Item->showContacts("PluginMonitoringComponentscatalog", $item->getID()); break; case 6: $pmUnavailability = new PluginMonitoringUnavailability(); $pmUnavailability->displayComponentscatalog($item->getID()); break; case 7: $pmPluginMonitoringComponentscatalog = new PluginMonitoringComponentscatalog(); $pmPluginMonitoringComponentscatalog->showSimpleReport($item->getID()); break; case 8: $pmPluginMonitoringComponentscatalog = new PluginMonitoringComponentscatalog(); $pmPluginMonitoringComponentscatalog->showSyntheseReport($item->getID()); break; default : } } return true; }
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'); }
/** * Display graphs of services associated with host * * @param $itemtype value type of item * @param $items_id integer id of the object * **/ function showGraphsByHost($itemtype, $items_id) { global $CFG_GLPI, $DB; PluginMonitoringServicegraph::loadLib(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponent = new PluginMonitoringComponent(); $pmServicegraph = new PluginMonitoringServicegraph(); $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `items_id`='" . $items_id . "'\n AND `itemtype`='" . $itemtype . "'"; $result = $DB->query($query); echo '<div id="custom_date" style="display:none"></div>'; echo '<div id="custom_time" style="display:none"></div>'; echo "<table class='tab_cadre_fixe'>"; $td = 0; while ($data = $DB->fetch_array($result)) { $pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']); $querys = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services`\n LEFT JOIN `glpi_plugin_monitoring_components`\n on `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`\n WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $data['id'] . "'\n ORDER BY `name`"; $results = $DB->query($querys); while ($datas = $DB->fetch_array($results)) { $pmComponent->getFromDB($datas['plugin_monitoring_components_id']); if ($pmComponent->fields['graph_template'] != '') { if ($td == 0) { echo "<tr>"; } echo "<td width='425'>"; echo "<table class='tab_cadre'>"; echo "<tr class='tab_bg_3'>"; echo "<th width='475'>"; echo $pmComponent->fields['name']; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>"; $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $datas['id'], "0", "2h", "", 450); echo "</td>"; echo "</tr>"; echo "</table>"; $td++; echo "</td>"; if ($td == 2) { echo "</tr>"; $td = 0; } } } } if ($td == 1) { echo "<td></td>"; } echo "</tr>"; echo "</table>"; }