diff --git a/www/class/centreonCriticality.class.php b/www/class/centreonCriticality.class.php index 305967f311c..c63169d0a8e 100644 --- a/www/class/centreonCriticality.class.php +++ b/www/class/centreonCriticality.class.php @@ -293,7 +293,7 @@ public function criticitiesConfigOnSTpl($service_id) { if (isset($this->tree[$service_id]) && $this->tree[$service_id] != 0) { return $this->tree[$service_id]; } - return array(); + return 0; } /** @@ -329,4 +329,29 @@ protected function getServiceCriticality($service_id) { } return 0; } + + function getHostTplCriticities($host_id, $cache) { + global $pearDB; + + if (!$host_id) { + return NULL; + } + + $rq = "SELECT host_tpl_id " . + "FROM host_template_relation " . + "WHERE host_host_id = '".$host_id."' " . + "ORDER BY `order`"; + $DBRESULT = $pearDB->query($rq); + while ($row = $DBRESULT->fetchRow()) { + if (isset($cache[$row['host_tpl_id']])) { + return $this->getData($cache[$row['host_tpl_id']], false); + } else { + if ($result_field = $this->getHostTplCriticities($row['host_tpl_id'], $cache)) { + return $result_field; + } + } + } + return NULL; + } + } diff --git a/www/include/configuration/configGenerate/genServices.php b/www/include/configuration/configGenerate/genServices.php index e3317d1319a..263c4a37cf3 100644 --- a/www/include/configuration/configGenerate/genServices.php +++ b/www/include/configuration/configGenerate/genServices.php @@ -94,12 +94,11 @@ * Build cache for Macro */ $macroCache = array(); -$DBRESULT3 = $pearDB->query("SELECT svc_macro_name, svc_macro_value, svc_svc_id - FROM on_demand_macro_service - WHERE svc_macro_name NOT IN (SELECT macro_name FROM nagios_macro)"); +$DBRESULT3 = $pearDB->query("SELECT svc_macro_name, svc_macro_value, svc_svc_id FROM on_demand_macro_service WHERE svc_macro_name NOT IN (SELECT macro_name FROM nagios_macro)"); while ($od_macro = $DBRESULT3->fetchRow()) { - if (!isset($macroCache[$od_macro["svc_svc_id"]])) + if (!isset($macroCache[$od_macro["svc_svc_id"]])) { $macroCache[$od_macro["svc_svc_id"]] = array(); + } $macroCache[$od_macro["svc_svc_id"]][$od_macro["svc_macro_name"]] = $od_macro["svc_macro_value"]; } $DBRESULT3->free(); @@ -217,6 +216,7 @@ } else { // Check if criticities is configured on service templates $buff = $criticality->criticitiesConfigOnSTpl($service['service_template_model_stm_id']); + if ($buff == 0) { // Get Criticities From hosts global $critCacheName; @@ -224,6 +224,10 @@ $name = $critCacheName[$host_name]['name']; $strTMP .= print_line("_CRITICALITY_LEVEL", $critSData[$name]['level']); $strTMP .= print_line("_CRITICALITY_ID", $critSData[$name]['id']); + } else { + $tmp1 = $criticality->getHostTplCriticities($host_id, $critHTpl); + $strTMP .= print_line("_CRITICALITY_LEVEL", $critSData[$tmp1['name']]['level']); + $strTMP .= print_line("_CRITICALITY_ID", $critSData[$tmp1['name']]['id']); } } } @@ -541,10 +545,14 @@ * Host Relation */ $strTMPTemp = NULL; + $tmpHostName = ""; if (isset($serviceRelation[$service["service_id"]]["h"])) foreach ($serviceRelation[$service["service_id"]]["h"] as $key => $value) { $parent = true; $strTMPTemp != NULL ? $strTMPTemp .= ", ".$value : $strTMPTemp = $value; + if ($tmpHostName == ''){ + $tmpHostName = $strTMPTemp; + } $LinkedToHost++; } if ($strTMPTemp) { @@ -580,10 +588,14 @@ if ($buff == 0) { // Get Criticities From hosts global $critCacheName; - if (isset($critCacheName[$host_name])) { - $name = $critCacheName[$host_name]['name']; + if (isset($critCacheName[$tmpHostName])) { + $name = $critCacheName[$tmpHostName]['name']; $strTMP .= print_line("_CRITICALITY_LEVEL", $critSData[$name]['level']); $strTMP .= print_line("_CRITICALITY_ID", $critSData[$name]['id']); + } else { + $tmp1 = $criticality->getHostTplCriticities($host_id, $critHTpl); + $strTMP .= print_line("_CRITICALITY_LEVEL", $critSData[$tmp1['name']]['level']); + $strTMP .= print_line("_CRITICALITY_ID", $critSData[$tmp1['name']]['id']); } } }