Changeset 6257

Show
Ignore:
Timestamp:
08/21/08 19:30:43 (5 months ago)
Author:
dduponchelle
Message:

Export problem resolved with hostgroups escalations.
Comments added and code normalized.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/centreon/www/include/configuration/configGenerate/genEscalations.php

    r6138 r6257  
    1616 */ 
    1717 
     18/* 
     19 * This script generate the file configuration escalations.cfg used by Nagios. 
     20 * This script is shared to 6 parts: 
     21 *  - PART 1 : Collect Escalations for all Hosts 
     22 *  - PART 2 : Collect Escalations for all HostGroups  
     23 *  - PART 3 : Collect Escalations for all ServiceGroups 
     24 *  - PART 4 : Collect Escalations for all Services 
     25 *  - PART 5 : Generate the configuration with all datas collected 
     26 * 
     27 * PHP version 5 
     28 * 
     29 * @package genEscalations.php 
     30 * @author Damien Duponchelle dduponchelle@merethis.com 
     31 * @version $Id: $ 
     32 * @copyright (c) 2007-2008 Centreon 
     33 * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
     34 */ 
     35 
    1836        if (!isset($oreon)) 
    1937                exit(); 
     
    2341        } 
    2442 
     43        // Creating handle to write the file configuration 
    2544        $handle = create_file($nagiosCFGPath.$tab['id']."/escalations.cfg", $oreon->user->get_name()); 
     45 
     46        // PART 1 - Escalations for all Hosts 
    2647        $DBRESULT =& $pearDB->query("SELECT DISTINCT esc.* FROM escalation_host_relation ehr, escalation esc WHERE ehr.escalation_esc_id = esc.esc_id ORDER BY esc.esc_name"); 
    27         if (PEAR::isError($DBRESULT)) 
    28                 print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     48        if (PEAR::isError($DBRESULT)){ 
     49                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />";          
     50        } 
     51         
    2952        $escalation = array(); 
    3053        $i = 1; 
    3154        $str = NULL; 
    32         while($escalation =& $DBRESULT->fetchRow()){ 
     55        while($escalation =& $DBRESULT->fetchRow()) { 
     56                 
    3357                $BP = false; 
    3458                $strDef = ""; 
    3559                $linkedToHost = 0; 
     60                 
    3661                $DBRESULT2 =& $pearDB->query("SELECT DISTINCT host.host_id, host.host_name FROM escalation_host_relation ehr, host , ns_host_relation nhr WHERE ehr.escalation_esc_id = '".$escalation["esc_id"]."' AND host.host_id = ehr.host_host_id AND host.host_id = nhr.host_host_id AND nhr.nagios_server_id = '".$tab['id']."' "); 
    37                 if (PEAR::isError($DBRESULT2)) 
     62                if (PEAR::isError($DBRESULT2)) { 
    3863                        print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     64                } 
     65                 
    3966                $host = array(); 
    4067                $strTemp = NULL; 
    4168                while ($host =& $DBRESULT2->fetchRow()) { 
     69                         
    4270                        $BP = false; 
    4371                        array_key_exists($host["host_id"], $gbArr[2]) ? $BP = true : NULL; 
    4472                         
    45                         if ($BP && isHostOnThisInstance($host["host_id"], $tab['id'])){ 
    46                                 $linkedToHost++;         
     73                        if($BP && isHostOnThisInstance($host["host_id"], $tab['id'])) { 
     74                                $linkedToHost++; 
    4775                                $strTemp != NULL ? $strTemp .= ", ".$host["host_name"] : $strTemp = $host["host_name"]; 
    4876                        } 
    4977                } 
     78                 
    5079                $DBRESULT2->free();                      
    51                 if ($strTemp)   { 
     80                if (isset($strTemp) == true) { 
    5281                        $ret["comment"] ? ($strDef .= "# '".$escalation["esc_name"]."' host escalation definition ".$i."\n") : NULL; 
    53                         if ($ret["comment"] && $escalation["esc_comment"])      { 
     82                         
     83                        if ($ret["comment"] && $escalation["esc_comment"]) { 
    5484                                $comment = array(); 
    5585                                $comment = explode("\n", $escalation["esc_comment"]); 
    56                                 foreach ($comment as $cmt) 
     86                                 
     87                                foreach ($comment as $cmt) { 
    5788                                        $strDef .= "# ".$cmt."\n"; 
    58                         } 
     89                                } 
     90                        } 
     91                         
    5992                        $strDef .= "define hostescalation{\n"; 
    6093                        $strDef .= print_line("host_name", $strTemp); 
     
    6295                        $cg = array(); 
    6396                        $strTemp = NULL; 
     97                         
    6498                        $DBRESULT2 =& $pearDB->query("SELECT DISTINCT cg.cg_id, cg.cg_name FROM escalation_contactgroup_relation ecgr, contactgroup cg WHERE ecgr.escalation_esc_id = '".$escalation["esc_id"]."' AND ecgr.contactgroup_cg_id = cg.cg_id ORDER BY cg.cg_name"); 
    65                         if (PEAR::isError($DBRESULT2)) 
    66                                 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
    67                         while($cg =& $DBRESULT2->fetchRow())    { 
     99                        if (PEAR::isError($DBRESULT2)) { 
     100                                print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     101                        } 
     102                         
     103                        while($cg =& $DBRESULT2->fetchRow()) { 
    68104                                $BP = false;                             
    69105                                array_key_exists($cg["cg_id"], $gbArr[1]) ? $BP = true : $BP = false; 
    70106                                 
    71                                 if ($BP) 
     107                                if ($BP) { 
    72108                                        $strTemp != NULL ? $strTemp .= ", ".$cg["cg_name"] : $strTemp = $cg["cg_name"]; 
     109                                } 
    73110                        } 
    74111                         
    75112                        $DBRESULT2->free(); 
    76                         if ($strTemp) $strDef .= print_line("contact_groups", $strTemp);                         
    77                         if ($escalation["first_notification"] != NULL) $strDef .= print_line("first_notification", $escalation["first_notification"]); 
    78                         if ($escalation["last_notification"] != NULL) $strDef .= print_line("last_notification", $escalation["last_notification"]); 
    79                         if ($escalation["notification_interval"]!= NULL) $strDef .= print_line("notification_interval", $escalation["notification_interval"]); 
    80                          
    81                         // Nagios 2 & 3 
    82                          
    83                         if ($oreon->user->get_version() >= 2)   { 
    84                                 $DBRESULT2 =& $pearDB->query("SELECT tp_name FROM timeperiod WHERE tp_id = '".$escalation["escalation_period"]."'"); 
    85                                 if (PEAR::isError($DBRESULT2)) 
    86                                         print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
    87                                 $tp =& $DBRESULT2->fetchRow();                           
    88                                 if ($tp["tp_name"]) $strDef .= print_line("escalation_period", $tp["tp_name"]); 
    89                                 if ($escalation["escalation_options1"]) $strDef .= print_line("escalation_options", $escalation["escalation_options1"]); 
    90                                 $DBRESULT2->free(); 
    91                         } 
     113                        if (isset($strTemp) == true) $strDef .= print_line("contact_groups", $strTemp);                  
     114                        if (isset($escalation["first_notification"]) == true) $strDef .= print_line("first_notification", $escalation["first_notification"]); 
     115                        if (isset($escalation["last_notification"]) == true) $strDef .= print_line("last_notification", $escalation["last_notification"]); 
     116                        if (isset($escalation["notification_interval"]) == true) $strDef .= print_line("notification_interval", $escalation["notification_interval"]); 
     117                         
     118                        $DBRESULT2 =& $pearDB->query("SELECT tp_name FROM timeperiod WHERE tp_id = '".$escalation["escalation_period"]."'"); 
     119                        if (PEAR::isError($DBRESULT2)) { 
     120                                print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     121                        } 
     122                                 
     123                        $tp =& $DBRESULT2->fetchRow();                           
     124                        if (isset($tp["tp_name"]) == true) $strDef .= print_line("escalation_period", $tp["tp_name"]); 
     125                        if (isset($escalation["escalation_options1"]) == true) $strDef .= print_line("escalation_options", $escalation["escalation_options1"]); 
     126                         
     127                        $DBRESULT2->free(); 
    92128                        $strDef .= "}\n\n"; 
    93129                        $i++; 
    94130                } 
    95                 if ($linkedToHost) 
     131                 
     132                if (isset($linkedToHost) == true) { 
    96133                        $str .= $strDef; 
     134                } 
    97135                unset($strDef); 
    98136        } 
    99137        unset($escalation); 
    100138        $DBRESULT->free(); 
     139 
     140        // PART 2 - Escalations for all HostGroups       
     141        $DBRESULT =& $pearDB->query("SELECT DISTINCT esc.* FROM escalation_hostgroup_relation ehgr, escalation esc WHERE ehgr.escalation_esc_id = esc.esc_id ORDER BY esc.esc_name"); 
     142        if (PEAR::isError($DBRESULT)) { 
     143                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     144        } 
    101145         
    102         $DBRESULT =& $pearDB->query("SELECT DISTINCT esc.* FROM escalation_hostgroup_relation ehgr, escalation esc WHERE ehgr.escalation_esc_id = esc.esc_id ORDER BY esc.esc_name"); 
    103         if (PEAR::isError($DBRESULT)) 
    104                 print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
    105146        $escalation = array(); 
    106147        while($escalation =& $DBRESULT->fetchRow())     { 
    107148                $BP = false; 
    108149                $DBRESULT2 =& $pearDB->query("SELECT DISTINCT hg.hg_id, hg.hg_name FROM escalation_hostgroup_relation ehgr, hostgroup hg WHERE ehgr.escalation_esc_id = '".$escalation["esc_id"]."' AND hg.hg_id = ehgr.hostgroup_hg_id"); 
    109                 if (PEAR::isError($DBRESULT2)) 
     150                if (PEAR::isError($DBRESULT2)) { 
    110151                        print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     152                } 
     153                 
    111154                $hg = array(); 
    112155                $strTemp = NULL; 
    113                 while ($hg =& $DBRESULT2->fetchRow())   { 
     156                while ($hg =& $DBRESULT2->fetchRow()) { 
    114157                        $BP = false; 
    115158                        array_key_exists($hg["hg_id"], $gbArr[3]) ? $BP = true : NULL; 
    116159                         
    117                         if ($BP && $generatedHG[$hg["hg_name"]])         
     160                        if($BP) {        
    118161                                $strTemp != NULL ? $strTemp .= ", ".$hg["hg_name"] : $strTemp = $hg["hg_name"]; 
    119                 } 
     162                        } 
     163                } 
     164                 
    120165                $DBRESULT2->free(); 
    121                          
    122                 if ($strTemp && $generatedHG[$hg["hg_id"]])     { 
     166                 
     167                if (isset($strTemp) == true) { 
    123168                        $ret["comment"] ? ($str .= "# '".$escalation["esc_name"]."' host (group) escalation definition ".$i."\n") : NULL; 
    124                         if ($ret["comment"] && $escalation["esc_comment"])      { 
     169                         
     170                        if (isset($ret["comment"]) == true && isset($escalation["esc_comment"]) == true) { 
    125171                                $comment = array(); 
    126172                                $comment = explode("\n", $escalation["esc_comment"]); 
    127                                 foreach ($comment as $cmt) 
     173                                 
     174                                foreach ($comment as $cmt) { 
    128175                                        $str .= "# ".$cmt."\n"; 
    129                         } 
     176                                } 
     177                        } 
     178                         
    130179                        $str .= "define hostescalation{\n"; 
    131180                        $str .= print_line("hostgroup_name", $strTemp);                  
     181                         
     182                        $cg = array(); 
     183                        $strTemp = NULL; 
     184                         
     185                        $DBRESULT2 =& $pearDB->query("SELECT DISTINCT cg.cg_id, cg.cg_name FROM escalation_contactgroup_relation ecgr, contactgroup cg WHERE ecgr.escalation_esc_id = '".$escalation["esc_id"]."' AND ecgr.contactgroup_cg_id = cg.cg_id ORDER BY cg.cg_name"); 
     186                        if (PEAR::isError($DBRESULT2)) { 
     187                                print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     188                        } 
     189                         
     190                        while($cg =& $DBRESULT2->fetchRow()) { 
     191                                $BP = false;                             
     192                                array_key_exists($cg["cg_id"], $gbArr[1]) ? $BP = true : $BP = false; 
     193                                 
     194                                if($BP) { 
     195                                        $strTemp != NULL ? $strTemp .= ", ".$cg["cg_name"] : $strTemp = $cg["cg_name"]; 
     196                                } 
     197                        } 
     198                         
     199                        $DBRESULT2->free(); 
     200                         
     201                        if (isset($strTemp) == true) $str .= print_line("contact_groups", $strTemp);                     
     202                        if ($escalation["first_notification"] != NULL) $str .= print_line("first_notification", $escalation["first_notification"]); 
     203                        if ($escalation["last_notification"] != NULL) $str .= print_line("last_notification", $escalation["last_notification"]); 
     204                        if ($escalation["notification_interval"] != NULL) $str .= print_line("notification_interval", $escalation["notification_interval"]); 
     205                         
     206                        $DBRESULT2 =& $pearDB->query("SELECT tp_name FROM timeperiod WHERE tp_id = '".$escalation["escalation_period"]."'"); 
     207                        if (PEAR::isError($DBRESULT2)) { 
     208                                print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     209                        } 
     210                         
     211                        $tp =& $DBRESULT2->fetchRow();                           
     212                        if (isset($tp["tp_name"]) == true) $str .= print_line("escalation_period", $tp["tp_name"]); 
     213                        if ($escalation["escalation_options1"]) $str .= print_line("escalation_options", $escalation["escalation_options1"]); 
     214                        $str .= "}\n\n"; 
     215                        $i++; 
     216                } 
     217        } 
     218        unset($escalation); 
     219        $DBRESULT->free();       
     220 
     221        // PART 3 - Escalations for all ServiceGroups    
     222        $DBRESULT =& $pearDB->query("SELECT DISTINCT esc.* FROM escalation_servicegroup_relation esgr, escalation esc WHERE esgr.escalation_esc_id = esc.esc_id ORDER BY esc.esc_name"); 
     223        if (PEAR::isError($DBRESULT)) { 
     224                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     225        } 
     226         
     227        $escalation = array(); 
     228        $strTemp = NULL; 
     229        while($escalation =& $DBRESULT->fetchRow())     { 
     230                $BP = false; 
     231                 
     232                $DBRESULT2 =& $pearDB->query("SELECT DISTINCT sg.sg_id, sg.sg_name FROM escalation_servicegroup_relation esgr, servicegroup sg WHERE esgr.escalation_esc_id = '".$escalation["esc_id"]."' AND sg.sg_id = esgr.servicegroup_sg_id"); 
     233                if (PEAR::isError($DBRESULT2)) { 
     234                        print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     235                } 
     236                 
     237                $sg = array(); 
     238                 
     239                while ($sg =& $DBRESULT2->fetchRow()) { 
     240                        $BP = false; 
     241                        array_key_exists($sg["sg_id"], $gbArr[5]) ? $BP = true : NULL; 
     242                         
     243                        if($BP) {        
     244                                $strTemp != NULL ? $strTemp .= ", ".$sg["sg_name"] : $strTemp = $sg["sg_name"]; 
     245                        } 
     246                } 
     247                 
     248                $DBRESULT2->free(); 
     249                         
     250                if (isset($strTemp) == true) { 
     251                        $ret["comment"] ? ($str .= "# '".$escalation["esc_name"]."' service (group) escalation definition ".$i."\n") : NULL; 
     252                         
     253                        if ($ret["comment"] && $escalation["esc_comment"]) { 
     254                                $comment = array(); 
     255                                $comment = explode("\n", $escalation["esc_comment"]); 
     256                                 
     257                                foreach ($comment as $cmt) { 
     258                                        $str .= "# ".$cmt."\n"; 
     259                                } 
     260                        } 
     261                         
     262                        $str .= "define serviceescalation{\n"; 
     263                        $str .= print_line("servicegroup_name", $strTemp);                       
     264                         
    132265                        $cg = array(); 
    133266                        $strTemp = NULL; 
    134267                        $DBRESULT2 =& $pearDB->query("SELECT DISTINCT cg.cg_id, cg.cg_name FROM escalation_contactgroup_relation ecgr, contactgroup cg WHERE ecgr.escalation_esc_id = '".$escalation["esc_id"]."' AND ecgr.contactgroup_cg_id = cg.cg_id ORDER BY cg.cg_name"); 
    135                         if (PEAR::isError($DBRESULT2)) 
    136                                 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
    137                         while($cg =& $DBRESULT2->fetchRow())    { 
    138                                 $BP = false;                             
     268                        if (PEAR::isError($DBRESULT2)) { 
     269                                print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     270                        } 
     271                         
     272                        while($cg =& $DBRESULT2->fetchRow()) { 
     273                                $BP = false;                     
    139274                                array_key_exists($cg["cg_id"], $gbArr[1]) ? $BP = true : $BP = false; 
    140275                                 
    141                                 if ($BP) 
     276                                if($BP) { 
    142277                                        $strTemp != NULL ? $strTemp .= ", ".$cg["cg_name"] : $strTemp = $cg["cg_name"]; 
    143                         } 
     278                                } 
     279                        } 
     280                         
    144281                        $DBRESULT2->free(); 
    145                         if ($strTemp) $str .= print_line("contact_groups", $strTemp);                    
    146                         if ($escalation["first_notification"] != NULL) $str .= print_line("first_notification", $escalation["first_notification"]); 
    147                         if ($escalation["last_notification"] != NULL) $str .= print_line("last_notification", $escalation["last_notification"]); 
    148                         if ($escalation["notification_interval"] != NULL) $str .= print_line("notification_interval", $escalation["notification_interval"]); 
    149                          
    150                         /* 
    151                          *  Nagios 2 
    152                          */ 
    153                          
    154                         if ($oreon->user->get_version() >= 2)   { 
    155                                 $DBRESULT2 =& $pearDB->query("SELECT tp_name FROM timeperiod WHERE tp_id = '".$escalation["escalation_period"]."'"); 
    156                                 if (PEAR::isError($DBRESULT2)) 
    157                                         print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
    158                                 $tp =& $DBRESULT2->fetchRow();                           
    159                                 if ($tp["tp_name"]) $str .= print_line("escalation_period", $tp["tp_name"]); 
    160                                 if ($escalation["escalation_options1"]) $str .= print_line("escalation_options", $escalation["escalation_options1"]); 
    161                         } 
     282                         
     283                        if (isset($strTemp) == true) $str .= print_line("contact_groups", $strTemp);                     
     284                        if (isset($escalation["first_notification"]) == true) $str .= print_line("first_notification", $escalation["first_notification"]); 
     285                        if (isset($escalation["last_notification"]) == true) $str .= print_line("last_notification", $escalation["last_notification"]); 
     286                        if (isset($escalation["notification_interval"]) == true) $str .= print_line("notification_interval", $escalation["notification_interval"]); 
     287 
     288                        $DBRESULT2 =& $pearDB->query("SELECT tp_name FROM timeperiod WHERE tp_id = '".$escalation["escalation_period"]."'"); 
     289                        if (PEAR::isError($DBRESULT2)) { 
     290                                print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     291                        } 
     292                         
     293                        $tp =& $DBRESULT2->fetchRow();                           
     294                        if (isset($tp["tp_name"]) == true) $str .= print_line("escalation_period", $tp["tp_name"]); 
     295                        if (isset($escalation["escalation_options2"]) == true) $str .= print_line("escalation_options", $escalation["escalation_options2"]); 
     296 
    162297                        $str .= "}\n\n"; 
    163298                        $i++; 
     
    166301        unset($escalation); 
    167302        $DBRESULT->free();       
     303 
     304        // PART 4 -Escalation for all Services   
     305        $DBRESULT =& $pearDB->query("SELECT DISTINCT service.service_activate, service.service_description, esr.service_service_id FROM service, escalation_service_relation esr WHERE esr.service_service_id = service.service_id ORDER BY esr.service_service_id"); 
     306        if (PEAR::isError($DBRESULT)) { 
     307                print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
     308        } 
    168309         
    169         $DBRESULT =& $pearDB->query("SELECT DISTINCT esc.* FROM escalation_servicegroup_relation esgr, escalation esc WHERE esgr.escalation_esc_id = esc.esc_id ORDER BY esc.esc_name"); 
    170         if (PEAR::isError($DBRESULT)) 
    171                 print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
    172         $escalation = array(); 
    173         while($escalation =& $DBRESULT->fetchRow())     { 
    174                 $BP = false; 
    175                 $DBRESULT2 =& $pearDB->query("SELECT DISTINCT sg.sg_id, sg.sg_name FROM escalation_servicegroup_relation esgr, servicegroup sg WHERE esgr.escalation_esc_id = '".$escalation["esc_id"]."' AND sg.sg_id = esgr.servicegroup_sg_id"); 
    176                 if (PEAR::isError($DBRESULT2)) 
    177                         print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
    178                 $sg = array(); 
    179                 $strTemp = NULL; 
    180                 while ($sg =& $DBRESULT2->fetchRow())   { 
    181                         $BP = false; 
    182                         array_key_exists($sg["sg_id"], $gbArr[5]) ? $BP = true : NULL; 
    183                          
    184                         if ($BP)         
    185                                 $strTemp != NULL ? $strTemp .= ", ".$sg["sg_name"] : $strTemp = $sg["sg_name"]; 
    186                 } 
    187                 $DBRESULT2->free();                      
    188                 if ($strTemp)   { 
    189                         $ret["comment"] ? ($str .= "# '".$escalation["esc_name"]."' service (group) escalation definition ".$i."\n") : NULL; 
    190                         if ($ret["comment"] && $escalation["esc_comment"])      { 
    191                                 $comment = array(); 
    192                                 $comment = explode("\n", $escalation["esc_comment"]); 
    193                                 foreach ($comment as $cmt) 
    194                                         $str .= "# ".$cmt."\n"; 
    195                         } 
    196                         $str .= "define serviceescalation{\n"; 
    197                         $str .= print_line("servicegroup_name", $strTemp);                       
    198                         $cg = array(); 
    199                         $strTemp = NULL; 
    200                         $DBRESULT2 =& $pearDB->query("SELECT DISTINCT cg.cg_id, cg.cg_name FROM escalation_contactgroup_relation ecgr, contactgroup cg WHERE ecgr.escalation_esc_id = '".$escalation["esc_id"]."' AND ecgr.contactgroup_cg_id = cg.cg_id ORDER BY cg.cg_name"); 
    201                         if (PEAR::isError($DBRESULT2)) 
    202                                 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
    203                         while($cg =& $DBRESULT2->fetchRow())    { 
    204                                 $BP = false;                             
    205                                 array_key_exists($cg["cg_id"], $gbArr[1]) ? $BP = true : $BP = false; 
    206                                  
    207                                 if ($BP) 
    208                                         $strTemp != NULL ? $strTemp .= ", ".$cg["cg_name"] : $strTemp = $cg["cg_name"]; 
    209                         } 
    210                         $DBRESULT2->free(); 
    211                         if ($strTemp) $str .= print_line("contact_groups", $strTemp);                    
    212                         if ($escalation["first_notification"] != NULL) $str .= print_line("first_notification", $escalation["first_notification"]); 
    213                         if ($escalation["last_notification"] != NULL) $str .= print_line("last_notification", $escalation["last_notification"]); 
    214                         if ($escalation["notification_interval"] != NULL) $str .= print_line("notification_interval", $escalation["notification_interval"]); 
    215                         // Nagios 2 & 3 
    216                         if ($oreon->user->get_version() >= 2)   { 
    217                                 $DBRESULT2 =& $pearDB->query("SELECT tp_name FROM timeperiod WHERE tp_id = '".$escalation["escalation_period"]."'"); 
    218                                 if (PEAR::isError($DBRESULT2)) 
    219                                         print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
    220                                 $tp =& $DBRESULT2->fetchRow();                           
    221                                 if ($tp["tp_name"]) $str .= print_line("escalation_period", $tp["tp_name"]); 
    222                                 if ($escalation["escalation_options2"]) $str .= print_line("escalation_options", $escalation["escalation_options2"]); 
    223                         } 
    224                         $str .= "}\n\n"; 
    225                         $i++; 
    226                 } 
    227         } 
    228         unset($escalation); 
    229         $DBRESULT->free();       
    230          
    231         $DBRESULT =& $pearDB->query("SELECT DISTINCT service.service_activate, service.service_description, esr.service_service_id FROM service, escalation_service_relation esr WHERE esr.service_service_id = service.service_id ORDER BY esr.service_service_id"); 
    232         if (PEAR::isError($DBRESULT)) 
    233                 print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; 
    234310        $generated = 0; 
    235         while($service =& $DBRESULT->fetchRow())        { 
     311        while($service =& $DBRESULT->fetchRow()) { 
    236312                $BP = false;             
    237313                array_key_exists($service["service_service_id"], $gbArr[4]) ? $BP = true : NULL; 
    238314                 
    239                 if ($BP)        { 
     315                if($BP) { 
    240316                        $DBRESULT2 =& $pearDB->query("SELECT * FROM escalation esc, escalation_service_relation esr WHERE esr.service_service_id = '".$service["service_service_id"]."' AND esc.esc_id = esr.escalation_esc_id ORDER BY esc.esc_name"); 
    241                         if (PEAR::isError($DBRESULT2)) 
    242                                 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     317                        if (PEAR::isError($DBRESULT2)) { 
     318                                print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 
     319                        } 
     320                         
    243321                        $escalation = array(); 
    244                         while($escalation =& $DBRESULT2->fetchRow())    { 
     322                        while($escalation =& $DBRESULT2->fetchRow()) { 
    245323                                $host = array(); 
    246324                                $BP = false; 
     
    249327                                 
    250328                                $service["service_description"] = str_replace('#S#', "/", $service["service_description"]); 
    251                                 $service["service_description"] = str_replace('#BS#', "\\", $service["service_description"]);                            
    252                                 if ($BP)        { 
     329                                $service["service_description"] = str_replace('#BS#', "\\", $service["service_description"]); 
     330                                                                 
     331                                if($BP) { 
    253332                                        $ret["comment"] ? ($strDef .= "# '".$escalation["esc_name"]."' service escalation definition ".$i."\n") : NULL; 
    254                                         if ($ret["comment"] && $escalation["esc_comment"])      { 
     333                                         
     334                                        if(isset($ret["comment"]) == true && isset($escalation["esc_comment"]) == true) { 
    255335                                                $comment = array(); 
    256336                                                $comment = explode("\n", $escalation["esc_comment"]); 
    257                                                 foreach ($comment as $cmt) 
     337                                                 
     338                                                foreach ($comment as $cmt) { 
    258339                                                        $strDef .= "# ".$cmt."\n"; 
     340                                                } 
    259341                                        } 
     342                                         
    260343                                        $strDef .= "define serviceescalation{\n";                        
    261344                                        $strDef .= print_line("host_name", getMyHostName($escalation["host_host_id"]));                                                                          
     
    263346                                                $generated++; 
    264347                                        } 
     348                                         
    265349                                        $strDef .= print_line("service_description", $service["service_description"]); 
    266350                                        $cg = array(); 
    267351                                        $strTemp = NULL; 
     352                                         
    268353                                        $DBRESULT3 =& $pearDB->query("SELECT DISTINCT cg.cg_id, cg.cg_name FROM escalation_contactgroup_relation ecgr, contactgroup cg WHERE ecgr.escalation_esc_id = '".$escalation["esc_id"]."' AND ecgr.contactgroup_cg_id = cg.cg_id ORDER BY cg.cg_name"); 
    269         &nb