Changeset 6718
- Timestamp:
- 10/03/08 20:01:10 (2 months ago)
- Location:
- trunk/centreon/www/include/configuration/configGenerate
- Files:
-
- 6 modified
-
DB-Func.php (modified) (2 diffs)
-
formGenerateFiles.php (modified) (3 diffs)
-
genHosts.php (modified) (3 diffs)
-
genServices.php (modified) (6 diffs)
-
genTimeperiods.php (modified) (1 diff)
-
generateFiles.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/centreon/www/include/configuration/configGenerate/DB-Func.php
r6700 r6718 15 15 * For information : contact@centreon.com 16 16 */ 17 17 18 /* 19 * Get Contact Group 20 */ 21 22 23 /* 24 * Get contact List 25 */ 26 27 28 /* 29 * Convert Service Spécial Char for generation 30 */ 31 32 function convertServiceSpecialChar($str) { 33 $str = str_replace('#S#', "/", $str); 34 $str = str_replace('#BS#', "\\", $str); 35 return $str; 36 } 37 38 /* 39 * Purge Args for commands 40 */ 41 42 function convertServiceSpecialCharInCmd($str) { 43 $str = str_replace('#BR#', "\\n", $str); 44 $str = str_replace('#T#', "\\t", $str); 45 $str = str_replace('#R#', "\\r", $str); 46 $str = str_replace('#S#', "/", $str); 47 $str = str_replace('#BS#', "\\", $str); 48 return $str; 49 } 18 50 /* 19 51 * Compute values for time range … … 61 93 function isHostOnThisInstance($host_id, $instance_id){ 62 94 global $pearDB; 63 64 95 $DBRESULT_relation =& $pearDB->query("SELECT * FROM ns_host_relation WHERE host_host_id = '".$host_id."' AND nagios_server_id = '".$instance_id."'"); 65 96 if (PEAR::isError($DBRESULT_relation)) -
trunk/centreon/www/include/configuration/configGenerate/formGenerateFiles.php
r6699 r6718 38 38 */ 39 39 if ($n > 1) 40 $tab_nagios_server = array( NULL=> "");40 $tab_nagios_server = array(-1 => ""); 41 41 /* 42 42 * Display all servers list … … 102 102 103 103 if (isset($ret["gen"]) && $ret["gen"] && ($ret["host"] == 0 || $ret["host"])){ 104 /* 105 * Get commands 106 */ 107 $commands = array(); 108 $DBRESULT2 =& $pearDB->query("SELECT command_id, command_name FROM command"); 109 if (PEAR::isError($DBRESULT2)) 110 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 111 while ($command = $DBRESULT2->fetchRow()) 112 $commands[$command["command_id"]] = $command["command_name"] ; 113 $DBRESULT2->free(); 114 115 /* 116 * Get timeperiods 117 */ 118 $timeperiods = array(); 119 $DBRESULT2 =& $pearDB->query("SELECT tp_name, tp_id FROM timeperiod"); 120 if (PEAR::isError($DBRESULT2)) 121 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 122 while ($timeperiod =& $DBRESULT2->fetchRow()) 123 $timeperiods[$timeperiod["tp_id"]] = $timeperiod["tp_name"]; 124 $DBRESULT2->free(); 125 104 126 /* 105 127 * Check dependancies … … 110 132 print "DB Error : ".$DBRESULT_Servers->getDebugInfo()."<br />"; 111 133 while ($tab =& $DBRESULT_Servers->fetchRow()){ 112 if (isset($ret["host"]) && $ret["host"] == 0 || $ret["host"] == $tab['id']){ 134 if (isset($ret["host"]) && ($ret["host"] == 0 || $ret["host"] == $tab['id'])) { 135 /* 136 * Check temporary files access 137 */ 138 if (!is_dir($nagiosCFGPath.$tab['id']."/")) 139 mkdir($nagiosCFGPath.$tab['id']."/"); 140 141 print "<br>=================== Generation de ".$tab['id']."==================<br>"; 142 113 143 unset($DBRESULT2); 114 144 require $path."genCGICFG.php"; -
trunk/centreon/www/include/configuration/configGenerate/genHosts.php
r6668 r6718 18 18 if (!isset($oreon)) 19 19 exit(); 20 21 if (!is_dir($nagiosCFGPath.$tab['id']."/")) { 22 mkdir($nagiosCFGPath.$tab['id']."/"); 23 } 24 25 /* 26 * Get commands 27 */ 28 $commands = array(); 29 $DBRESULT2 =& $pearDB->query("SELECT command_id, command_name FROM command"); 30 if (PEAR::isError($DBRESULT2)) 31 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 32 while ($command = $DBRESULT2->fetchRow()) 33 $commands[$command["command_id"]] = $command["command_name"] ; 34 $DBRESULT2->free(); 35 36 /* 37 * Get timeperiods 38 */ 39 $timeperiods = array(); 40 $DBRESULT2 =& $pearDB->query("SELECT tp_name, tp_id FROM timeperiod"); 41 if (PEAR::isError($DBRESULT2)) 42 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 43 while ($timeperiod =& $DBRESULT2->fetchRow()) 44 $timeperiods[$timeperiod["tp_id"]] = $timeperiod["tp_name"]; 45 $DBRESULT2->free(); 46 20 47 21 /* 48 22 * Get Host List … … 202 176 $host["timeperiod_tp_id"] = getMyHostField($host["host_id"], "timeperiod_tp_id"); 203 177 if ($host["timeperiod_tp_id"]) 204 $str .= print_line("check_period", $timeperiods[$host["timeperiod_tp_id"]]. "_GMT".$host["host_location"]);178 $str .= print_line("check_period", $timeperiods[$host["timeperiod_tp_id"]].($oreon->CentreonGMT->used() == 1 ? "_GMT".$host["host_location"] : "")); 205 179 206 180 if ($host["host_obsess_over_host"] != 2) … … 282 256 $host["timeperiod_tp_id2"] = getMyHostField($host["host_id"], "timeperiod_tp_id2"); 283 257 if ($host["timeperiod_tp_id2"]) 284 $str .= print_line("notification_period", $timeperiods[$host["timeperiod_tp_id2"]]. "_GMT".$host["host_location"]);285 258 $str .= print_line("notification_period", $timeperiods[$host["timeperiod_tp_id2"]].($oreon->CentreonGMT->used() == 1 ? "_GMT".$host["host_location"] : "")); 259 286 260 if ($host["host_notification_options"]) 287 261 $str .= print_line("notification_options", $host["host_notification_options"]); -
trunk/centreon/www/include/configuration/configGenerate/genServices.php
r6646 r6718 19 19 exit(); 20 20 21 if (!is_dir($nagiosCFGPath.$tab['id']."/")) {22 mkdir($nagiosCFGPath.$tab['id']."/");23 }21 /* 22 * Create file 23 */ 24 24 25 25 $handle = create_file($nagiosCFGPath.$tab['id']."/services.cfg", $oreon->user->get_name()); 26 $DBRESULT =& $pearDB->query("SELECT * FROM service WHERE `service_activate` = '1' ORDER BY `service_register`, `service_description`"); 26 27 /* 28 * Get Service List 29 */ 30 $DBRESULT =& $pearDB->query("SELECT * FROM `service` WHERE `service_activate` = '1' ORDER BY `service_register`, `service_description`"); 27 31 if (PEAR::isError($DBRESULT)) 28 32 print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; … … 30 34 $i = 1; 31 35 $str = NULL; 32 while ($service =& $DBRESULT->fetchRow()) {36 while ($service =& $DBRESULT->fetchRow()) { 33 37 $BP = false; 34 38 $LinkedToHost = 0; … … 37 41 isset($gbArr[4][$service["service_id"]]) ? $BP = true : NULL; 38 42 39 $service["service_description"] = str_replace('#S#', "/", $service["service_description"]); 40 $service["service_description"] = str_replace('#BS#', "\\", $service["service_description"]); 41 $service["service_alias"] = str_replace('#S#', "/", $service["service_alias"]); 42 $service["service_alias"] = str_replace('#BS#', "\\", $service["service_alias"]); 43 if ($BP) { 43 /* 44 * Convert spécial char 45 */ 46 $service["service_description"] = convertServiceSpecialChar($service["service_description"]); 47 $service["service_alias"] = convertServiceSpecialChar($service["service_alias"]); 48 49 // print "---".$service["service_description"]." - ".$service["service_id"]."---<br>\n"; 50 51 if ($BP) { 52 44 53 /* 45 * Can merge multiple Host or HostGroup Definition 54 * Check GMT compatibility 55 * 46 56 */ 47 $strTMP = NULL; 48 $parent = false; 49 $ret["comment"] ? ($strTMP .= "# '" . $service["service_description"] . "' service definition " . $i . "\n") : NULL; 50 if ($ret["comment"] && $service["service_comment"]) { 51 $comment = array(); 52 $comment = explode("\n", $service["service_comment"]); 53 foreach ($comment as $cmt) 54 $strTMP .= "# ".$cmt."\n"; 55 } 56 $strTMP .= "define service{\n"; 57 if ($service["service_register"]) { 58 /* 59 * HostGroup Relation 60 */ 61 $hostGroup = array(); 62 $strTMPTemp = NULL; 63 $DBRESULT2 =& $pearDB->query("SELECT hg.hg_id, hg.hg_name FROM host_service_relation hsr, hostgroup hg WHERE hsr.service_service_id ='".$service["service_id"]."' AND hsr.hostgroup_hg_id = hg.hg_id"); 64 if (PEAR::isError($DBRESULT2)) 65 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 66 while ($hostGroup =& $DBRESULT2->fetchRow()) { 67 $BP = false; 68 if (isset($generatedHG[$hostGroup["hg_id"]]) && $generatedHG[$hostGroup["hg_id"]]){ 69 $parent = true; 70 $strTMPTemp != NULL ? $strTMPTemp .= ", ".$hostGroup["hg_name"] : $strTMPTemp = $hostGroup["hg_name"]; 71 $LinkedToHost++; 57 58 if ($oreon->CentreonGMT->used() == 1 && $service["service_register"] == 1) { 59 60 /* 61 * List of HostGroups to be checked 62 */ 63 64 $hostGroups = array(); 65 66 /* 67 * HostGroup Relation 68 */ 69 $DBRESULT2 =& $pearDB->query( "SELECT hg.hg_id, hg.hg_name " . 70 "FROM host_service_relation hsr, hostgroup hg " . 71 "WHERE hsr.service_service_id ='".$service["service_id"]."' " . 72 "AND hsr.hostgroup_hg_id = hg.hg_id"); 73 if (PEAR::isError($DBRESULT2)) 74 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 75 while ($hostGroup =& $DBRESULT2->fetchRow()) { 76 if (isset($generatedHG[$hostGroup["hg_id"]]) && $generatedHG[$hostGroup["hg_id"]]){ 77 $hostGroups[$hostGroup["hg_id"]] = $hostGroup["hg_name"]; 78 $LinkedToHost++; 79 } 80 unset($hostGroup); 72 81 } 73 } 74 $DBRESULT2->free(); 75 if ($strTMPTemp) 76 $strTMP .= print_line("hostgroup_name", $strTMPTemp); 77 unset($hostGroup); 78 unset($strTMPTemp); 79 80 if (!$parent) { 82 $DBRESULT2->free(); 83 81 84 /* 82 * Host Relation85 * Hosts Relations 83 86 */ 84 $host = array(); 85 $strTMPTemp = NULL; 86 $DBRESULT2 =& $pearDB->query("SELECT host.host_id, host.host_name FROM host_service_relation hsr, host WHERE hsr.service_service_id ='".$service["service_id"]."' AND hsr.host_host_id = host.host_id"); 87 $hosts = array(); 88 $DBRESULT2 =& $pearDB->query( "SELECT host.host_id, host_location, host.host_name " . 89 "FROM host_service_relation hsr, host " . 90 "WHERE hsr.service_service_id ='".$service["service_id"]."' " . 91 "AND hsr.host_host_id = host.host_id"); 87 92 if (PEAR::isError($DBRESULT2)) 88 93 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 89 94 while ($host =& $DBRESULT2->fetchRow()) { 90 $BP = false; 91 isset($gbArr[2][$host["host_id"]]) ? $BP = true : NULL; 92 93 if ($BP) { 94 $parent = true; 95 if (isHostOnThisInstance($host["host_id"], $tab['id'])){ 96 $strTMPTemp != NULL ? $strTMPTemp .= ", ".$host["host_name"] : $strTMPTemp = $host["host_name"]; 95 if (isset($gbArr[2][$host["host_id"]])) { 96 if (isHostOnThisInstance($host["host_id"], $tab['id'])) { 97 $parent = true; 98 if (!isset($hosts[$host["host_location"]])) 99 $hosts[$host["host_location"]] = array(); 100 $hosts[$host["host_location"]][$host["host_id"]] = $host["host_name"]; 97 101 $LinkedToHost++; 98 102 } … … 100 104 } 101 105 $DBRESULT2->free(); 102 if ($strTMPTemp) $strTMP .= print_line("host_name", $strTMPTemp);103 106 unset($host); 104 } 105 unset($strTMPTemp); 106 } 107 if (!$service["service_register"] && $service["service_description"]) { 108 $strTMP .= print_line("name", $service["service_description"]); 109 $strTMP .= print_line("service_description", $service["service_alias"]); 110 } else if ($service["service_description"]) 111 $strTMP .= print_line("service_description", $service["service_description"]); 112 # Template Model Relation 113 if ($service["service_template_model_stm_id"]) { 114 $serviceTemplate = array(); 115 $DBRESULT2 =& $pearDB->query("SELECT service.service_description FROM service WHERE service.service_id = '".$service["service_template_model_stm_id"]."' LIMIT 1"); 116 if (PEAR::isError($DBRESULT2)) 117 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 118 while($serviceTemplate =& $DBRESULT2->fetchRow()) { 119 $serviceTemplate["service_description"] = str_replace('#S#', "/", $serviceTemplate["service_description"]); 120 $serviceTemplate["service_description"] = str_replace('#BS#', "\\", $serviceTemplate["service_description"]); 121 $strTMP .= print_line("use", $serviceTemplate["service_description"]); 122 } 123 $DBRESULT2->free(); 124 unset($serviceTemplate); 125 } 126 # Nagios V2 && V3: Servicegroups relation 127 if ($oreon->user->get_version() >= 2) { 107 108 $strTMPTemp = ""; 109 if (count($hosts) || count($hostGroups)) { 110 /* 111 * Emulate HG GTM management 112 */ 113 if (count($hostGroups)) { 114 foreach ($hostGroups as $hg_id => $hg_name){ 115 $hostList = getMyHostGroupHosts($hg_id); 116 foreach ($hostList as $host_id){ 117 $host_location = getMyHostFieldOnHost($host_id, "host_location"); 118 if (!isset($hosts[$host_location])) 119 $hosts[$host_location] = array(); 120 $hosts[$host_location][$host_id] = getMyHostField($host_id, "host_name"); 121 unset($host_location); 122 123 } 124 unset($hg_id); 125 unset($hg_name); 126 unset($hostList); 127 } 128 } 129 130 /* 131 * Generate by host 132 */ 133 if (count($hosts)) { 134 foreach ($hosts as $gmt => $host) { 135 $strTMP = NULL; 136 $parent = false; 137 $ret["comment"] ? ($strTMP .= "# '" . $service["service_description"] . "' service definition " . $i . "\n") : NULL; 138 if ($ret["comment"] && $service["service_comment"]) { 139 $comment = array(); 140 $comment = explode("\n", $service["service_comment"]); 141 foreach ($comment as $cmt) 142 $strTMP .= "# ".$cmt."\n"; 143 } 144 $strTMP .= "define service{\n"; 145 146 /* 147 * Host List 148 */ 149 $strTMPHost = ""; 150 foreach ($host as $host_id => $hostList){ 151 if ($strTMPHost != "") 152 $strTMPHost .= ","; 153 $strTMPHost .= $hostList; 154 } 155 156 $strTMP .= print_line("host_name", $strTMPHost); 157 unset($strTMPHost); 158 159 $strTMP .= print_line("service_description", $service["service_description"]); 160 161 /* 162 * Template Model Relation 163 */ 164 if ($service["service_template_model_stm_id"]) { 165 $serviceTemplate = array(); 166 $DBRESULT2 =& $pearDB->query("SELECT service.service_description FROM service WHERE service.service_id = '".$service["service_template_model_stm_id"]."' LIMIT 1"); 167 if (PEAR::isError($DBRESULT2)) 168 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 169 while ($serviceTemplate =& $DBRESULT2->fetchRow()) 170 $strTMP .= print_line("use", convertServiceSpecialChar($serviceTemplate["service_description"])); 171 $DBRESULT2->free(); 172 unset($serviceTemplate); 173 } 174 175 176 $serviceGroup = array(); 177 $strTMPSG = NULL; 178 $DBRESULT2 =& $pearDB->query("SELECT DISTINCT sg.sg_id, sg.sg_name FROM servicegroup_relation sgr, servicegroup sg WHERE sgr.service_service_id = '".$service["service_id"]."' AND sgr.servicegroup_sg_id = sg.sg_id ORDER BY `sg_name`"); 179 if (PEAR::isError($DBRESULT2)) 180 print "DB Error : ".$DBRESULT2->getDebugInfo()."<br />"; 181 while ($serviceGroup =& $DBRESULT2->fetchRow()) { 182 if (isset($gbArr[5][$serviceGroup["sg_id"]])) 183 $strTMPSG != NULL ? $strTMPSG .= ", ".$serviceGroup["sg_name"] : $strTMPSG = $serviceGroup["sg_name"]; 184 } 185 $DBRESULT2->free(); 186 if ($strTMPSG) 187 $strTMP .= print_line("servicegroups", $strTMPSG); 188 unset($serviceGroup); 189 unset($strTMPSG); 190 191 if ($service["service_is_volatile"] != 2) 192 $strTMP .= print_line("is_volatile", $service["service_is_volatile"] == 1 ? "1": "0"); 193 194 /* 195 * Check Command 196 */ 197 $command = NULL; 198 $command = getMyCheckCmdParam($service["service_id"]); 199 if ($command) 200 $strTMP .= print_line("check_command", $command); 201 202 if ($service["service_max_check_attempts"] != NULL) 203 $strTMP .= print_line("max_check_attempts", $service["service_max_check_attempts"]); 204 if ($service["service_normal_check_interval"] != NULL) 205 $strTMP .= print_line("normal_check_interval", $service["service_normal_check_interval"]); 206 if ($se
