Ejemplo n.º 1
0
 /**
  * This method get the macro attached to the host
  * 
  * @param int $iHostId
  * @param int $bIsTemplate
  * @param array $aListTemplate
  * @param int $iIdCommande
  * @return array
  */
 public function getMacros($iHostId, $bIsTemplate, $aListTemplate, $iIdCommande)
 {
     $aMacro = array();
     $macroArray = array();
     $aMacroInCommande = array();
     $aMacroInService = array();
     //Get macro attached to the host
     $macroArray = $this->getCustomMacroInDb($iHostId);
     //Get macro attached to the template
     $aMacroTemplate = array();
     foreach ($aListTemplate as $template) {
         if (!empty($template['host_id'])) {
             $aMacroTemplate[] = $this->getCustomMacroInDb($template['host_id'], $template);
         }
     }
     if (empty($iIdCommande)) {
         foreach ($aListTemplate as $template) {
             if (!empty($template['command_command_id'])) {
                 $iIdCommande = $template['command_command_id'];
                 break;
             }
         }
     }
     //Get macro attached to the command
     if (!empty($iIdCommande)) {
         $oCommand = new CentreonCommand($this->db);
         $aMacroInCommande[] = $oCommand->getMacroByIdAndType($iIdCommande, 'host');
     }
     //filter a macro
     $aTempMacro = array();
     if (count($macroArray) > 0) {
         foreach ($macroArray as $directMacro) {
             $directMacro['macroOldValue'] = $directMacro["host_macro_value"];
             $directMacro['macroFrom'] = 'direct';
             $directMacro['source'] = 'direct';
             $aTempMacro[] = $directMacro;
         }
     }
     if (count($aMacroTemplate) > 0) {
         foreach ($aMacroTemplate as $key => $macr) {
             foreach ($macr as $mm) {
                 $mm['macroOldValue'] = $mm["host_macro_value"];
                 $mm['macroFrom'] = 'fromTpl';
                 $mm['source'] = 'fromTpl';
                 $aTempMacro[] = $mm;
             }
         }
     }
     if (count($aMacroInCommande) > 0) {
         $macroCommande = current($aMacroInCommande);
         for ($i = 0; $i < count($macroCommande); $i++) {
             $macroCommande[$i]['macroOldValue'] = $macroCommande[$i]["host_macro_value"];
             $macroCommande[$i]['macroFrom'] = 'fromCommand';
             $macroCommande[$i]['source'] = 'fromCommand';
             $aTempMacro[] = $macroCommande[$i];
         }
     }
     $aFinalMacro = $this->macro_unique($aTempMacro);
     return $aFinalMacro;
 }
 /**
  * This method get the macro attached to the service
  * 
  * @param int $iServiceId
  * @param array $aListTemplate
  * @param int $iIdCommande
  * 
  * @return array
  */
 public function getMacros($iServiceId, $aListTemplate, $iIdCommande)
 {
     $aMacro = array();
     $macroArray = array();
     $aMacroInService = array();
     //Get macro attached to the service
     $macroArray = $this->getCustomMacroInDb($iServiceId);
     $iNb = count($macroArray);
     //Get macro attached to the template
     $aMacroTemplate = array();
     // clear current template/service from the list.
     unset($aListTemplate[count($aListTemplate) - 1]);
     foreach ($aListTemplate as $template) {
         if (!empty($template)) {
             $aMacroTemplate[] = $this->getCustomMacroInDb($template['service_id'], $template);
         }
     }
     if (empty($iIdCommande)) {
         foreach ($aListTemplate as $template) {
             if (!empty($template['command_command_id'])) {
                 $iIdCommande = $template['command_command_id'];
             }
         }
     }
     //Get macro attached to the command
     if (!empty($iIdCommande)) {
         $oCommand = new CentreonCommand($this->db);
         $aMacroInService[] = $oCommand->getMacroByIdAndType($iIdCommande, 'service');
     }
     //filter a macro
     $aTempMacro = array();
     $serv = current($aMacroInService);
     if (count($aMacroInService) > 0) {
         for ($i = 0; $i < count($serv); $i++) {
             $serv[$i]['macroOldValue_#index#'] = $serv[$i]["svc_macro_value"];
             $serv[$i]['macroFrom_#index#'] = 'fromService';
             $serv[$i]['source'] = 'fromService';
             $aTempMacro[] = $serv[$i];
         }
     }
     if (count($aMacroTemplate) > 0) {
         foreach ($aMacroTemplate as $key => $macr) {
             foreach ($macr as $mm) {
                 $mm['macroOldValue_#index#'] = $mm["svc_macro_value"];
                 $mm['macroFrom_#index#'] = 'fromTpl';
                 $mm['source'] = 'fromTpl';
                 $aTempMacro[] = $mm;
             }
         }
     }
     if (count($macroArray) > 0) {
         foreach ($macroArray as $directMacro) {
             $directMacro['macroOldValue_#index#'] = $directMacro["svc_macro_value"];
             $directMacro['macroFrom_#index#'] = 'direct';
             $directMacro['source'] = 'direct';
             $aTempMacro[] = $directMacro;
         }
     }
     $aFinalMacro = $this->macro_unique($aTempMacro);
     return $aFinalMacro;
 }