Example #1
0
function boost_graph_cache_check($local_graph_id, $rra_id, $rrdtool_pipe, $graph_data_array, $return = true)
{
    global $config;
    /* include poller processing routinges */
    include_once $config['library_path'] . '/poller.php';
    /* suppressnwarnings */
    if (defined('E_DEPRECATED')) {
        error_reporting(E_ALL ^ E_DEPRECATED);
    } else {
        error_reporting(E_ALL);
    }
    /* install the boost error handler */
    set_error_handler('boost_error_handler');
    /* if we are just printing the rrd command return */
    if (isset($graph_data_array['print_source'])) {
        /* restore original error handler */
        restore_error_handler();
        return false;
    }
    /* if we want to view the error message, then don't show the cache */
    if (isset($graph_data_array['output_type']) && $graph_data_array['output_type'] == RRDTOOL_OUTPUT_STDERR) {
        /* restore original error handler */
        restore_error_handler();
        return false;
    }
    /* get the information to populate into the rrd files */
    if (boost_check_correct_enabled()) {
        /* before we make a graph, we need to check for rrd updates and perform them. */
        $local_data_ids = db_fetch_assoc_prepared('SELECT DISTINCT
			data_template_rrd.local_data_id
			FROM graph_templates_item
			INNER JOIN data_template_rrd
			ON (graph_templates_item.task_item_id = data_template_rrd.id)
			WHERE graph_templates_item.local_graph_id = ?
			AND data_template_rrd.local_data_id > 0', array($local_graph_id));
        /* first update the RRD files */
        if (sizeof($local_data_ids)) {
            $updates = 0;
            foreach ($local_data_ids as $local_data_id) {
                $updates += boost_process_poller_output(true, $local_data_id['local_data_id']);
            }
            if ($updates) {
                /* restore original error handler */
                restore_error_handler();
                return false;
            }
        }
    }
    if (isset($_SESSION['sess_current_timespan'])) {
        $timespan = $_SESSION['sess_current_timespan'];
    } else {
        $timespan = 0;
    }
    /* check the graph cache and use it if it is valid, otherwise turn over to
     * cacti's graphing fucntions.
     */
    if (read_config_option('boost_png_cache_enable') == 'on' && boost_determine_caching_state()) {
        /* if timespan is greater than 1, it is a predefined, if it does not
         * exist, it is the old fasioned MRTG type graph
         */
        $cache_directory = read_config_option('boost_png_cache_directory');
        if (strlen($cache_directory)) {
            if (is_dir($cache_directory)) {
                if (is_writable($cache_directory)) {
                    if ($rra_id > 0) {
                        $cache_file = $cache_directory . '/lgi_' . $data['local_graph_id'] . '_rrai_' . $data['rra_id'];
                    } else {
                        $cache_file = $cache_directory . '/lgi_' . $data['local_graph_id'] . '_rrai_' . $data['rra_id'] . '_tsi_' . $timespan;
                    }
                    if (isset($graph_data_array['graph_height'])) {
                        $cache_file .= '_height_' . $graph_data_array['graph_height'];
                    }
                    if (isset($graph_data_array['graph_width'])) {
                        $cache_file .= '_width_' . $graph_data_array['graph_width'];
                    }
                    if (isset($graph_data_array['graph_nolegend'])) {
                        $cache_file .= '_thumb.png';
                    } else {
                        $cache_file .= '.png';
                    }
                    if (file_exists($cache_file)) {
                        $mod_time = filemtime($cache_file);
                        $poller_interval = read_config_option('poller_interval');
                        if (!isset($poller_interval)) {
                            $poller_interval = '300';
                        }
                        if ($mod_time + $poller_interval > time()) {
                            if ($fileptr = fopen($cache_file, 'rb')) {
                                $output = fread($fileptr, filesize($cache_file));
                                fclose($fileptr);
                                /* restore original error handler */
                                restore_error_handler();
                                /* get access to the SNMP Cache of BOOST*/
                                $mc = new MibCache('CACTI-BOOST-MIB');
                                $mc->object('boostStatsTotalsImagesCacheReads')->count();
                                $mc->object('boostStatsLastUpdate')->set(time());
                                return $output;
                            } else {
                                if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_DEBUG) {
                                    cacti_log("Attempting to open cache file '{$cache_file}' failed", false, 'BOOST');
                                }
                            }
                        } else {
                            if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_DEBUG) {
                                cacti_log("Boost Cache PNG Expired.  Image '{$cache_file}' will be recreated", false, 'BOOST');
                            }
                        }
                    }
                } else {
                    cacti_log('ERROR: Boost Cache Directory is not writable!  Can not cache images', false, 'BOOST');
                }
            } else {
                cacti_log('ERROR: Boost Cache Directory does not exist! Can not cache images', false, 'BOOST');
            }
        } else {
            cacti_log('ERROR: Boost Cache Directory variable is not set! Can not cache images', false, 'BOOST');
        }
    }
    /* restore original error handler */
    restore_error_handler();
    return false;
}
Example #2
0
function boost_graph_cache_check($data)
{
    global $config;
    /* include poller processing routinges */
    include_once $config["library_path"] . "/poller.php";
    /* suppress warnings */
    if (defined("E_DEPRECATED")) {
        error_reporting(E_ALL ^ E_DEPRECATED);
    } else {
        error_reporting(E_ALL);
    }
    /* install the boost error handler */
    set_error_handler("boost_error_handler");
    /* process input parameters */
    $local_graph_id = $data['local_graph_id'];
    $rra_id = $data['rra_id'];
    $rrdtool_pipe = $data['rrd_struc'];
    $graph_data_array = $data['graph_data_array'];
    /* if we are just printing the rrd command return */
    if (isset($graph_data_array["print_source"])) {
        /* restore original error handler */
        restore_error_handler();
        return FALSE;
    }
    /* if we want to view the error message, then don't show the cache */
    if (isset($graph_data_array["output_type"]) && $graph_data_array["output_type"] == RRDTOOL_OUTPUT_STDERR) {
        /* restore original error handler */
        restore_error_handler();
        return FALSE;
    }
    /* get the information to populate into the rrd files */
    if (boost_check_correct_enabled()) {
        /* before we make a graph, we need to check for rrd updates and perform them. */
        $local_data_ids = db_fetch_assoc("SELECT DISTINCT\r\n\t\t\tdata_template_rrd.local_data_id\r\n\t\t\tFROM graph_templates_item\r\n\t\t\tINNER JOIN data_template_rrd\r\n\t\t\tON (graph_templates_item.task_item_id=data_template_rrd.id)\r\n\t\t\tWHERE graph_templates_item.local_graph_id='{$local_graph_id}'\r\n\t\t\tAND data_template_rrd.local_data_id > 0");
        /* first update the RRD files */
        if (sizeof($local_data_ids)) {
            $updates = 0;
            foreach ($local_data_ids as $local_data_id) {
                $updates += boost_process_poller_output(TRUE, $local_data_id["local_data_id"]);
            }
            if ($updates) {
                /* restore original error handler */
                restore_error_handler();
                return FALSE;
            }
        }
    }
    if (isset($_SESSION["sess_current_timespan"])) {
        $timespan = $_SESSION["sess_current_timespan"];
    } else {
        $timespan = 0;
    }
    /* check the graph cache and use it if it is valid, otherwise turn over to
     * cacti's graphing fucntions.
     */
    if (read_config_option("boost_png_cache_enable") && boost_determine_caching_state()) {
        /* if timespan is greater than 1, it is a predefined, if it does not
         * exist, it is the old fasioned MRTG type graph
         */
        $cache_directory = read_config_option("boost_png_cache_directory");
        if (strlen($cache_directory)) {
            if (is_dir($cache_directory)) {
                if (is_writable($cache_directory)) {
                    if ($rra_id > 0) {
                        $cache_file = $cache_directory . "/lgi_" . $data["local_graph_id"] . "_rrai_" . $data["rra_id"];
                    } else {
                        $cache_file = $cache_directory . "/lgi_" . $data["local_graph_id"] . "_rrai_" . $data["rra_id"] . "_tsi_" . $timespan;
                    }
                    if (isset($graph_data_array["graph_height"])) {
                        $cache_file .= "_height_" . $graph_data_array["graph_height"];
                    }
                    if (isset($graph_data_array["graph_width"])) {
                        $cache_file .= "_width_" . $graph_data_array["graph_width"];
                    }
                    if (isset($graph_data_array["graph_nolegend"])) {
                        $cache_file .= "_thumb.png";
                    } else {
                        $cache_file .= ".png";
                    }
                    if (file_exists($cache_file)) {
                        $mod_time = filemtime($cache_file);
                        $poller_interval = read_config_option("poller_interval");
                        if (!isset($poller_interval)) {
                            $poller_interval = "300";
                        }
                        if ($mod_time + $poller_interval > time()) {
                            if ($fileptr = fopen($cache_file, "rb")) {
                                $data['return'] = fread($fileptr, filesize($cache_file));
                                fclose($fileptr);
                                /* restore original error handler */
                                restore_error_handler();
                                return $data;
                            } else {
                                if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_DEBUG) {
                                    cacti_log("Attempting to open cache file '{$cache_file}' failed", FALSE, "BOOST");
                                }
                            }
                        } else {
                            if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_DEBUG) {
                                cacti_log("Boost Cache PNG Expired.  Image '{$cache_file}' will be recreated", FALSE, "BOOST");
                            }
                        }
                    }
                } else {
                    cacti_log("ERROR: Boost Cache Directory is not writable!  Can not cache images", FALSE, "BOOST");
                }
            } else {
                cacti_log("ERROR: Boost Cache Directory does not exist! Can not cache images", FALSE, "BOOST");
            }
        } else {
            cacti_log("ERROR: Boost Cache Directory variable is not set! Can not cache images", FALSE, "BOOST");
        }
    }
    /* restore original error handler */
    restore_error_handler();
    return FALSE;
}
Example #3
0
function get_current_value($rra, $ds, $cdef = 0)
{
    global $config;
    /* get the information to populate into the rrd files */
    if (function_exists("boost_check_correct_enabled") && boost_check_correct_enabled()) {
        boost_process_poller_output(TRUE, $rra);
    }
    $last_time_entry = thold_rrd_last($rra);
    // This should fix and 'did you really mean month 899 errors', this is because your RRD has not polled yet
    if ($last_time_entry == -1) {
        $last_time_entry = time();
    }
    $data_template_data = db_fetch_row("SELECT * FROM data_template_data WHERE local_data_id={$rra}");
    $step = $data_template_data['rrd_step'];
    // Round down to the nearest 100
    $last_time_entry = intval($last_time_entry / 100) * 100 - $step;
    $last_needed = $last_time_entry + $step;
    $result = rrdtool_function_fetch($rra, trim($last_time_entry), trim($last_needed));
    // Return Blank if the data source is not found (Newly created?)
    if (!isset($result['data_source_names'])) {
        return '';
    }
    $idx = array_search($ds, $result['data_source_names']);
    // Return Blank if the value was not found (Cache Cleared?)
    if (!isset($result['values'][$idx][0])) {
        return '';
    }
    $value = $result['values'][$idx][0];
    if ($cdef != 0) {
        $value = thold_build_cdef($cdef, $value, $rra, $ds);
    }
    return round($value, 4);
}