$where = "AND `hostname` LIKE ?"; $doing = $options['h']; $params[] = str_replace('*', '%', $options['h']); } } if (!$where) { print_message("%n\nUSAGE:\n{$scriptname} [-drqV] [-i instances] [-n number] [-m module] [-h device]\n\nEXAMPLE:\n-h <device id> | <device hostname wildcard> Poll single device\n-h odd Poll odd numbered devices (same as -i 2 -n 0)\n-h even Poll even numbered devices (same as -i 2 -n 1)\n-h all Poll all devices\n-h new Poll all devices that have not had a discovery run before\n\n-i <instances> -n <number> Poll as instance <number> of <instances>\n Instances start at 0. 0-3 for -n 4\n\nOPTIONS:\n -h Device hostname, id or key odd/even/all/new.\n -i Poll instance.\n -n Poll number.\n -s Sends alerts even if they have already been sent.\n -q Quiet output.\n -V Show version and exit.\n\nDEBUGGING OPTIONS:\n -r Do not create or update RRDs\n -d Enable debugging output.\n -dd More verbose debugging output.\n -m Specify module(s) (separated by commas) to be run.\n\n%rInvalid arguments!%n", 'color'); exit; } print_cli_heading("%WStarting alerter run at " . date("Y-m-d H:i:s"), 0); $polled_devices = 0; if (!isset($query)) { $query = "SELECT `device_id` FROM `devices` WHERE `disabled` = 0 {$where} ORDER BY `device_id` ASC"; } $alert_rules = cache_alert_rules(); $alert_assoc = cache_alert_assoc(); // Allow the URL building code to build URLs with proper links. $_SESSION['userlevel'] = 10; foreach (dbFetch($query, $params) as $device) { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id'])); humanize_device($device); // Overwrite the autogenerated base_url with external_url when we can't guess. ## FIXME -- Do this automatically when we know we're not running in a webserver. $config['base_url'] = $config['external_url']; process_alerts($device); process_notifications($device); // Send all notifications (also for syslog from queue) dbUpdate(array('last_alerter' => array('NOW()')), 'devices', '`device_id` = ?', array($device['device_id'])); } print_cli_heading("%WFinished alerter run at " . date("Y-m-d H:i:s"), 0); // EOF
exit; case "--help": display_help(); exit; default: print "ERROR: Invalid Parameter " . $parameter . "\n\n"; display_help(); exit; } } if ($camm_debug) { camm_debug("S0. Found enabled DEBUG mode. Output will be verbose"); } camm_debug("S0. About to enter iper poller processing"); $seconds_offset = read_config_option("camm_autopurge_timing"); process_alerts(); if ($seconds_offset != "disabled" || $forcerun) { camm_debug("S2. Checking to determine if it's time to run AutoPurge process."); $seconds_offset = $seconds_offset * 60; /* find out if it's time to collect device information */ //$base_start_time = read_config_option("camm_base_time"); $last_run_time = read_config_option("camm_last_run_time", true); //$previous_base_start_time = read_config_option("camm_prev_base_time"); /* determine the next start time */ $current_time = strtotime("now"); $next_run_time = $last_run_time + $seconds_offset; $time_till_next_run = $next_run_time - $current_time; if ($time_till_next_run < 0) { camm_debug("S2.1 The next AutoPurge process run time has been determined to be NOW"); } else { camm_debug("S2.1 The next AutoPurge process run time has been determined to be at '" . date("Y-m-d G:i:s", $next_run_time) . "'. Last run time was '" . date("Y-m-d G:i:s", $last_run_time) . "'");