This script is only meant to run at the command line."); } $no_http_headers = true; include(dirname(__FILE__) . "/../include/global.php"); include_once($config["base_path"] . "/lib/utility.php"); /* process calling arguments */ $parms = $_SERVER["argv"]; array_shift($parms); $debug = FALSE; $host_id = 0; foreach($parms as $parameter) { @list($arg, $value) = @explode("=", $parameter); switch ($arg) { case "-d": case "--debug": $debug = TRUE; break; case "--host-id": $host_id = trim($value); if (!is_numeric($host_id)) { echo "ERROR: You must supply a valid host-id to run this script!\n"; exit(1); } break; case "-h": case "-v": case "--version": case "--help": display_help(); exit; default: print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } /* obtain timeout settings */ $max_execution = ini_get("max_execution_time"); /* set new timeout */ ini_set("max_execution_time", "0"); /* get the data_local Id's for the poller cache */ if ($host_id > 0) { $poller_data = db_fetch_assoc("SELECT id FROM data_local WHERE host_id=$host_id"); } else { $poller_data = db_fetch_assoc("SELECT id FROM data_local"); } /* initialize some variables */ $current_ds = 1; $total_ds = sizeof($poller_data); /* setting local_data_ids to an empty array saves time during updates */ $local_data_ids = array(); $poller_items = array(); /* issue warnings and start message if applicable */ print "WARNING: Do not interrupt this script. Rebuilding the Poller Cache can take quite some time\n"; debug("There are '" . sizeof($poller_data) . "' data source elements to update."); /* start rebuilding the poller cache */ if (sizeof($poller_data) > 0) { foreach ($poller_data as $data) { if (!$debug) print "."; $local_data_ids[] = $data["id"]; $poller_items = array_merge($poller_items, update_poller_cache($data["id"])); debug("Data Source Item '$current_ds' of '$total_ds' updated"); $current_ds++; } if (sizeof($local_data_ids)) { poller_update_poller_cache_from_buffer($local_data_ids, $poller_items); } } if (!$debug) print "\n"; /* poller cache rebuilt, restore runtime parameters */ ini_set("max_execution_time", $max_execution); /* display_help - displays the usage of the function */ function display_help () { $version = db_fetch_cell('SELECT cacti FROM version'); echo "Rebuild Poller Cache Utility, Version $version, " . COPYRIGHT_YEARS . "\n\n"; echo "usage: rebuild_poller_cache.php [--host-id=ID] [-d | --debug] [-h | --help | -v | --version]\n\n"; echo "-d | --debug - Display verbose output during execution\n"; echo "-v --version - Display this help message\n"; echo "-h --help - Display this help message\n"; } function debug($message) { global $debug; if ($debug) { print("DEBUG: " . $message . "\n"); } } ?>