Changeset 6725

Show
Ignore:
Timestamp:
10/06/08 12:28:10 (2 months ago)
Author:
jmathis
Message:

activate GMT management for graphs RRDTools

Location:
trunk/centreon/www/include
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/centreon/www/include/nagiosStats/getStats.php

    r6646 r6725  
    5959        } 
    6060         
    61         require_once("@CENTREON_ETC@/centreon.conf.php"); 
    62         require_once("$centreon_path/www/DBconnect.php"); 
    63         require_once("$centreon_path/www/DBOdsConnect.php"); 
     61        //require_once("@CENTREON_ETC@/centreon.conf.php"); 
     62        require_once "/etc/centreon/centreon.conf.php"; 
     63        require_once "$centreon_path/www/class/centreonGMT.class.php"; 
     64        require_once "$centreon_path/www/DBconnect.php"; 
     65        require_once "$centreon_path/www/DBOdsConnect.php"; 
    6466 
     67        $CentreonGMT = new CentreonGMT(); 
     68         
    6569        /* 
    6670         * Get RRDTool binary Path  
    6771         */ 
    6872          
    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 { 
    15977          
    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"]; 
    162164                         
    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(); 
    175188                $nagios_stats_path = $nagios_stats['RRDdatabase_nagios_stats_path']; 
    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                } 
    207238        } 
    208239?> 
  • trunk/centreon/www/include/nagiosStats/nagiosStats.ihtml

    r6646 r6725  
    2929                        {foreach from=$options key=keyOptions item=itemOptions}                  
    3030                                {if $startPeriod} 
    31                                 <img src="./include/nagiosStats/getStats.php?ns_id={$key}&key={$keyOptions}&start={$startPeriod}"> 
     31                                <img src="./include/nagiosStats/getStats.php?ns_id={$key}&key={$keyOptions}&start={$startPeriod}&session_id={$session_id}"> 
    3232                                {else} 
    33                                 <img src="./include/nagiosStats/getStats.php?ns_id={$key}&key={$keyOptions}"> 
     33                                <img src="./include/nagiosStats/getStats.php?ns_id={$key}&key={$keyOptions}&session_id={$session_id}"> 
    3434                                {/if}            
    3535                        {assign var='counter' value=$counter+1} 
     
    4040</div> 
    4141{/foreach} 
    42 </form>          
     42</form> 
  • trunk/centreon/www/include/nagiosStats/nagiosStats.php

    r6646 r6725  
    104104        $tpl->assign("p", $p); 
    105105        $tpl->assign("options", $options); 
    106         $tpl->assign("session", session_id()); 
     106        $tpl->assign("session_id", session_id()); 
    107107        $tpl->display("nagiosStats.ihtml"); 
    108108?> 
  • trunk/centreon/www/include/views/graphs/graphODS/generateImages/generateODSImage.php

    r6646 r6725  
    1616 */ 
    1717  
    18         header('Content-Type: image/png'); 
     18        //header('Content-Type: image/png'); 
    1919         
    2020        function escape_command($command) { 
     
    2424        include("@CENTREON_ETC@/centreon.conf.php"); 
    2525         
    26         require_once ('DB.php'); 
    27         require_once ('./DB-Func.php'); 
    28         require_once ($centreon_path."www/class/Session.class.php"); 
    29         require_once ($centreon_path."www/class/Oreon.class.php"); 
     26        require_once 'DB.php'; 
     27        require_once './DB-Func.php'; 
     28        require_once $centreon_path."www/class/Session.class.php"; 
     29        require_once $centreon_path."www/class/Oreon.class.php"; 
     30        require_once "$centreon_path/www/class/centreonGMT.class.php"; 
    3031         
    3132        Session::start(); 
    3233        $oreon =& $_SESSION["oreon"]; 
     34         
     35        $CentreonGMT = new CentreonGMT(); 
    3336 
    3437        require_once $centreon_path."www/include/common/common-Func.php"; 
     
    7477                exit; 
    7578        } else { 
     79                 
     80                /* 
     81                 * Get GMT for current user 
     82                 */ 
     83                $gmt = $CentreonGMT->getMyGMTFromSession($_GET["session_id"]); 
     84         
    7685                /* 
    7786                 * Get Values 
     
    252261                 */ 
    253262                 
    254                 $rrd_time  = addslashes(date("Y\/m\/d G:i", $start)); 
     263                $rrd_time  = addslashes($CentreonGMT->getDate("Y\/m\/d G:i", $start)); 
    255264                $rrd_time = str_replace(":", "\:", $rrd_time); 
    256                 $rrd_time2 = addslashes(date("Y\/m\/d G:i", $end)) ; 
     265                $rrd_time2 = addslashes($CentreonGMT->getDate("Y\/m\/d G:i", $end)) ; 
    257266                $rrd_time2 = str_replace(":", "\:", $rrd_time2); 
    258267                $command_line .= " COMMENT:\" From $rrd_time to $rrd_time2 \\c\" "; 
  • trunk/centreon/www/include/views/graphs/graphODS/generateImages/generateODSImageZoom.php

    r6646 r6725  
    3232         
    3333        include("@CENTREON_ETC@/centreon.conf.php"); 
    34         require_once ('DB.php'); 
    35         require_once ('./DB-Func.php'); 
    36         require_once ($centreon_path."www/class/Session.class.php"); 
    37         require_once ($centreon_path."www/class/Oreon.class.php"); 
     34         
     35        require_once 'DB.php'; 
     36        require_once './DB-Func.php'; 
     37        require_once $centreon_path."www/class/Session.class.php"; 
     38        require_once $centreon_path."www/class/Oreon.class.php"; 
     39        require_once "$centreon_path/www/class/centreonGMT.class.php"; 
    3840         
    3941        Session::start(); 
    4042        $oreon =& $_SESSION["oreon"]; 
     43 
     44        $CentreonGMT = new CentreonGMT(); 
    4145 
    4246        require_once $centreon_path."www/include/common/common-Func.php"; 
     
    6670        } else { 
    6771                $session->free(); 
     72                 
     73                /* 
     74                 * Get GMT for current user 
     75                 */ 
     76                $gmt = $CentreonGMT->getMyGMTFromSession($_GET["session_id"]); 
     77                 
    6878                /* 
    6979                 * Connect to ods 
     
    228238                 */ 
    229239                 
    230                 $rrd_time  = addslashes(date("Y\/m\/d G:i", $_GET["start"])); 
     240                $rrd_time  = addslashes($CentreonGMT->getDate("Y\/m\/d G:i", $_GET["start"])); 
    231241                $rrd_time = str_replace(":", "\:", $rrd_time); 
    232                 $rrd_time2 = addslashes(date("Y\/m\/d G:i", $_GET["end"])) ; 
     242                $rrd_time2 = addslashes($CentreonGMT->getDate("Y\/m\/d G:i", $_GET["end"])) ; 
    233243                $rrd_time2 = str_replace(":", "\:", $rrd_time2); 
    234244                $command_line .= " COMMENT:\" From $rrd_time to $rrd_time2 \\c\" "; 
  • trunk/centreon/www/include/views/graphs/graphODS/generateImages/generateODSMetricImage.php

    r6646 r6725  
    2424        include("@CENTREON_ETC@/centreon.conf.php"); 
    2525         
    26         require_once ('DB.php'); 
    27         require_once ('./DB-Func.php'); 
    28         require_once ($centreon_path."www/class/Session.class.php"); 
    29         require_once ($centreon_path."www/class/Oreon.class.php"); 
     26        require_once 'DB.php'; 
     27        require_once './DB-Func.php'; 
     28        require_once $centreon_path."www/class/Session.class.php"; 
     29        require_once $centreon_path."www/class/Oreon.class.php"; 
     30        require_once "$centreon_path/www/class/centreonGMT.class.php"; 
    3031         
    3132        Session::start(); 
    3233        $oreon =& $_SESSION["oreon"]; 
     34 
     35        $CentreonGMT = new CentreonGMT(); 
    3336 
    3437        require_once $centreon_path."www/include/common/common-Func.php"; 
     
    5861        } else { 
    5962                $session->free(); 
     63                 
     64                /* 
     65                 * Get GMT for current user 
     66                 */ 
     67                $gmt = $CentreonGMT->getMyGMTFromSession($_GET["session_id"]); 
     68                 
    6069                /* 
    6170                 * Connect to ods 
     
    215224                 */ 
    216225                 
    217                 $rrd_time  = addslashes(date("Y\/m\/d G:i", $_GET["start"])); 
     226                $rrd_time  = addslashes($CentreonGMT->getDate("Y\/m\/d G:i", $_GET["start"])); 
    218227                $rrd_time = str_replace(":", "\:", $rrd_time); 
    219                 $rrd_time2 = addslashes(date("Y\/m\/d G:i", $_GET["end"])) ; 
     228                $rrd_time2 = addslashes($CentreonGMT->getDate("Y\/m\/d G:i", $_GET["end"])) ; 
    220229                $rrd_time2 = str_replace(":", "\:", $rrd_time2); 
    221230                $command_line .= " COMMENT:\" From $rrd_time to $rrd_time2 \\c\" ";