| 69 | | $DBRESULT =& $pearDB->query("SELECT `rrdtool_path_bin` FROM `general_opt`"); |
| 70 | | if (PEAR::isError($DBRESULT)) |
| 71 | | print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; |
| 72 | | $options =& $DBRESULT->fetchRow(); |
| 73 | | $rrdtoolPath = $options["rrdtool_path_bin"]; |
| 74 | | unset($options); |
| 75 | | $DBRESULT->free(); |
| 76 | | |
| 77 | | $title = array( |
| 78 | | "active_host_check" => _("Host checks"), |
| 79 | | "active_host_last" => _("Active hosts"), |
| 80 | | "host_latency" => _("Host check latency"), |
| 81 | | "active_service_check" => _("Service checks"), |
| 82 | | "active_service_last" => _("Active services"), |
| 83 | | "service_latency" => _("Service check latency"), |
| 84 | | "cmd_buffer" => _("Commands in buffer"), |
| 85 | | "host_states" => _("Host status"), |
| 86 | | "service_states" => _("Services status")); |
| 87 | | |
| 88 | | $options = array( |
| 89 | | "active_host_check" => "nagios_active_host_execution.rrd", |
| 90 | | "active_host_last" => "nagios_active_host_last.rrd", |
| 91 | | "host_latency" => "nagios_active_host_latency.rrd", |
| 92 | | "active_service_check" => "nagios_active_service_execution.rrd", |
| 93 | | "active_service_last" => "nagios_active_service_last.rrd", |
| 94 | | "service_latency" => "nagios_active_service_latency.rrd", |
| 95 | | "cmd_buffer" => "nagios_cmd_buffer.rrd", |
| 96 | | "host_states" => "nagios_hosts_states.rrd", |
| 97 | | "service_states" => "nagios_services_states.rrd"); |
| 98 | | |
| 99 | | $differentStats = array( |
| 100 | | "nagios_active_host_execution.rrd" => array("Used", "High", "Total"), |
| 101 | | "nagios_active_host_last.rrd" => array("T1", "T5", "T15", "T60"), |
| 102 | | "nagios_active_host_latency.rrd" => array("Used", "High", "Total"), |
| 103 | | "nagios_active_service_execution.rrd" => array("Used", "High", "Total"), |
| 104 | | "nagios_active_service_last.rrd" => array("T1", "T5", "T15", "T60"), |
| 105 | | "nagios_active_service_latency.rrd" => array("Used", "High", "Total"), |
| 106 | | "nagios_cmd_buffer.rrd" => array("Used", "High", "Total"), |
| 107 | | "nagios_hosts_states.rrd" => array("Up", "Down", "Unreach"), |
| 108 | | "nagios_services_states.rrd" => array("Ok", "Warn", "Crit", "Unk")); |
| 109 | | |
| 110 | | |
| 111 | | /* |
| 112 | | * Verify if start and end date |
| 113 | | */ |
| 114 | | |
| 115 | | if (!isset($_GET["start"])) { |
| 116 | | $start = time() - (60*60*24); |
| 117 | | } else { |
| 118 | | switch ($_GET["start"]) { |
| 119 | | case "today" : |
| 120 | | $start = time() - (60*60*24); |
| 121 | | break; |
| 122 | | case "yesterday" : |
| 123 | | $start = time() - (60*60*48); |
| 124 | | break; |
| 125 | | case "last4days" : |
| 126 | | $start = time() - (60*60*96); |
| 127 | | break; |
| 128 | | case "lastweek" : |
| 129 | | $start = time() - (60*60*168); |
| 130 | | break; |
| 131 | | case "lastmonth" : |
| 132 | | $start = time() - (60*60*24*30); |
| 133 | | break; |
| 134 | | case "last6month" : |
| 135 | | $start = time() - (60*60*24*30*6); |
| 136 | | break; |
| 137 | | case "lastyear" : |
| 138 | | $start = time() - (60*60*24*30*12); |
| 139 | | break; |
| 140 | | } |
| 141 | | } |
| 142 | | |
| 143 | | /* |
| 144 | | * Get end values |
| 145 | | */ |
| 146 | | if (!isset($_GET["end"])) |
| 147 | | $end = time(); |
| 148 | | else |
| 149 | | $end = $_GET["end"]; |
| 150 | | |
| 151 | | /* |
| 152 | | * Begin Command Line |
| 153 | | */ |
| 154 | | $command_line = " graph - --start=".$start." --end=".$end; |
| 155 | | |
| 156 | | /* |
| 157 | | * get all template infos |
| 158 | | */ |
| | 73 | $session =& $pearDB->query("SELECT * FROM `session` WHERE session_id = '".$_GET["session_id"]."'"); |
| | 74 | if (!$session->numRows()){ |
| | 75 | ; |
| | 76 | } else { |
| 160 | | $command_line .= " --interlaced --imgformat PNG --width=400 --height=100 --title='".$title[$_GET["key"]]."' --vertical-label='".$_GET["key"]."' --slope-mode "; |
| 161 | | $command_line .= "--rigid --alt-autoscale-max "; |
| | 78 | /* |
| | 79 | * Get GMT for current user |
| | 80 | */ |
| | 81 | $gmt = $CentreonGMT->getMyGMTFromSession($_GET["session_id"]); |
| | 82 | |
| | 83 | $DBRESULT =& $pearDB->query("SELECT `rrdtool_path_bin` FROM `general_opt`"); |
| | 84 | if (PEAR::isError($DBRESULT)) |
| | 85 | print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; |
| | 86 | $options =& $DBRESULT->fetchRow(); |
| | 87 | $rrdtoolPath = $options["rrdtool_path_bin"]; |
| | 88 | unset($options); |
| | 89 | $DBRESULT->free(); |
| | 90 | |
| | 91 | $title = array( |
| | 92 | "active_host_check" => _("Host checks"), |
| | 93 | "active_host_last" => _("Active hosts"), |
| | 94 | "host_latency" => _("Host check latency"), |
| | 95 | "active_service_check" => _("Service checks"), |
| | 96 | "active_service_last" => _("Active services"), |
| | 97 | "service_latency" => _("Service check latency"), |
| | 98 | "cmd_buffer" => _("Commands in buffer"), |
| | 99 | "host_states" => _("Host status"), |
| | 100 | "service_states" => _("Services status")); |
| | 101 | |
| | 102 | $options = array( |
| | 103 | "active_host_check" => "nagios_active_host_execution.rrd", |
| | 104 | "active_host_last" => "nagios_active_host_last.rrd", |
| | 105 | "host_latency" => "nagios_active_host_latency.rrd", |
| | 106 | "active_service_check" => "nagios_active_service_execution.rrd", |
| | 107 | "active_service_last" => "nagios_active_service_last.rrd", |
| | 108 | "service_latency" => "nagios_active_service_latency.rrd", |
| | 109 | "cmd_buffer" => "nagios_cmd_buffer.rrd", |
| | 110 | "host_states" => "nagios_hosts_states.rrd", |
| | 111 | "service_states" => "nagios_services_states.rrd"); |
| | 112 | |
| | 113 | $differentStats = array( |
| | 114 | "nagios_active_host_execution.rrd" => array("Used", "High", "Total"), |
| | 115 | "nagios_active_host_last.rrd" => array("T1", "T5", "T15", "T60"), |
| | 116 | "nagios_active_host_latency.rrd" => array("Used", "High", "Total"), |
| | 117 | "nagios_active_service_execution.rrd" => array("Used", "High", "Total"), |
| | 118 | "nagios_active_service_last.rrd" => array("T1", "T5", "T15", "T60"), |
| | 119 | "nagios_active_service_latency.rrd" => array("Used", "High", "Total"), |
| | 120 | "nagios_cmd_buffer.rrd" => array("Used", "High", "Total"), |
| | 121 | "nagios_hosts_states.rrd" => array("Up", "Down", "Unreach"), |
| | 122 | "nagios_services_states.rrd" => array("Ok", "Warn", "Crit", "Unk")); |
| | 123 | |
| | 124 | |
| | 125 | /* |
| | 126 | * Verify if start and end date |
| | 127 | */ |
| | 128 | |
| | 129 | if (!isset($_GET["start"])) { |
| | 130 | $start = time() - (60*60*24); |
| | 131 | } else { |
| | 132 | switch ($_GET["start"]) { |
| | 133 | case "today" : |
| | 134 | $start = time() - (60*60*24); |
| | 135 | break; |
| | 136 | case "yesterday" : |
| | 137 | $start = time() - (60*60*48); |
| | 138 | break; |
| | 139 | case "last4days" : |
| | 140 | $start = time() - (60*60*96); |
| | 141 | break; |
| | 142 | case "lastweek" : |
| | 143 | $start = time() - (60*60*168); |
| | 144 | break; |
| | 145 | case "lastmonth" : |
| | 146 | $start = time() - (60*60*24*30); |
| | 147 | break; |
| | 148 | case "last6month" : |
| | 149 | $start = time() - (60*60*24*30*6); |
| | 150 | break; |
| | 151 | case "lastyear" : |
| | 152 | $start = time() - (60*60*24*30*12); |
| | 153 | break; |
| | 154 | } |
| | 155 | } |
| | 156 | |
| | 157 | /* |
| | 158 | * Get end values |
| | 159 | */ |
| | 160 | if (!isset($_GET["end"])) |
| | 161 | $end = time(); |
| | 162 | else |
| | 163 | $end = $_GET["end"]; |
| 163 | | /* |
| 164 | | * Init DS template For each curv |
| 165 | | */ |
| 166 | | |
| 167 | | $colors = array("1"=>"#19EE11", "2"=>"#82CFD8", "3"=>"#F8C706", "4"=>"#F8C706"); |
| 168 | | |
| 169 | | $metrics = $differentStats[$options[$_GET["key"]]]; |
| 170 | | $cpt = 1; |
| 171 | | $DBRESULT =& $pearDBO->query("SELECT RRDdatabase_nagios_stats_path FROM config"); |
| 172 | | if (PEAR::isError($DBRESULT)) |
| 173 | | print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; |
| 174 | | while ($nagios_stats =& $DBRESULT->fetchRow()) |
| | 165 | /* |
| | 166 | * Begin Command Line |
| | 167 | */ |
| | 168 | $command_line = " graph - --start=".$start." --end=".$end; |
| | 169 | |
| | 170 | /* |
| | 171 | * get all template infos |
| | 172 | */ |
| | 173 | |
| | 174 | $command_line .= " --interlaced --imgformat PNG --width=400 --height=100 --title='".$title[$_GET["key"]]."' --vertical-label='".$_GET["key"]."' --slope-mode --rigid --alt-autoscale-max "; |
| | 175 | |
| | 176 | /* |
| | 177 | * Init DS template For each curv |
| | 178 | */ |
| | 179 | |
| | 180 | $colors = array("1"=>"#19EE11", "2"=>"#82CFD8", "3"=>"#F8C706", "4"=>"#F8C706"); |
| | 181 | |
| | 182 | $metrics = $differentStats[$options[$_GET["key"]]]; |
| | 183 | $cpt = 1; |
| | 184 | $DBRESULT =& $pearDBO->query("SELECT RRDdatabase_nagios_stats_path FROM config"); |
| | 185 | if (PEAR::isError($DBRESULT)) |
| | 186 | print "DB Error : ".$DBRESULT->getDebugInfo()."<br />"; |
| | 187 | $nagios_stats =& $DBRESULT->fetchRow(); |
| 176 | | |
| 177 | | foreach ($metrics as $key => $value){ |
| 178 | | $command_line .= " DEF:v".$cpt."=".$nagios_stats_path."perfmon-".$_GET["ns_id"]."/".$options[$_GET["key"]].":".$value.":AVERAGE "; |
| 179 | | $cpt++; |
| 180 | | } |
| 181 | | $command_line .= " COMMENT:\" \\l\" "; |
| 182 | | |
| 183 | | /* |
| 184 | | * Create Legende |
| 185 | | */ |
| 186 | | $cpt = 1; |
| 187 | | |
| 188 | | foreach ($metrics as $key => $tm){ |
| 189 | | $command_line .= " LINE1:v".($cpt); |
| 190 | | $command_line .= $colors[$cpt].":\""; |
| 191 | | $command_line .= $tm."\""; |
| 192 | | $cpt++; |
| 193 | | } |
| 194 | | |
| 195 | | $command_line = "$rrdtoolPath ".$command_line." 2>&1"; |
| 196 | | $command_line = escape_command("$command_line"); |
| 197 | | |
| 198 | | //print $command_line; |
| 199 | | $fp = popen($command_line , 'r'); |
| 200 | | if (isset($fp) && $fp ) { |
| 201 | | $str =''; |
| 202 | | while (!feof ($fp)) { |
| 203 | | $buffer = fgets($fp, 4096); |
| 204 | | $str = $str . $buffer ; |
| 205 | | } |
| 206 | | print $str; |
| | 189 | |
| | 190 | foreach ($metrics as $key => $value){ |
| | 191 | $command_line .= " DEF:v".$cpt."=".$nagios_stats_path."perfmon-".$_GET["ns_id"]."/".$options[$_GET["key"]].":".$value.":AVERAGE "; |
| | 192 | $cpt++; |
| | 193 | } |
| | 194 | |
| | 195 | /* |
| | 196 | * Add comment start and end time inf graph footer. |
| | 197 | */ |
| | 198 | $rrd_time = addslashes($CentreonGMT->getDate("Y\/m\/d G:i", $start, $gmt)); |
| | 199 | $rrd_time = str_replace(":", "\:", $rrd_time); |
| | 200 | $rrd_time2 = addslashes($CentreonGMT->getDate("Y\/m\/d G:i", $end, $gmt)) ; |
| | 201 | $rrd_time2 = str_replace(":", "\:", $rrd_time2); |
| | 202 | $command_line .= " COMMENT:\" From $rrd_time to $rrd_time2 \\c\" "; |
| | 203 | |
| | 204 | /* |
| | 205 | * Create Legende |
| | 206 | */ |
| | 207 | $cpt = 1; |
| | 208 | |
| | 209 | foreach ($metrics as $key => $tm){ |
| | 210 | $command_line .= " LINE1:v".($cpt); |
| | 211 | $command_line .= $colors[$cpt].":\""; |
| | 212 | $command_line .= $tm."\""; |
| | 213 | $cpt++; |
| | 214 | } |
| | 215 | |
| | 216 | $command_line = "$rrdtoolPath ".$command_line." 2>&1"; |
| | 217 | |
| | 218 | /* |
| | 219 | * Add Timezone for current user. |
| | 220 | */ |
| | 221 | |
| | 222 | $command_line = "export TZ='CMT-6' ; ".$command_line; |
| | 223 | |
| | 224 | $command_line = escape_command("$command_line"); |
| | 225 | /* |
| | 226 | * Debug |
| | 227 | */ |
| | 228 | //print $command_line; |
| | 229 | $fp = popen($command_line , 'r'); |
| | 230 | if (isset($fp) && $fp ) { |
| | 231 | $str =''; |
| | 232 | while (!feof ($fp)) { |
| | 233 | $buffer = fgets($fp, 4096); |
| | 234 | $str = $str . $buffer ; |
| | 235 | } |
| | 236 | print $str; |
| | 237 | } |