Пример #1
0
function snmpagent_cache_init()
{
    /* fill up the cache with a minimum of data data and ignore all values that
     *  will be updated automatically at the bottom of the next poller run
     */
    $mc = new MibCache();
    /* update global settings */
    snmpagent_global_settings_update();
    /* add pollers of a distributed system (future) */
    $pollers = db_fetch_assoc("SELECT id FROM poller ORDER BY id ASC");
    if ($pollers && sizeof($pollers) > 0) {
        foreach ($pollers as $poller) {
            $poller_data = db_fetch_row("SELECT * FROM poller WHERE id = " . $poller["id"]);
        }
    } else {
        /* this is NOT a distributed system, but it should have at least one local poller. */
        $poller_lastrun = read_config_option("poller_lastrun", true);
        $values = array("cactiApplPollerIndex" => 1, "cactiApplPollerHostname" => "localhost", "cactiApplPollerIpAddress" => "127.0.0.1", "cactiApplPollerLastUpdate" => $poller_lastrun);
        $mc->table('cactiApplPollerTable')->row(1)->insert($values);
        $values = array("cactiStatsPollerIndex" => 1, "cactiStatsPollerHostname" => "localhost", "cactiStatsPollerMethod" => read_config_option("poller_type", true));
        $mc->table('cactiStatsPollerTable')->row(1)->insert($values);
    }
    /* add all devices as devicetable entries to the snmp cache */
    $devices = db_fetch_assoc("SELECT id, description, hostname, disabled, status_event_count, status_fail_date, status_rec_date, status_last_error, min_time, max_time, cur_time, avg_time, total_polls, failed_polls, availability FROM host ORDER BY id ASC");
    if ($devices && sizeof($devices) > 0) {
        foreach ($devices as $device) {
            $device = db_fetch_row("SELECT * FROM host WHERE id = " . $device["id"]);
            /* add device to cactiApplDeviceTable */
            $values = array("cactiApplDeviceIndex" => $device["id"], "cactiApplDeviceDescription" => $device["description"], "cactiApplDeviceHostname" => $device["hostname"], "cactiApplDeviceStatus" => $device["disabled"] == 'on' ? 4 : $device["status"], "cactiApplDeviceEventCount" => $device["status_event_count"], "cactiApplDeviceFailDate" => $device["status_fail_date"], "cactiApplDeviceRecoveryDate" => $device["status_rec_date"], "cactiApplDeviceLastError" => $device["status_last_error"]);
            $mc->table('cactiApplDeviceTable')->row($device["id"])->insert($values);
            /* add device to cactiStatsDeviceTable */
            $values = array("cactiStatsDeviceIndex" => $device["id"], "cactiStatsDeviceHostname" => $device["hostname"], "cactiStatsDeviceMinTime" => $device["min_time"], "cactiStatsDeviceMaxTime" => $device["max_time"], "cactiStatsDeviceCurTime" => $device["cur_time"], "cactiStatsDeviceAvgTime" => $device["avg_time"], "cactiStatsDeviceTotalPolls" => $device["total_polls"], "cactiStatsDeviceFailedPolls" => $device["failed_polls"], "cactiStatsDeviceAvailability" => $device["availability"]);
            $mc->table('cactiStatsDeviceTable')->row($device["id"])->insert($values);
        }
    }
}
Пример #2
0
function boost_graph_set_file(&$output, $local_graph_id, $rra_id)
{
    global $config, $boost_sock, $graph_data_array;
    /* get access to the SNMP Cache of BOOST*/
    $mc = new MibCache('CACTI-BOOST-MIB');
    /* 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');
    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()) {
        $cache_directory = read_config_option('boost_png_cache_directory');
        if (strlen($cache_directory)) {
            if (is_dir($cache_directory)) {
                if ($rra_id > 0) {
                    $cache_file = $cache_directory . '/lgi_' . $local_graph_id . '_rrai_' . $rra_id;
                } else {
                    $cache_file = $cache_directory . '/lgi_' . $local_graph_id . '_rrai_' . $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 (is_writable($cache_directory)) {
                    /* if the cache file was created in a prior step, save it */
                    if (strlen($output) > 10) {
                        if ($fileptr = fopen($cache_file, 'w')) {
                            fwrite($fileptr, $output, strlen($output));
                            fclose($fileptr);
                            chmod($cache_file, 0666);
                            /* count the number of images that had to be cached */
                            $mc->object('boostStatsTotalsImagesCacheWrites')->count();
                            $mc->object('boostStatsLastUpdate')->set(time());
                        }
                    }
                } 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();
}
Пример #3
0
function thold_snmpagent_cache_uninstall()
{
    global $config;
    if (class_exists('MibCache')) {
        $mc = new MibCache('CACTI-THOLD-MIB');
        $mc->uninstall();
    }
}