예제 #1
0
include $config['html_dir'] . "/includes/functions.inc.php";
//var_dump(cli_is_piped());
$scriptname = basename($argv[0]);
$cli = TRUE;
$localhost = get_localhost();
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WTest Alert Notification%n\n", 'color');
print_versions();
// Allow the URL building code to build URLs with proper links.
$_SESSION['userlevel'] = 10;
if ($options['a']) {
    if ($config['alerts']['disable']['all']) {
        print_warning("All alert notifications disabled in config \$config['alerts']['disable']['all'], ignore it for testing!");
        $config['alerts']['disable']['all'] = FALSE;
    }
    $alert_rules = cache_alert_rules();
    $alert_assoc = cache_alert_assoc();
    $sql = "SELECT * FROM `alert_table`";
    $sql .= " WHERE `alert_table_id` = ?";
    $entry = dbFetchRow($sql, array($options['a']));
    //print_r($entry);
    alert_notifier($entry);
} else {
    print_cli("\nUSAGE:\n{$scriptname} -a alert_entry [-d debug]\n", 'color');
    $arguments = new \cli\Arguments();
    $arguments->addFlag('d', 'Turn on debug output');
    $arguments->addFlag('dd', 'More verbose debug output');
    $arguments->addOption('a', array('default' => '<alert entry id>', 'description' => 'Send test notification to for an alert entry'));
    echo $arguments->getHelpScreen();
    echo PHP_EOL . PHP_EOL;
}
// EOF
예제 #2
0
function process_alerts($device)
{
    global $config, $alert_rules, $alert_assoc;
    $pid_info = check_process_run($device);
    // This just clear stalled DB entries
    add_process_info($device);
    // Store process info
    print_cli_heading($device['hostname'] . " [" . $device['device_id'] . "]", 1);
    $alert_table = cache_device_alert_table($device['device_id']);
    $sql = "SELECT * FROM `alert_table`";
    //$sql .= " LEFT JOIN `alert_table-state` ON `alert_table`.`alert_table_id` = `alert_table-state`.`alert_table_id`";
    $sql .= " WHERE `device_id` = ? AND `alert_status` IS NOT NULL;";
    foreach (dbFetchRows($sql, array($device['device_id'])) as $entry) {
        print_cli_data_field('Alert: ' . $entry['alert_table_id']);
        print_cli('Status: [' . $entry['alert_status'] . '] ', 'color');
        // If the alerter is now OK and has previously alerted, send an recovery notice.
        if ($entry['alert_status'] == '1' && $entry['has_alerted'] == '1') {
            $alert = $alert_rules[$entry['alert_test_id']];
            if (!$alert['suppress_recovery']) {
                alert_notifier($entry, "recovery");
                $log_id = log_alert('Recovery notification sent', $device, $entry, 'RECOVER_NOTIFY');
            } else {
                echo 'Recovery suppressed.';
                $log_id = log_alert('Recovery notification suppressed', $device, $entry, 'RECOVER_SUPPRESSED');
            }
            $update_array['last_recovered'] = time();
            $update_array['has_alerted'] = 0;
            dbUpdate($update_array, 'alert_table', '`alert_table_id` = ?', array($entry['alert_table_id']));
        }
        if ($entry['alert_status'] == '0') {
            echo 'Alert tripped. ';
            // Has this been alerted more frequently than the alert interval in the config?
            /// FIXME -- this should be configurable per-entity or per-checker
            if (time() - $entry['last_alerted'] < $config['alerts']['interval'] && !isset($GLOBALS['spam'])) {
                $entry['suppress_alert'] = TRUE;
            }
            // Don't re-alert if interval set to 0
            if ($config['alerts']['interval'] == 0 && $entry['last_alerted'] != 0) {
                $entry['suppress_alert'] = TRUE;
            }
            // Check if alert has ignore_until set.
            if (is_numeric($entry['ignore_until']) && $entry['ignore_until'] > time()) {
                $entry['suppress_alert'] = TRUE;
            }
            // Check if alert has ignore_until_ok set.
            if (is_numeric($entry['ignore_until_ok']) && $entry['ignore_until_ok'] == '1') {
                $entry['suppress_alert'] = TRUE;
            }
            if ($entry['suppress_alert'] != TRUE) {
                echo 'Requires notification. ';
                alert_notifier($entry, "alert");
                $log_id = log_alert('Alert notification sent', $device, $entry, 'ALERT_NOTIFY');
                $update_array['last_alerted'] = time();
                $update_array['has_alerted'] = 1;
                dbUpdate($update_array, 'alert_table', '`alert_table_id` = ?', array($entry['alert_table_id']));
            } else {
                echo "No notification required. " . (time() - $entry['last_alerted']);
            }
        } else {
            if ($entry['alert_status'] == '1') {
                echo "Status: OK. ";
            } else {
                if ($entry['alert_status'] == '2') {
                    echo "Status: Notification Delayed. ";
                } else {
                    if ($entry['alert_status'] == '3') {
                        echo "Status: Notification Suppressed. ";
                    } else {
                        echo "Unknown status.";
                    }
                }
            }
        }
        echo PHP_EOL;
    }
    echo PHP_EOL;
    print_cli_heading($device['hostname'] . " [" . $device['device_id'] . "] completed notifications at " . date("Y-m-d H:i:s"), 1);
    // Clean
    del_process_info($device);
    // Remove process info
}