function showWidgetFrame($id, $reduced_interface = false, $is_minemap = FALSE) { global $DB, $CFG_GLPI; $pmParentSC = new PluginMonitoringServicescatalog(); $pMonitoringBusinessrule = new PluginMonitoringBusinessrule(); $pMonitoringBusinessrulegroup = new PluginMonitoringBusinessrulegroup(); $pMonitoringService = new PluginMonitoringService(); $this->getFromDB($id); $derivated = false; if ($this->getField('plugin_monitoring_servicescatalogs_id') > 0) { $derivated = true; $pmParentSC->getFromDB($this->getField('plugin_monitoring_servicescatalogs_id')); } $data = $this->fields; // Toolbox::logInFile("pm", "SC : ".$data['id'].", name : ".$data['name'].", derivated : ".$derivated."\n"); $colorclass = 'ok'; switch ($data['state']) { case 'CRITICAL': case 'DOWNTIME': $colorclass = 'crit'; break; case 'WARNING': case 'UNKNOWN': case 'RECOVERY': case 'FLAPPING': case '': $colorclass = 'warn'; break; } echo '<br/><div class="ch-itemup"> <div class="ch-info-' . $colorclass . '"> <h1><a href="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/front/servicescatalog.form.php?id=' . $data['id'] . '&detail=1">'; echo $data['name']; if ($data['comment'] != '') { echo ' ' . $this->getComments(); } echo '</a></h1> </div> </div>'; // If SC is derivated from a template, get groups from its parent ... if ($derivated) { $a_group = $pMonitoringBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $pmParentSC->fields['id'] . "'"); } else { $a_group = $pMonitoringBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $data['id'] . "'"); } // Array updated dynamically with groups/hosts/services status ... $colorclass = 'ok'; $a_gstate = array(); $cs_info = array(); foreach ($a_group as $gdata) { // Toolbox::logInFile("pm", "BR group : ".$gdata['id'].", name : ".$gdata['name']."\n"); $a_brules = $pMonitoringBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $gdata['id'] . "'"); $state = array(); $state['OK'] = 0; $state['WARNING'] = 0; $state['CRITICAL'] = 0; $cs_info_hosts = array(); $cs_info_services = array(); foreach ($a_brules as $brulesdata) { // If SC is derivated from a template, do not care about services not from the same entity ... if (!$pMonitoringService->getFromDB($brulesdata['plugin_monitoring_services_id'])) { continue; } if ($derivated && $pMonitoringService->getField('entities_id') != $this->getField('entities_id')) { continue; } // Toolbox::logInFile("pm", "BR : ".$brulesdata['id'].", service : ".$brulesdata['plugin_monitoring_services_id']."\n"); if (!isset($cs_info_hosts[$pMonitoringService->getHostName()])) { $cs_info_hosts[$pMonitoringService->getHostName()] = array(); } $cs_info_hosts[$pMonitoringService->getHostName()]['id'] = $pMonitoringService->getHostId(); $cs_info_hosts[$pMonitoringService->getHostName()]['name'] = $pMonitoringService->getHostName(); $cs_info_hosts[$pMonitoringService->getHostName()]['services'][$pMonitoringService->getName()]['id'] = $pMonitoringService->fields['id']; $cs_info_hosts[$pMonitoringService->getHostName()]['services'][$pMonitoringService->getName()]['state'] = $pMonitoringService->fields['state']; $cs_info_hosts[$pMonitoringService->getHostName()]['services'][$pMonitoringService->getName()]['last_check'] = $pMonitoringService->fields['last_check']; $cs_info_hosts[$pMonitoringService->getHostName()]['services'][$pMonitoringService->getName()]['event'] = $pMonitoringService->fields['event']; // Get all host services except if state is ok or is already acknowledged ... $a_ret = PluginMonitoringHost::getServicesState($pMonitoringService->getHostId(), "`glpi_plugin_monitoring_services`.`state` != 'OK'"); $cs_info_hosts[$pMonitoringService->getHostName()]['state'] = $a_ret[0]; $cs_info_services[$pMonitoringService->getName()] = $pMonitoringService->fields['plugin_monitoring_components_id']; switch ($pMonitoringService->fields['state']) { case 'UP': case 'OK': $state['OK']++; break; case 'DOWN': case 'UNREACHABLE': case 'CRITICAL': case 'DOWNTIME': $state['CRITICAL']++; break; case 'WARNING': case 'UNKNOWN': case 'RECOVERY': case 'FLAPPING': $state['WARNING']++; break; } } if ($state['CRITICAL'] >= 1) { $a_gstate[$gdata['id']] = "CRITICAL"; } else { if ($state['WARNING'] >= 1) { $a_gstate[$gdata['id']] = "WARNING"; } else { $a_gstate[$gdata['id']] = "OK"; } } $cs_info[$gdata['id']] = array(); $cs_info[$gdata['id']]['name'] = $gdata['name']; $cs_info[$gdata['id']]['state'] = $a_gstate[$gdata['id']]; $cs_info[$gdata['id']]['hosts'] = $cs_info_hosts; $cs_info[$gdata['id']]['services'] = $cs_info_services; } $state = array(); $state['OK'] = 0; $state['WARNING'] = 0; $state['CRITICAL'] = 0; foreach ($a_gstate as $value) { $state[$value]++; } $color = 'green'; if ($state['CRITICAL'] > 0) { $color = 'red'; $colorclass = 'crit'; } else { if ($state['WARNING'] > 0) { $color = 'orange'; $colorclass = 'warn'; } } echo '<div class="ch-itemdown"> <div class="ch-info-' . $colorclass . '"> <p><font style="font-size: 20px;">'; if ($colorclass != 'ok') { echo __('Degraded mode', 'monitoring') . '!'; } echo '</font></p> </div> </div>'; // Show a minemap if requested ... echo "<div class='minemapdiv' align='center'>" . "<a onclick='\$(\"#minemapSC-" . $id . "\").toggle();'>" . __('Minemap', 'monitoring') . "</a></div>"; if (!$is_minemap) { echo '<div class="minemapdiv" id="minemapSC-' . $id . '" style="display: none; z-index: 1500">'; } else { echo '<div class="minemapdiv" id="minemapSC-' . $id . '">'; } echo '<table class="tab_cadrehov">'; foreach ($cs_info as $groupName => $group) { echo '<table class="tab_cadrehov">'; echo '<tr>'; echo '<th colspan="' . (1 + count($group['services'])) . '">' . __('Business rules group', 'monitoring') . " : " . $group['name'] . '</th>'; echo '</tr>'; echo '<tr>'; echo "<th>"; echo __('Hosts', 'monitoring'); echo "</th>"; foreach ($group['services'] as $serviceName => $service) { if (Session::haveRight("plugin_monitoring_service", READ)) { $link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?hidesearch=1" . "&criteria[0][field]=2" . "&criteria[0][searchtype]=equals" . "&criteria[0][value]=" . $service . "&itemtype=PluginMonitoringService" . "&start=0'"; echo '<th class="vertical">'; echo '<a href="' . $link . '"><div class="rotated-text"><span class="rotated-text__inner">' . $serviceName . '</span></div></a>'; echo '</th>'; } else { echo '<th class="vertical">'; echo '<div class="rotated-text"><span class="rotated-text__inner">' . $serviceName . '</span></div>'; echo '</th>'; } } echo '</tr>'; foreach ($group['hosts'] as $host) { echo "<tr class='tab_bg_2' style='height: 50px;'>"; if (Session::haveRight("plugin_monitoring_service", READ)) { $link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?hidesearch=1" . "&criteria[0][field]=20" . "&criteria[0][searchtype]=equals" . "&criteria[0][value]=" . $host['id'] . "&itemtype=PluginMonitoringService" . "&start=0'"; echo "<td class='left'><a href='" . $link . "'>" . $host['name'] . "</a></td>"; } else { echo "<td class='left'>" . $host['name'] . "</td>"; } // echo "<td class='left'>".$host['name']."</td>"; foreach ($host['services'] as $serviceName => $service) { echo '<td>'; echo '<div title="' . $service['last_check'] . ' - ' . $service['event'] . '" class="service service' . $service['state'] . '"></div>'; echo '</td>'; } echo '</tr>'; } echo '</table>'; } echo '</table>'; echo '</div>'; }