Esempio n. 1
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage discovery
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
print_cli_data_field("Discovering MIBs", 3);
// Include all discovery modules by supported MIB
$include_dir = "includes/discovery/processors";
include "includes/include-dir-mib.inc.php";
// Detect processors by simple MIB-based discovery :
// FIXME - this should also be extended to understand multiple entries in a table, and take descr from an OID but this is all I need right now :)
foreach (get_device_mibs($device) as $mib) {
    if (is_array($config['mibs'][$mib]['processor'])) {
        echo "{$mib} ";
        foreach ($config['mibs'][$mib]['processor'] as $entry_name => $entry) {
            //echo($entry_name.' ');
            $entry['found'] = FALSE;
            if ($entry['type'] == 'table') {
                $processors_array = snmpwalk_cache_oid($device, $entry['table'], array(), $mib);
                if ($entry['table_descr']) {
                    // If descr in separate table with same indexes
                    $processors_array = snmpwalk_cache_oid($device, $entry['table_descr'], $processors_array, $mib);
                }
Esempio n. 2
0
 $bgpLocalAs = snmp_dewrap32bit($bgpLocalAs);
 // Dewrap for 32bit ASN
 print_cli_data("Local AS", "AS{$bgpLocalAs} ", 2);
 if ($bgpLocalAs != $device['bgpLocalAs']) {
     if (!$device['bgpLocalAs']) {
         log_event('BGP Local ASN added: AS' . $bgpLocalAs, $device, 'device', $device['device_id']);
     } elseif (!$bgpLocalAs) {
         log_event('BGP Local ASN removed: AS' . $device['bgpLocalAs'], $device, 'device', $device['device_id']);
     } else {
         log_event('BGP ASN changed: AS' . $device['bgpLocalAs'] . ' -> AS' . $bgpLocalAs, $device, 'device', $device['device_id']);
     }
     dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id = ?', array($device['device_id']));
     print_cli_data("Updated ASN", $device['bgpLocalAs'] . " -> {$bgpLocalAs}", 2);
     //print_message('Updated ASN (from '.$device['bgpLocalAs']." -> $bgpLocalAs)");
 }
 print_cli_data_field("Caching", 2);
 print_debug("BGP4-MIB ");
 $cisco_version = FALSE;
 if (is_device_mib($device, 'CISCO-BGP4-MIB')) {
     $cisco_version = 1;
     // Check Cisco cbgpPeer2Table
     $cisco_peers = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', array(), 'CISCO-BGP4-MIB');
     if (count($cisco_peers) > 0) {
         echo "CISCO-BGP4-MIB ";
         $cisco_version = 2;
         $cisco_peers = snmpwalk_cache_oid($device, 'cbgpPeer2LocalAddr', $cisco_peers, 'CISCO-BGP4-MIB');
         // Cisco vendor mib LocalAddr issue:
         // cbgpPeer2LocalAddr.ipv4."10.0.1.1" = "0B 8E 95 38 " --> 11.142.149.56
         // but should:
         // bgpPeerLocalAddr.10.0.1.1 = 10.0.1.3
         // Yah, Cisco you again added extra work for me? What mean this random numbers?
Esempio n. 3
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage poller
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
$app_rows = dbFetchRows("SELECT * FROM `applications` WHERE `device_id` = ?", array($device['device_id']));
foreach ($app_rows as $app) {
    $valid_applications[$app] = $app;
}
if (is_array($valid_applications) && count($valid_applications)) {
    print_cli_data_field("Applications", 2);
    foreach ($valid_applications as $app_type) {
        echo $app_type . ' ';
        // One include per application type. Multiple instances currently handled within the application code
        $app_include = $config['install_dir'] . '/includes/polling/applications/' . $app_type . '.inc.php';
        if (is_file($app_include)) {
            include $app_include;
        } else {
            echo $app['app_type'] . ' include missing! ';
        }
    }
    echo PHP_EOL;
}
$app_rows = dbFetchRows("SELECT * FROM `applications` WHERE `device_id` = ? AND `app_lastpolled` < ?", array($device['device_id'], time() - 604800));
foreach ($app_rows as $app) {
    dbDelete('applications', '`app_id` = ?', array($app['app_id']));
Esempio n. 4
0
    $downstream_oids = array_diff($downstream_oids, $hc_oids);
}
// Merge stat oids
$stat_oids = array_merge($stat_oids_ifEntry, $stat_oids_ifXEntry);
// Cisco old locIf OIDs. Currently unused.
$cisco_oids = array('locIfHardType', 'locIfInRunts', 'locIfInGiants', 'locIfInCRC', 'locIfInFrame', 'locIfInOverrun', 'locIfInIgnored', 'locIfInAbort', 'locIfCollisions', 'locIfInputQueueDrops', 'locIfOutputQueueDrops');
// PAgP OIDs
//$pagp_oids = array('pagpOperationMode', 'pagpPortState', 'pagpPartnerDeviceId', 'pagpPartnerLearnMethod', 'pagpPartnerIfIndex', 'pagpPartnerGroupIfIndex',
//                   'pagpPartnerDeviceName', 'pagpEthcOperationMode', 'pagpDeviceId', 'pagpGroupIfIndex');
$pagp_oids = array();
// PAgP disabled since r7987, while not moved to new polling style
// PoE OIDs
$cpe_oids = array('cpeExtPsePortEnable', 'cpeExtPsePortDiscoverMode', 'cpeExtPsePortDeviceDetected', 'cpeExtPsePortIeeePd', 'cpeExtPsePortAdditionalStatus', 'cpeExtPsePortPwrMax', 'cpeExtPsePortPwrAllocated', 'cpeExtPsePortPwrAvailable', 'cpeExtPsePortPwrConsumption', 'cpeExtPsePortMaxPwrDrawn', 'cpeExtPsePortEntPhyIndex', 'cpeExtPsePortEntPhyIndex', 'cpeExtPsePortPolicingCapable', 'cpeExtPsePortPolicingEnable', 'cpeExtPsePortPolicingAction', 'cpeExtPsePortPwrManAlloc');
$peth_oids = array('pethPsePortAdminEnable', 'pethPsePortPowerPairsControlAbility', 'pethPsePortPowerPairs', 'pethPsePortDetectionStatus', 'pethPsePortPowerPriority', 'pethPsePortMPSAbsentCounter', 'pethPsePortType', 'pethPsePortPowerClassifications', 'pethPsePortInvalidSignatureCounter', 'pethPsePortPowerDeniedCounter', 'pethPsePortOverLoadCounter', 'pethPsePortShortCounter', 'pethMainPseConsumptionPower');
//$ifmib_oids = array_merge($data_oids, $stat_oids);
print_cli_data_field("Caching Oids");
$port_stats = array();
if (!$ports_modules['separate_walk']) {
    print_debug("Used full table ifEntry/ifXEntry snmpwalk.");
    $ifmib_oids = array('ifEntry', 'ifXEntry');
    foreach ($ifmib_oids as $oid) {
        $has_name = 'has_' . $oid;
        echo "{$oid} ";
        $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "IF-MIB");
        ${$has_name} = $GLOBALS['snmp_status'] || $GLOBALS['snmp_error_code'] === 2;
        // $has_ifEntry, $has_ifXEntry
        //print_vars($$has_name);
        if ($oid == 'ifEntry') {
            // Store error_code, 1000 == not exist table, 2 and 3 - not complete request
            $has_ifEntry_error_code = $GLOBALS['snmp_error_code'];
        }
Esempio n. 5
0
    if ($entry['sla_status'] != 'active') {
        continue;
    }
    if (!isset($entry['sla_mib'])) {
        $entry['sla_mib'] = 'CISCO-RTTMON-MIB';
    }
    // CLEANME, remove in r7500, but not before CE 0.16.1
    $index = $entry['sla_index'];
    $mib_lower = strtolower($entry['sla_mib']);
    if ($mib_lower != 'cisco-rttmon-mib') {
        // Use 'owner.index' as index, because all except Cisco use this!
        $index = $entry['sla_owner'] . '.' . $index;
    }
    $sla_db[$mib_lower][$index] = $entry;
}
print_cli_data_field("MIBs", 2);
foreach (array_keys($sla_db) as $mib_lower) {
    $file = $config['install_dir'] . "/includes/polling/slas/" . $mib_lower . ".inc.php";
    if (is_file($file)) {
        $cache_sla = array();
        include $file;
    } else {
        continue;
    }
    $sla_polled_time = time();
    // Store polled time for current MIB
    if (OBS_DEBUG > 1) {
        print_vars($cache_sla);
    }
    //$sla_db_count   += count($sla_db[$mib_lower]);
    $sla_snmp_count += count($cache_sla[$mib_lower]);
Esempio n. 6
0
#IP-MIB::ipSystemStatsOutDiscards.ipv6 = Counter32: 0
#IP-MIB::ipSystemStatsOutFragFails.ipv4 = Counter32: 0
#IP-MIB::ipSystemStatsOutFragFails.ipv6 = Counter32: 0
#IP-MIB::ipSystemStatsOutFragCreates.ipv4 = Counter32: 0
#IP-MIB::ipSystemStatsOutFragCreates.ipv6 = Counter32: 68
#IP-MIB::ipSystemStatsDiscontinuityTime.ipv4 = Timeticks: (0) 0:00:00.00
#IP-MIB::ipSystemStatsDiscontinuityTime.ipv6 = Timeticks: (0) 0:00:00.00
#IP-MIB::ipSystemStatsRefreshRate.ipv4 = Gauge32: 30000 milli-seconds
#IP-MIB::ipSystemStatsRefreshRate.ipv6 = Gauge32: 30000 milli-seconds
// FIXME instead of checking for blacklist, shouldn't we just add it to ALL devices, then use is_device_mib ?
// This code means you can't disable IP-MIB from the web interface and have it actually work.
if (!in_array("IP-MIB", get_device_mibs_blacklist($device))) {
    print_cli_data("Collecting", 'ipSystemStats', 2);
    $ipSystemStats = snmpwalk_cache_oid($device, "ipSystemStats", NULL, "IP-MIB");
    if ($ipSystemStats) {
        print_cli_data_field("Address Families", 2);
        foreach ($ipSystemStats as $af => $stats) {
            echo " {$af}";
            $oids = array('ipSystemStatsInReceives', 'ipSystemStatsInHdrErrors', 'ipSystemStatsInAddrErrors', 'ipSystemStatsInUnknownProtos', 'ipSystemStatsInForwDatagrams', 'ipSystemStatsReasmReqds', 'ipSystemStatsReasmOKs', 'ipSystemStatsReasmFails', 'ipSystemStatsInDiscards', 'ipSystemStatsInDelivers', 'ipSystemStatsOutRequests', 'ipSystemStatsOutNoRoutes', 'ipSystemStatsOutDiscards', 'ipSystemStatsOutFragFails', 'ipSystemStatsOutFragCreates', 'ipSystemStatsOutForwDatagrams');
            // Use HC counters instead if they're available.
            if (isset($stats['ipSystemStatsHCInReceives'])) {
                $stats['ipSystemStatsInReceives'] = $stats['ipSystemStatsHCInReceives'];
            }
            if (isset($stats['ipSystemStatsHCInForwDatagrams'])) {
                $stats['ipSystemStatsInForwDatagrams'] = $stats['ipSystemStatsHCInForwDatagrams'];
            }
            if (isset($stats['ipSystemStatsHCInDelivers'])) {
                $stats['ipSystemStatsInDelivers'] = $stats['ipSystemStatsHCInDelivers'];
            }
            if (isset($stats['ipSystemStatsHCOutRequests'])) {
                $stats['ipSystemStatsOutRequests'] = $stats['ipSystemStatsHCOutRequests'];
Esempio n. 7
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage poller
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
// FIXME -- we're walking, so we can discover here too.
/// FIXME FIXME REWRITE ME please ;)
print_cli_data_field('MIBs', 2);
#dbQuery('TRUNCATE TABLE `mac_accounting`');
#dbQuery('TRUNCATE TABLE `mac_accounting-state`');
// Cache DB entries
$sql = 'SELECT * FROM `mac_accounting`';
$sql .= ' LEFT JOIN `mac_accounting-state` USING(`ma_id`)';
$sql .= ' WHERE `device_id` = ?';
$acc_id_db = array();
foreach (dbFetchRows($sql, array($device['device_id'])) as $acc) {
    $port = get_port_by_id($acc['port_id']);
    if (is_array($port)) {
        $acc['ifIndex'] = $port['ifIndex'];
        unset($port);
        $ma_db_array[$acc['ifIndex'] . '-' . $acc['vlan_id'] . '-' . $acc['mac']] = $acc;
    }
    $acc_id_db[$acc['ma_id']] = $acc['ma_id'];
}
Esempio n. 8
0
print_cli(PHP_EOL);
// End Building SNMP Cache Array
if (OBS_DEBUG && count($port_stats)) {
    print_vars($port_stats);
}
// Build array of ports in the database
// FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :>
//       -- i can make it a function, so that you don't know what it's doing.
//       -- $ports_db = adamasMagicFunction($ports_db); ?
print_cli_data_field("Caching DB", 3);
foreach (dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ?", array($device['device_id'])) as $port) {
    $ports_db[$port['ifIndex']] = $port;
    $ports_db_l[$port['ifIndex']] = $port['port_id'];
}
print_cli(count($ports_db) . " ports" . PHP_EOL);
print_cli_data_field("Discovering ports", 3);
$table_rows = array();
// New interface detection
foreach ($port_stats as $ifIndex => $port) {
    $port['ifIndex'] = $ifIndex;
    $table_row = array($ifIndex, truncate($port['ifDescr'], 30), $port['ifName'], truncate($port['ifAlias'], 20), $port['ifType'], $port['ifOperStatus']);
    // Check the port against our filters.
    if (is_port_valid($port, $device)) {
        $table_row[] = '%gno%n';
        if (!is_array($ports_db[$ifIndex])) {
            process_port_label($port, $device);
            // Process ifDescr if needed
            $table_row[1] = truncate($port['ifDescr'], 30);
            $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex, 'ifAlias' => $port['ifAlias'], 'ifDescr' => $port['ifDescr'], 'ifName' => $port['ifName'], 'ifType' => $port['ifType']), 'ports');
            $ports_db[$ifIndex] = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ifIndex));
            echo " " . $port['ifName'] . "(" . $ifIndex . ")[" . $ports_db[$ifIndex]['port_id'] . "]";
Esempio n. 9
0
        }
    }
}
echo PHP_EOL;
// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98
// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0
// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128
// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2
// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0
// OSPF-MIB::ospfNbrState.172.22.203.98.0 full
// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6
// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1
// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active
// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic
// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false
print_cli_data_field('Neighbours', 2);
$ospf_nbr_oids_db = array('ospfNbrIpAddr', 'ospfNbrAddressLessIndex', 'ospfNbrRtrId', 'ospfNbrOptions', 'ospfNbrPriority', 'ospfNbrState', 'ospfNbrEvents', 'ospfNbrLsRetransQLen', 'ospfNbmaNbrStatus', 'ospfNbmaNbrPermanence', 'ospfNbrHelloSuppressed');
$ospf_nbr_oids_rrd = array();
$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd);
// Build array of existing entries
foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ?', array($device['device_id'])) as $nbr_entry) {
    $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']] = $nbr_entry;
}
foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) {
    // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
    if (!isset($ospf_nbrs_db[$ospf_nbr_id])) {
        dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id), 'ospf_nbrs');
        echo '+';
        $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id));
        $ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry;
    }
Esempio n. 10
0
        $type = isset($config['os'][$os]['type']) ? $config['os'][$os]['type'] : 'unknown';
        // Also change $type
        print_cli_data('Device OS changed', $device['os'] . " -> {$os}", 1);
        log_event('OS changed: ' . $device['os'] . ' -> ' . $os, $device, 'device', $device['device_id'], 'warning');
        dbUpdate(array('os' => $os), 'devices', '`device_id` = ?', array($device['device_id']));
        $device['os'] = $os;
        $device['type'] = $type;
    }
}
// If enabled, check the sysORID table for supported MIBs
if ($config['snmp']['snmp_sysorid']) {
    $sysORID_mibs = array();
    $table_rows = array();
    $advertised_mibs = array();
    $capabilities_mibs = array();
    print_cli_data_field('sysORID table');
    $device_sysORID = snmpwalk_cache_oid_num2($device, 'sysORID', array(), 'SNMPv2-MIB');
    $device_sysORID = snmpwalk_cache_oid($device, 'sysORDescr', $device_sysORID, 'SNMPv2-MIB', NULL, OBS_SNMP_ALL_MULTILINE);
    //print_vars($device_sysORID);
    foreach ($device_sysORID as $entry) {
        $advertised_mibs[] = $entry['sysORID'];
        if (preg_match('/AGENT-CAPABILITIES\\s+SUPPORTS\\s+(?<mib>\\S+)/', $entry['sysORDescr'], $matches)) {
            $mib = str_ireplace('ETHERLIKE-MIB', 'EtherLike-MIB', $matches['mib']);
            // Fix camel-case mib name
            // Collect AGENT-CAPABILITIES if MIB exist in definitions
            if (isset($config['mibs'][$mib]) && $mib != 'Printer-MIB') {
                $capabilities_mibs[$mib][] = $entry['sysORID'];
            } else {
                // This is just for info in output
                $capabilities_unused[$entry['sysORID']] = $mib;
            }
Esempio n. 11
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
// Collect data for non-entity graphs
$include_dir = "includes/polling/graphs/";
include "includes/include-dir-mib.inc.php";
foreach ($table_defs as $mib_name => $mib_tables) {
    print_cli_data_field("{$mib_name}", 2);
    foreach ($mib_tables as $table_name => $table_def) {
        echo "{$table_name} ";
        collect_table($device, $table_def, $graphs);
    }
    echo PHP_EOL;
}
// EOF
Esempio n. 12
0
                            unset($old_rrd, $new_rrd);
                        }
                        discover_sensor($valid['sensor'], $entry['class'], $device, $oid_num, $index, $entry['type'], $descr, $entry['scale'], $value, $options);
                    }
                    $i++;
                }
            }
            print_cli('] ');
        }
        print_cli(PHP_EOL);
    }
}
// Detect Status by simple MIB-based discovery :
foreach (get_device_mibs($device) as $mib) {
    if (is_array($config['mibs'][$mib]['status'])) {
        print_cli_data_field($mib);
        foreach ($config['mibs'][$mib]['status'] as $oid => $oid_data) {
            print_cli($oid . ' [');
            foreach ($oid_data['indexes'] as $index => $entry) {
                $entry['oid'] = $oid;
                if (empty($entry['oid_num'])) {
                    // Use snmptranslate if oid_num not set
                    $entry['oid_num'] = snmp_translate($oid . '.' . $index, $mib);
                }
                $value = snmp_get($device, $entry['oid_num'], '-OQUvsn');
                if (is_numeric($value)) {
                    // Fetch description from oid if specified
                    if (isset($entry['oid_descr'])) {
                        $entry['descr'] = snmp_get($device, $entry['oid_descr'], '-OQUvs');
                    }
                    rename_rrd($device, "status-" . $entry['type'] . '-' . $index, "status-" . $entry['type'] . '-' . "{$oid}.{$index}");
Esempio n. 13
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage discovery
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
print_cli_data_field("Discovering IP Addresses", 3);
$ip_data = array('ipv4' => array(), 'ipv6' => array());
$valid['ip-addresses'] = array();
$include_dir = 'includes/discovery/ip-addresses';
$include_order = 'default';
// Use MIBs from default os definitions by first!
include $config['install_dir'] . "/includes/include-dir-mib.inc.php";
// Process IP Addresses
$table_rows = array();
$check_networks = array();
foreach (array('ipv4', 'ipv6') as $ip_version) {
    if (OBS_DEBUG && count($ip_data[$ip_version])) {
        print_vars($ip_data[$ip_version]);
    }
    // Caching old IP addresses table
    $query = 'SELECT * FROM `' . $ip_version . '_addresses`
            LEFT JOIN `ports` USING(`port_id`)
            WHERE `device_id` = ?';
    foreach (dbFetchRows($query, array($device['device_id'])) as $entry) {
Esempio n. 14
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage poller
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
//  Generic System Statistics
if (is_device_mib($device, 'HOST-RESOURCES-MIB')) {
    $oid_list = "hrSystemProcesses.0 hrSystemNumUsers.0";
    $hrSystem = snmp_get_multi($device, $oid_list, "-OUQs", "HOST-RESOURCES-MIB");
    print_cli_data_field("Collecting", 2);
    if (is_numeric($hrSystem[0]['hrSystemProcesses'])) {
        rrdtool_update_ng($device, 'hr_processes', array('procs' => $hrSystem[0]['hrSystemProcesses']));
        $graphs['hr_processes'] = TRUE;
        echo " Processes";
    }
    if (is_numeric($hrSystem[0]['hrSystemNumUsers'])) {
        rrdtool_update_ng($device, 'hr_users', array('users' => $hrSystem[0]['hrSystemNumUsers']));
        $graphs['hr_users'] = TRUE;
        echo " Users";
    }
    echo PHP_EOL;
}
# end is_device_mib()
// EOF
Esempio n. 15
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
}