Пример #1
0
 // Discover BGP peers
 /// NOTE. PeerIdentifier != PeerRemoteAddr
 if (is_numeric($bgpLocalAs) && $bgpLocalAs != '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
Пример #2
0
function discover_device($device, $options = NULL)
{
    global $config, $valid, $exec_status, $discovered_devices;
    // Initialise variables
    $valid = array();
    // Reset $valid array
    $modules = array();
    $cache_discovery = array();
    // Specific discovery cache for exchange snmpwalk data between modules (memory/storage/sensors/etc)
    $attribs = get_entity_attribs('device', $device['device_id']);
    $device_start = utime();
    // Start counting device poll time
    // Check if device discovery already running
    $pid_info = check_process_run($device);
    if ($pid_info) {
        // Process ID exist in DB
        print_message("%rAnother " . $pid_info['process_name'] . " process (PID: " . $pid_info['PID'] . ", UID: " . $pid_info['UID'] . ", STARTED: " . $pid_info['STARTED'] . ") already running for device " . $device['hostname'] . " (" . $device['device_id'] . ").%n", 'color');
        return FALSE;
    }
    add_process_info($device);
    // Store process info
    print_cli_heading($device['hostname'] . " [" . $device['device_id'] . "]", 1);
    $detect_os = TRUE;
    // Set TRUE or FALSE for module 'os' (exclude double os detection)
    if ($device['os'] == 'generic' || isset($options['h']) && $options['h'] == 'new') {
        $detect_os = FALSE;
        $old_os = $device['os'];
        $device['os'] = get_device_os($device);
        if ($device['os'] != $old_os) {
            print_cli_data("Device OS changed", $old_os . " -> " . $device['os'], 1);
            log_event('OS changed: ' . $old_os . ' -> ' . $device['os'], $device, 'device', $device['device_id'], 'warning');
            dbUpdate(array('os' => $device['os']), 'devices', '`device_id` = ?', array($device['device_id']));
        }
    }
    print_cli_data("OS Type", $device['os'], 1);
    if ($config['os'][$device['os']]['group']) {
        $device['os_group'] = $config['os'][$device['os']]['group'];
        print_cli_data("OS Group", $device['os_group'], 1);
    }
    print_cli_data("SNMP Version", $device['snmp_version'], 1);
    print_cli_data("Last discovery", $device['last_discovered'], 1);
    print_cli_data("Last duration", $device['last_discovered_timetaken'] . " seconds", 1);
    echo PHP_EOL;
    // Either only run the modules specified on the commandline, or run all modules in config.
    if ($options['m']) {
        foreach (explode(",", $options['m']) as $module) {
            $modules[$module] = TRUE;
        }
    } else {
        if ($device['force_discovery'] && $options['h'] == 'new' && isset($attribs['force_discovery_modules'])) {
            // Forced discovery specific modules
            foreach (json_decode($attribs['force_discovery_modules'], TRUE) as $module) {
                $modules[$module] = TRUE;
            }
            log_event('Forced discovery module(s): ' . implode(', ', array_keys($modules)), $device, 'device', $device['device_id'], 'debug');
        } else {
            $modules = $config['discovery_modules'];
        }
    }
    // Use os specific modules order
    //print_vars($modules);
    if (isset($config['os'][$device['os']]['discovery_order'])) {
        //print_vars($config['os'][$device['os']]['discovery_order']);
        foreach ($config['os'][$device['os']]['discovery_order'] as $module => $module_order) {
            if (array_key_exists($module, $modules)) {
                $module_status = $modules[$module];
                switch ($module_order) {
                    case 'last':
                        // add to end of modules list
                        unset($modules[$module]);
                        $modules[$module] = $module_status;
                        break;
                    case 'first':
                        // add to begin of modules list, but not before os/system
                        $new_modules = array();
                        if ($modules['os']) {
                            $new_modules['os'] = $modules['os'];
                            unset($modules['os']);
                        }
                        if ($modules['system']) {
                            $new_modules['system'] = $modules['system'];
                            unset($modules['system']);
                        }
                        $new_modules[$module] = $module_status;
                        unset($modules[$module]);
                        $modules = $new_modules + $modules;
                        break;
                    default:
                        // add into specific place (after module name in $module_order)
                        // yes, this is hard and magically
                        if (array_key_exists($module_order, $modules)) {
                            unset($modules[$module]);
                            $new_modules = array();
                            foreach ($modules as $new_module => $new_status) {
                                array_shift($modules);
                                $new_modules[$new_module] = $new_status;
                                if ($new_module == $module_order) {
                                    $new_modules[$module] = $module_status;
                                    break;
                                }
                            }
                            $modules = array_merge($new_modules, (array) $modules);
                        }
                }
            }
        }
        //print_vars($modules);
    }
    foreach ($modules as $module => $module_status) {
        if (discovery_module_excluded($device, $module) === FALSE) {
            if ($attribs['discover_' . $module] || $module_status && !isset($attribs['discover_' . $module])) {
                $m_start = utime();
                $GLOBALS['module_stats'][$module] = array();
                print_cli_heading("Module Start: %R" . $module . "");
                include "includes/discovery/{$module}.inc.php";
                $m_end = utime();
                $GLOBALS['module_stats'][$module]['time'] = round($m_end - $m_start, 4);
                print_module_stats($device, $module);
                echo PHP_EOL;
                //print_cli_heading("Module End: %R".$module."");
            } elseif (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == "0") {
                print_debug("Module [ {$module} ] disabled on host.");
            } else {
                print_debug("Module [ {$module} ] disabled globally.");
            }
        }
    }
    // Set type to a predefined type for the OS if it's not already set
    if ($device['type'] == "unknown" || $device['type'] == "") {
        if ($config['os'][$device['os']]['type']) {
            $device['type'] = $config['os'][$device['os']]['type'];
        }
    }
    $device_end = utime();
    $device_run = $device_end - $device_start;
    $device_time = substr($device_run, 0, 5);
    dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time, 'force_discovery' => 0), 'devices', '`device_id` = ?', array($device['device_id']));
    if (isset($attribs['force_discovery_modules'])) {
        del_entity_attrib('device', $device['device_id'], 'force_discovery_modules');
    }
    // Put performance into devices_perftimes table
    // Not worth putting discovery data into rrd. it's not done every 5 mins :)
    dbInsert(array('device_id' => $device['device_id'], 'operation' => 'discover', 'start' => $device_start, 'duration' => $device_run), 'devices_perftimes');
    print_cli_heading($device['hostname'] . " [" . $device['device_id'] . "] completed discovery modules at " . date("Y-m-d H:i:s"), 1);
    print_cli_data("Discovery time", $device_time . " seconds", 1);
    echo PHP_EOL;
    $discovered_devices++;
    // Clean
    del_process_info($device);
    // Remove process info
    unset($cache_discovery);
}
Пример #3
0
    } else {
        $data = snmpwalk_cache_oid($device, $type, array(), $netstats['mib']);
        if (!count($data)) {
            continue;
        }
        $data_array = $data[0];
    }
    $rrd_file = 'netstats-' . $type . '.rrd';
    $rrd_create = '';
    $rrd_update = 'N';
    foreach ($oids as $oid) {
        $oid_ds = truncate($oid, 19, '');
        if ($oid == 'tcpCurrEstab') {
            $rrd_create .= ' DS:' . $oid_ds . ':GAUGE:600:U:4294967295';
            // Gauge32 max value 2^32 = 4294967295
        } else {
            $rrd_create .= ' DS:' . $oid_ds . ':COUNTER:600:U:4294967295';
            // Counter32 max value 2^32 = 4294967295
        }
        $value = is_numeric($data_array[$oid]) ? $data_array[$oid] : 'U';
        $rrd_update .= ':' . $value;
    }
    rrdtool_create($device, $rrd_file, $rrd_create);
    rrdtool_update($device, $rrd_file, $rrd_update);
    foreach ($netstats['graphs'] as $graph) {
        $graphs[$graph] = TRUE;
    }
    print_cli_data(nicecase($type) . " Graphs", implode(" ", $netstats['graphs']), 2);
}
unset($netstats_poll, $netstats, $type, $oids, $oid, $oid_ds, $oids_string, $data, $data_array, $rrd_create, $rrd_file, $rrd_update, $value, $mibs_blacklist);
// EOF
Пример #4
0
             list($bgpLocalAs) = explode("\n", $v_bgpLocalAs);
         }
         break;
     }
 }
 // Some Old IOS-XR (ie 4.3.2) also return BGP4-MIB::bgpLocalAs.0 as '0'.
 if ($vendor_mib === FALSE && $bgpLocalAs === '0' && is_device_mib($device, 'CISCO-BGP4-MIB')) {
     $v_bgpLocalAs = snmp_get($device, 'cbgpLocalAs.0', '-OUQvn', 'CISCO-BGP4-MIB');
     if (is_numeric($v_bgpLocalAs)) {
         $bgpLocalAs = $v_bgpLocalAs;
     }
 }
 if (is_numeric($bgpLocalAs) && $bgpLocalAs != '0') {
     $bgpLocalAs = snmp_dewrap32bit($bgpLocalAs);
     // Dewrap for 32bit ASN
     print_cli_data("Local AS", "AS{$bgpLocalAs} ", 2);
     $cisco_version = FALSE;
     if (is_device_mib($device, 'CISCO-BGP4-MIB')) {
         $cisco_version = 1;
         // Check Cisco cbgpPeer2Table first
         $cisco_peers = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', array(), 'CISCO-BGP4-MIB');
         if (count($cisco_peers) > 0) {
             $cisco_version = 2;
         }
     }
     // Cache data
     print_cli_data_field("Caching", 2);
     if ($cisco_version === 2) {
         echo "CISCO-BGP4-MIB ";
         foreach ($bgp_oids as $bgp_oid) {
             $c_oid = str_replace(array('bgpPeer', 'Identifier'), array('cbgpPeer2', 'RemoteIdentifier'), $bgp_oid);
Пример #5
0
function poll_device($device, $options)
{
    global $config, $device, $polled_devices, $db_stats, $exec_status, $alert_rules, $alert_table, $graphs, $attribs;
    $alert_metrics = array();
    $oid_cache = array();
    $old_device_state = unserialize($device['device_state']);
    $attribs = get_entity_attribs('device', $device['device_id']);
    $pid_info = check_process_run($device);
    // This just clear stalled DB entries
    add_process_info($device);
    // Store process info
    $alert_rules = cache_alert_rules();
    $alert_table = cache_device_alert_table($device['device_id']);
    if (OBS_DEBUG > 1 && (count($alert_rules) || count($alert_table))) {
        print_vars($alert_rules);
        print_vars($alert_table);
    }
    $status = 0;
    $device_start = utime();
    // Start counting device poll time
    print_cli_heading($device['hostname'] . " [" . $device['device_id'] . "]", 1);
    print_cli_data("OS", $device['os'], 1);
    if ($config['os'][$device['os']]['group']) {
        $device['os_group'] = $config['os'][$device['os']]['group'];
        print_cli_data("OS Group", $device['os_group'], 1);
    }
    if (is_numeric($device['last_polled_timetaken'])) {
        print_cli_data("Last poll duration", $device['last_polled_timetaken'] . " seconds", 1);
    }
    print_cli_data("Last Polled", $device['last_polled'], 1);
    print_cli_data("SNMP Version", $device['snmp_version'], 1);
    //unset($poll_update); unset($poll_update_query); unset($poll_separator);
    $update_array = array();
    $host_rrd_dir = $config['rrd_dir'] . "/" . $device['hostname'];
    if (!is_dir($host_rrd_dir)) {
        mkdir($host_rrd_dir);
        echo "Created directory : {$host_rrd_dir}\n";
    }
    $flags = OBS_DNS_ALL;
    if ($device['snmp_transport'] == 'udp6' || $device['snmp_transport'] == 'tcp6') {
        $flags = $flags ^ OBS_DNS_A;
    }
    $attribs['ping_skip'] = isset($attribs['ping_skip']) && $attribs['ping_skip'];
    if ($attribs['ping_skip']) {
        $flags = $flags | OBS_PING_SKIP;
        // Add skip ping flag
    }
    $device['pingable'] = isPingable($device['hostname'], $flags);
    if ($device['pingable']) {
        $device['snmpable'] = isSNMPable($device);
        if ($device['snmpable']) {
            $ping_msg = $attribs['ping_skip'] ? '' : 'PING (' . $device['pingable'] . 'ms) and ';
            print_cli_data("Device status", "Device is reachable by " . $ping_msg . "SNMP (" . $device['snmpable'] . "ms)", 1);
            $status = "1";
            $status_type = '';
        } else {
            print_cli_data("Device status", "Device is not responding to SNMP requests", 1);
            $status = "0";
            $status_type = 'snmp';
        }
    } else {
        print_cli_data("Device status", "Device is not responding to PINGs", 1);
        $status = "0";
        $status_type = 'ping';
    }
    if ($device['status'] != $status) {
        dbUpdate(array('status' => $status), 'devices', 'device_id = ?', array($device['device_id']));
        // dbInsert(array('importance' => '0', 'device_id' => $device['device_id'], 'message' => "Device is " .($status == '1' ? 'up' : 'down')), 'alerts');
        $event_msg = 'Device status changed to ';
        if ($status == '1') {
            // Device Up, Severity Warning (4)
            $event_msg .= 'Up';
            $event_severity = 4;
        } else {
            // Device Down, Severity Error (3)!
            $event_msg .= 'Down';
            $event_severity = 3;
        }
        if ($status_type != '') {
            $event_msg .= ' (' . $status_type . ')';
        }
        log_event($event_msg, $device, 'device', $device['device_id'], $event_severity);
    }
    rrdtool_update_ng($device, 'status', array('status' => $status));
    if (!$attribs['ping_skip']) {
        // Ping response RRD database.
        rrdtool_update_ng($device, 'ping', array('ping' => $device['pingable'] ? $device['pingable'] : 'U'));
    }
    // SNMP response RRD database.
    rrdtool_update_ng($device, 'ping_snmp', array('ping_snmp' => $device['snmpable'] ? $device['snmpable'] : 'U'));
    $alert_metrics['device_status'] = $status;
    $alert_metrics['device_status_type'] = $status_type;
    $alert_metrics['device_ping'] = $device['pingable'];
    // FIXME, when ping skipped, here always 0.001
    $alert_metrics['device_snmp'] = $device['snmpable'];
    if ($status == "1") {
        // Arrays for store and check enabled/disabled graphs
        $graphs = array();
        $graphs_db = array();
        foreach (dbFetchRows("SELECT * FROM `device_graphs` WHERE `device_id` = ?", array($device['device_id'])) as $entry) {
            $graphs_db[$entry['graph']] = isset($entry['enabled']) ? (bool) $entry['enabled'] : TRUE;
        }
        if (!$attribs['ping_skip']) {
            // Enable Ping graphs
            $graphs['ping'] = TRUE;
        }
        // Enable SNMP graphs
        $graphs['ping_snmp'] = TRUE;
        // Run these base modules always and before all other modules!
        $poll_modules = array('system', 'os');
        $mods_disabled_global = array();
        $mods_disabled_device = array();
        $mods_excluded = array();
        if ($options['m']) {
            foreach (explode(',', $options['m']) as $module) {
                $module = trim($module);
                if (in_array($module, $poll_modules)) {
                    continue;
                }
                // Skip already added modules
                if ($module == 'unix-agent') {
                    array_unshift($poll_modules, $module);
                    // Add 'unix-agent' before all
                    continue;
                }
                if (is_file($config['install_dir'] . "/includes/polling/{$module}.inc.php")) {
                    $poll_modules[] = $module;
                }
            }
        } else {
            foreach ($config['poller_modules'] as $module => $module_status) {
                if (in_array($module, $poll_modules)) {
                    continue;
                }
                // Skip already added modules
                if ($attribs['poll_' . $module] || $module_status && !isset($attribs['poll_' . $module])) {
                    if (poller_module_excluded($device, $module)) {
                        $mods_excluded[] = $module;
                        //print_warning("Module [ $module ] excluded for device.");
                        continue;
                    }
                    if ($module == 'unix-agent') {
                        array_unshift($poll_modules, $module);
                        // Add 'unix-agent' before all
                        continue;
                    }
                    if (is_file($config['install_dir'] . "/includes/polling/{$module}.inc.php")) {
                        $poll_modules[] = $module;
                    }
                } elseif (isset($attribs['poll_' . $module]) && !$attribs['poll_' . $module]) {
                    $mods_disabled_device[] = $module;
                    //print_warning("Module [ $module ] disabled on device.");
                } else {
                    $mods_disabled_global[] = $module;
                    //print_warning("Module [ $module ] disabled globally.");
                }
            }
        }
        if (count($mods_excluded)) {
            print_cli_data("Modules Excluded", implode(", ", $mods_excluded), 1);
        }
        if (count($mods_disabled_global)) {
            print_cli_data("Disabled Globally", implode(", ", $mods_disabled_global), 1);
        }
        if (count($mods_disabled_device)) {
            print_cli_data("Disabled Device", implode(", ", $mods_disabled_global), 1);
        }
        if (count($poll_modules)) {
            print_cli_data("Modules Enabled", implode(", ", $poll_modules), 1);
        }
        echo PHP_EOL;
        foreach ($poll_modules as $module) {
            print_debug(PHP_EOL . "including: includes/polling/{$module}.inc.php");
            print_cli_heading("Module Start: %R" . $module . "");
            $m_start = utime();
            include $config['install_dir'] . "/includes/polling/{$module}.inc.php";
            $m_end = utime();
            $m_run = round($m_end - $m_start, 4);
            $device_state['poller_mod_perf'][$module] = $m_run;
            print_cli_data("Module time", number_format($m_run, 4) . "s");
            echo PHP_EOL;
        }
        print_cli_heading($device['hostname'] . " [" . $device['device_id'] . "] completed poller modules at " . date("Y-m-d H:i:s"), 1);
        // Check and update graphs DB
        $graphs_stat = array();
        if (!isset($options['m'])) {
            // Hardcoded poller performance
            $graphs['poller_perf'] = TRUE;
            // Delete not exists graphs from DB (only if poller run without modules option)
            foreach ($graphs_db as $graph => $value) {
                if (!isset($graphs[$graph])) {
                    dbDelete('device_graphs', "`device_id` = ? AND `graph` = ?", array($device['device_id'], $graph));
                    unset($graphs_db[$graph]);
                    $graphs_stat['deleted'][] = $graph;
                }
            }
        }
        // Add or update graphs in DB
        foreach ($graphs as $graph => $value) {
            if (!isset($graphs_db[$graph])) {
                dbInsert(array('device_id' => $device['device_id'], 'graph' => $graph, 'enabled' => $value), 'device_graphs');
                $graphs_stat['added'][] = $graph;
            } else {
                if ($value != $graphs_db[$graph]) {
                    dbUpdate(array('enabled' => $value), 'device_graphs', '`device_id` = ? AND `graph` = ?', array($device['device_id'], $graph));
                    $graphs_stat['updated'][] = $graph;
                } else {
                    $graphs_stat['checked'][] = $graph;
                }
            }
        }
        // Print graphs stats
        foreach ($graphs_stat as $key => $stat) {
            if (count($stat)) {
                print_cli_data('Graphs [' . $key . ']', implode(', ', $stat), 1);
            }
        }
        $device_end = utime();
        $device_run = $device_end - $device_start;
        $device_time = round($device_run, 4);
        $update_array['last_polled'] = array('NOW()');
        $update_array['last_polled_timetaken'] = $device_time;
        $update_array['device_state'] = serialize($device_state);
        #echo("$device_end - $device_start; $device_time $device_run");
        print_cli_data("Poller time", $device_time . " seconds", 1);
        //print_message(PHP_EOL."Polled in $device_time seconds");
        // Only store performance data if we're not doing a single-module poll
        if (!$options['m']) {
            dbInsert(array('device_id' => $device['device_id'], 'operation' => 'poll', 'start' => $device_start, 'duration' => $device_run), 'devices_perftimes');
            rrdtool_update_ng($device, 'perf-poller', array('val' => $device_time));
        }
        if (OBS_DEBUG) {
            echo "Updating " . $device['hostname'] . " - ";
            print_vars($update_array);
            echo " \n";
        }
        $updated = dbUpdate($update_array, 'devices', '`device_id` = ?', array($device['device_id']));
        if ($updated) {
            print_cli_data("Updated Data", implode(", ", array_keys($update_array)), 1);
        }
        $alert_metrics['device_uptime'] = $device['uptime'];
        $alert_metrics['device_rebooted'] = $rebooted;
        // 0 - not rebooted, 1 - rebooted
        $alert_metrics['device_duration_poll'] = $device['last_polled_timetaken'];
        unset($cache_storage);
        // Clear cache of hrStorage ** MAYBE FIXME? ** (ok, later)
        unset($cache);
        // Clear cache (unify all things here?)
    }
    check_entity('device', $device, $alert_metrics);
    echo PHP_EOL;
    // Clean
    del_process_info($device);
    // Remove process info
    unset($alert_metrics);
}
Пример #6
0
    }
}
$oids = array('sysObjectID', 'sysContact', 'sysName', 'sysDescr');
foreach ($oids as $oid) {
    $poll_device[$oid] = snmp_fix_string($poll_device[$oid]);
    //print_vars($poll_device[$oid]);
    if ($poll_device[$oid] != $device[$oid]) {
        $update_array[$oid] = $poll_device[$oid] ? $poll_device[$oid] : array('NULL');
        log_event("{$oid} -> '" . $poll_device[$oid] . "'", $device, 'device', $device['device_id']);
    }
}
print_cli_data('sysObjectID', $poll_device['sysObjectID'], 2);
print_cli_data('snmpEngineID', $poll_device['snmpEngineID'], 2);
print_cli_data('sysDescr', $poll_device['sysDescr'], 2);
print_cli_data('sysName', $poll_device['sysName'], 2);
print_cli_data('Location', $poll_device['sysLocation'], 2);
$geo_detect = FALSE;
if ($device['location'] != $poll_device['sysLocation']) {
    // Reset geolocation when location changes - triggers re-geolocation
    $geo_detect = TRUE;
    $update_array['location'] = $poll_device['sysLocation'];
    log_event("sysLocation changed: '" . $device['location'] . "' -> '" . $poll_device['sysLocation'] . "'", $device, 'device', $device['device_id']);
}
if ($config['geocoding']['enable']) {
    $db_version = get_db_version();
    // Need for detect old geo DB schema
    if ($db_version < 169) {
        // FIXME. remove this part in r7000
        if ($geo_detect) {
            $update_array['location_lat'] = array('NULL');
            $update_array['location_lon'] = array('NULL');
Пример #7
0
            unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
            $rrdfile = "ipSystemStats-{$af}.rrd";
            $rrdupdate = "N";
            foreach ($oids as $oid) {
                $oid_ds = str_replace("ipSystemStats", "", $oid);
                $oid_ds = truncate($oid_ds, 19, '');
                $rrd_create .= " DS:{$oid_ds}:COUNTER:600:U:100000000000";
                if (strstr($stats[$oid], "No") || strstr($stats[$oid], "d") || strstr($stats[$oid], "s")) {
                    $stats[$oid] = "0";
                }
                $rrdupdate .= ":" . $stats[$oid];
                // Update StatsD/Carbon
                if ($config['statsd']['enable'] == TRUE && !strpos($oid, "HC")) {
                    StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'system' . '.' . $oid, $stats[$oid]);
                }
            }
            rrdtool_create($device, $rrdfile, $rrd_create);
            rrdtool_update($device, $rrdfile, $rrdupdate);
            unset($rrdupdate, $rrd_create);
            // FIXME per-AF?
            $graphs['ipsystemstats_' . $af] = TRUE;
            $graphs['ipsystemstats_' . $af . '_frag'] = TRUE;
            $show_graphs[] = 'ipsystemstats_' . $af;
            $show_graphs[] = 'ipsystemstats_' . $af . '_frag';
        }
        echo PHP_EOL;
        print_cli_data("Graphs", implode($show_graphs, " "), 2);
    }
}
unset($show_graphs);
// EOF
Пример #8
0
        dbDelete('ipsec_tunnels', '`tunnel_id` =  ?', array($t['tunnel_id']));
    }
}
$t_db_count = count($t_db);
$device_context = $device;
if (!$t_db_count) {
    // Set retries to 0 for speedup first walking, only if previously polling also empty (DB empty)
    $device_context['snmp_retries'] = 0;
}
print_cli_data("Collecting", "CISCO-IPSEC-FLOW-MONITOR-MIB::cikeTunnelEntry", 3);
$ike_poll = snmpwalk_cache_oid($device_context, 'cikeTunnelEntry', array(), 'CISCO-IPSEC-FLOW-MONITOR-MIB');
unset($device_context);
if ($GLOBALS['snmp_status']) {
    print_cli_data("Collecting", "CISCO-IPSEC-FLOW-MONITOR-MIB::cipSecTunnelEntry", 3);
    $ipsec_poll = snmpwalk_cache_oid($device, 'cipSecTunnelEntry', array(), 'CISCO-IPSEC-FLOW-MONITOR-MIB');
    print_cli_data("Collecting", "CISCO-IPSEC-FLOW-MONITOR-MIB::cipSecEndPtEntry", 3);
    $ipsec_endpt_poll = snmpwalk_cache_twopart_oid($device, 'cipSecEndPtEntry', array(), 'CISCO-IPSEC-FLOW-MONITOR-MIB');
    //print_cli_data("Collecting", "CISCO-IPSEC-FLOW-MONITOR-MIB::cikePeerCorrTable", 3);
    //$ike_peer_poll = snmpwalk_cache_oid($device, 'cikePeerCorrTable', array(), 'CISCO-IPSEC-FLOW-MONITOR-MIB', NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
}
// FIX for cisco issue, not correct IKE index
// https://bst.cloudapps.cisco.com/bugsearch/bug/CSCvb16714/
$ike_poll_index = array();
foreach ($ike_poll as $index => $entry) {
    foreach (array('cikeTunLocalAddr', 'cikeTunRemoteAddr') as $oid) {
        $entry[$oid] = hex2ip($entry[$oid]);
        $ike_poll[$index][$oid] = $entry[$oid];
    }
    $ike_poll_index[$entry['cikeTunLocalAddr']][$entry['cikeTunRemoteAddr']] = $index;
}
/* Yah, I create this for conceptual converting index into correct values, but not need this anyway (mike) :) */
Пример #9
0
function print_cli_table($table_rows, $table_header = array(), $descr = NULL)
{
    if (!is_array($table_rows)) {
        print_error("print_cli_table() argument {$table_rows} should be an array. Please report this error to developers.");
        return;
    }
    if (OBS_QUIET) {
        return;
    }
    if (!cli_is_piped() || OBS_DEBUG) {
        $count_rows = count($table_rows);
        if ($count_rows == 0) {
            return;
        }
        if (strlen($descr)) {
            print_cli_data($descr, '', 3);
        }
        $table = new \cli\Table();
        $count_header = count($table_header);
        if ($count_header) {
            $table->setHeaders($table_header);
        }
        $table->setRows($table_rows);
        $table->display();
        echo PHP_EOL;
    } else {
        print_cli_data("Notice", "Table output suppressed due to piped output." . PHP_EOL);
    }
}
Пример #10
0
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage discovery
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
// Redetect OS if necessary (controlled by discover_device function)
if ($detect_os) {
    $os = get_device_os($device);
    if ($os != $device['os']) {
        $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);
Пример #11
0
<?php

/* Observium Network Management and Monitoring System
 *
 * @package    observium
 * @subpackage poller
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
global $graphs;
$count = dbFetchCell('SELECT COUNT(*) FROM `status` WHERE `device_id` = ? AND `status_deleted` = ?;', array($device['device_id'], '0'));
print_cli_data("Status Count", $count);
if ($count > 0) {
    // Cache data for use by polling modules
    foreach (dbFetchRows("SELECT DISTINCT `status_type` FROM `status` WHERE `device_id` = ? AND `poller_type` = 'snmp' AND `status_deleted` = '0';", array($device['device_id'])) as $s_type) {
        if (is_array($config['sensor']['cache_oids'][$s_type['sensor_type']])) {
            echo 'Caching: ' . $s_type['sensor_type'] . ' ';
            // FIXME : This needs to be a function.
            foreach ($config['sensor']['cache_oids'][$s_type['sensor_type']] as $oid_to_cache) {
                if (!$oids_cached[$oid_to_cache]) {
                    echo $oid_to_cache . ' ';
                    $oids_cached[$oid_to_cache] = TRUE;
                    $oid_cache = snmpwalk_numericoids($device, $oid_to_cache, $oid_cache);
                    $oids_cached[$oid_to_cache] = TRUE;
                }
            }
            //echo(PHP_EOL);
        }
    }
    global $table_rows;
    $table_rows = array();
Пример #12
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage poller
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
$fnSysVersion = snmp_get($device, 'fgSysVersion.0', '-Ovq', 'FORTINET-FORTIGATE-MIB');
$serial = snmp_get($device, 'fnSysSerial.0', '-Ovq', 'FORTINET-CORE-MIB');
$version = preg_replace('/(.+),(.+),(.+)/', "\\1||\\2||\\3", $fnSysVersion);
list($version, $features) = explode('||', $version);
$hardware = rewrite_definition_hardware($device, $poll_device['sysObjectID']);
$fn_type = rewrite_definition_type($device, $poll_device['sysObjectID']);
if (!empty($fn_type)) {
    $type = $fn_type;
}
// FIXME, move to graphs module
$sessions = snmp_get($device, 'fgSysSesCount.0', '-Ovq', 'FORTINET-FORTIGATE-MIB');
if (is_numeric($sessions)) {
    rrdtool_update_ng($device, 'fortigate-sessions', array('sessions' => $sessions));
    print_cli_data('Firewall Sessions', $sessions);
    $graphs['fortigate_sessions'] = TRUE;
}
// EOF
Пример #13
0
/**
 * Print an discovery/poller module stats
 *
 * @global array $GLOBALS['module_stats']
 * @param array $device Device array
 * @param string $module Module name
 */
function print_module_stats($device, $module)
{
    $log_event = FALSE;
    $stats_msg = array();
    foreach (array('added', 'updated', 'deleted', 'unchanged') as $key) {
        if ($GLOBALS['module_stats'][$module][$key]) {
            $stats_msg[] = (int) $GLOBALS['module_stats'][$module][$key] . ' ' . $key;
            if ($key != 'unchanged') {
                $log_event = TRUE;
            }
        }
    }
    if (count($GLOBALS['module_stats'][$module])) {
        echo PHP_EOL;
    }
    if (count($stats_msg)) {
        print_cli_data("Changes", implode(', ', $stats_msg));
    }
    if ($GLOBALS['module_stats'][$module]['time']) {
        print_cli_data("Duration", $GLOBALS['module_stats'][$module]['time'] . "s");
    }
    if ($log_event) {
        log_event(nicecase($module) . ': ' . implode(', ', $stats_msg) . '.', $device, 'device', $device['device_id']);
    }
}
Пример #14
0
$end = utime();
$run = $end - $start;
$discovery_time = substr($run, 0, 5);
if ($discovered_devices) {
    dbInsert(array('type' => 'discover', 'doing' => $doing, 'start' => $start, 'duration' => $discovery_time, 'devices' => $discovered_devices), 'perf_times');
    if (is_numeric($doing)) {
        $doing = $device['hostname'];
    }
    // Single device ID convert to hostname for log
} else {
    if (!isset($options['q']) && !$options['u']) {
        print_warning("WARNING: 0 devices discovered." . ($options['h'] != 'new' ? " Did you specify a device that does not exist?" : ''));
    }
}
$string = $argv[0] . ": {$doing} - {$discovered_devices} devices discovered in {$discovery_time} secs";
print_debug($string);
if (!isset($options['q'])) {
    if ($config['snmp']['hide_auth']) {
        print_debug("NOTE, \$config['snmp']['hide_auth'] is set to TRUE, snmp community and snmp v3 auth hidden from debug output.");
    }
    print_cli_data('Devices Discovered', $discovered_devices, 0);
    print_cli_data('Discovery Time', $discovery_time . " secs", 0);
    print_cli_data('Memory usage', formatStorage(memory_get_usage(TRUE), 2, 4) . ' (peak: ' . formatStorage(memory_get_peak_usage(TRUE), 2, 4) . ')', 0);
    print_cli_data('MySQL Usage', 'Cell[' . ($db_stats['fetchcell'] + 0) . '/' . round($db_stats['fetchcell_sec'] + 0, 3) . 's]' . ' Row[' . ($db_stats['fetchrow'] + 0) . '/' . round($db_stats['fetchrow_sec'] + 0, 3) . 's]' . ' Rows[' . ($db_stats['fetchrows'] + 0) . '/' . round($db_stats['fetchrows_sec'] + 0, 3) . 's]' . ' Column[' . ($db_stats['fetchcol'] + 0) . '/' . round($db_stats['fetchcol_sec'] + 0, 3) . 's]' . ' Update[' . ($db_stats['update'] + 0) . '/' . round($db_stats['update_sec'] + 0, 3) . 's]' . ' Insert[' . ($db_stats['insert'] + 0) . '/' . round($db_stats['insert_sec'] + 0, 3) . 's]' . ' Delete[' . ($db_stats['delete'] + 0) . '/' . round($db_stats['delete_sec'] + 0, 3) . 's]', 0);
    foreach ($GLOBALS['rrdtool'] as $cmd => $data) {
        $rrd_times[] = $cmd . "[" . $data['count'] . "/" . round($data['time'], 3) . "s]";
    }
    print_cli_data('RRDTool Usage', implode(" ", $rrd_times), 0);
}
logfile($string);
// EOF
Пример #15
0
    print_cli_data('Poller Time', $poller_time . " secs", 0);
    print_cli_data('Memory usage', formatStorage(memory_get_usage(TRUE), 2, 4) . ' (peak: ' . formatStorage(memory_get_peak_usage(TRUE), 2, 4) . ')', 0);
    $mysql_time = 0;
    foreach ($db_stats as $cmd => $count) {
        if (isset($db_stats[$cmd . '_sec'])) {
            $mysql_times[] = ucfirst(str_replace("fetch", "", $cmd)) . "[" . $count . "/" . round($db_stats[$cmd . '_sec'], 3) . "s]";
            $mysql_time += $db_stats[$cmd . '_sec'];
        }
    }
    print_cli_data('MySQL Usage', implode(" ", $mysql_times) . ' (' . round($mysql_time, 3) . 's ' . round($mysql_time / $poller_time * 100, 3) . '%)', 0);
    $rrd_time = 0;
    foreach ($GLOBALS['rrdtool'] as $cmd => $data) {
        $rrd_times[] = $cmd . "[" . $data['count'] . "/" . round($data['time'], 3) . "s]";
        $rrd_time += $data['time'];
    }
    print_cli_data('RRDTool Usage', implode(" ", $rrd_times) . ' (' . round($rrd_time, 3) . 's ' . round($rrd_time / $poller_time * 100, 3) . '%)', 0);
    $snmp_time = 0;
    foreach ($GLOBALS['snmp_stats'] as $cmd => $data) {
        $snmp_times[] = $cmd . "[" . $data['count'] . "/" . round($data['time'], 3) . "s]";
        $snmp_time += $data['time'];
    }
    print_cli_data('SNMP Usage', implode(" ", $snmp_times) . ' (' . round($snmp_time, 3) . 's ' . round($snmp_time / $poller_time * 100, 3) . '%)', 0);
}
logfile($string);
rrdtool_pipe_close($rrd_process, $rrd_pipes);
unset($config);
// Remove this for testing
#print_vars(get_defined_vars());
echo "\n";
print_r($runtime_stats);
// EOF
Пример #16
0
<?php

/* Observium Network Management and Monitoring System
 *
 * @package    observium
 * @subpackage poller
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
global $graphs;
$count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `sensor_deleted` = ?;', array($device['device_id'], '0'));
print_cli_data("Sensor Count", $count);
if ($count > 0) {
    // Cache data for use by polling modules
    foreach (dbFetchRows("SELECT `sensor_type` FROM `sensors` WHERE `device_id` = ? AND `poller_type` = 'snmp' AND `sensor_deleted` = '0' GROUP BY `sensor_type`", array($device['device_id'])) as $s_type) {
        if (is_array($config['sensor']['cache_oids'][$s_type['sensor_type']])) {
            echo 'Caching: ' . $s_type['sensor_type'] . ' ';
            foreach ($config['sensor']['cache_oids'][$s_type['sensor_type']] as $oid_to_cache) {
                if (!$oids_cached[$oid_to_cache]) {
                    echo $oid_to_cache . ' ';
                    $oids_cached[$oid_to_cache] = TRUE;
                    $oid_cache = snmpwalk_numericoids($device, $oid_to_cache, $oid_cache);
                    $oids_cached[$oid_to_cache] = TRUE;
                }
            }
            echo PHP_EOL;
        }
    }
    global $table_rows;
    $table_rows = array();
    // Call poll_sensor for each sensor type that we support.
Пример #17
0
        print_cli_data("OS Poller", 'Group', 2);
        include $config['install_dir'] . "/includes/polling/os/" . $device['os_group'] . ".inc.php";
    } else {
        print_cli_data("OS Poller", '%rGeneric%w', 2);
    }
}
print_cli_data("Hardware", $hardware ?: "%b<empty>%n");
print_cli_data("Version", $version ?: "%b<empty>%n");
print_cli_data("Features", $features ?: "%b<empty>%n");
print_cli_data("Serial", $serial ?: "%b<empty>%n");
print_cli_data("Asset", $asset_tag ?: "%b<empty>%n");
echo PHP_EOL;
foreach ($os_additional_info as $header => $entries) {
    print_cli_heading($header, 3);
    foreach ($entries as $field => $entry) {
        print_cli_data($field, $entry, 3);
    }
    echo PHP_EOL;
}
// Fields notified in event log
$update_fields = array('version', 'features', 'hardware', 'serial', 'kernel', 'distro', 'distro_ver', 'arch', 'asset_tag');
// Log changed variables
foreach ($update_fields as $field) {
    if (isset(${$field})) {
        ${$field} = snmp_fix_string(${$field});
    }
    // Fix unprintable chars
    if ((isset(${$field}) || strlen($device[$field])) && ${$field} != $device[$field]) {
        $update_array[$field] = ${$field};
        log_event(nicecase($field) . " -> " . $update_array[$field], $device, 'device', $device['device_id']);
    }
Пример #18
0
function process_notifications($device = NULL, $types = NULL)
{
    global $config;
    if (empty($types)) {
        $types = array('alert', 'syslog');
    }
    $endpoints_result = array();
    foreach ($types as $notification_type) {
        $sql = 'SELECT * FROM `notifications_queue` WHERE `aca_type` = ?';
        $params = array($notification_type);
        switch ($notification_type) {
            case 'alert':
            case 'syslog':
                // Alerts/syslog required device_id
                $sql .= ' AND `device_id` = ?';
                $params[] = $device['device_id'];
                break;
            case 'web':
                // Currently not used
                break;
        }
        foreach (dbFetchRows($sql, $params) as $notification) {
            // Recheck if current notification is locked
            $locked = dbFetchCell('SELECT `notification_locked` FROM `notifications_queue` WHERE `notification_id` = ?', array($notification['notification_id']));
            //ALTER TABLE `notifications_queue` ADD `notification_locked` BOOLEAN NOT NULL DEFAULT FALSE AFTER `notification_entry`;
            if ($locked || $locked === NULL || $locked === FALSE) {
                // Notification already processed by other alerter or has already been sent
                continue;
            } else {
                // Lock current notification
                dbUpdate(array('notification_locked' => 1), 'notifications_queue', '`notification_id` = ?', array($notification['notification_id']));
            }
            $notification_count = 0;
            $transports = json_decode($notification['endpoints'], TRUE);
            if (!empty($transports)) {
                $message_tags = json_decode($notification['message_tags'], TRUE);
                $message_graphs = json_decode($notification['message_graphs'], TRUE);
                if (is_array($message_graphs) && count($message_graphs)) {
                    $message_tags['ENTITY_GRAPHS_ARRAY'] = $message_graphs;
                }
                if (isset($message_tags['TIMESTAMP']) && empty($message_tags['DURATION'])) {
                    $message_tags['DURATION'] = formatUptime(time() - strtotime($message_tags['TIMESTAMP'])) . ' (' . $message_tags['TIMESTAMP'] . ')';
                }
                foreach ($transports as $method => $endpoints) {
                    if (isset($GLOBALS['config']['alerts']['disable'][$method]) && $GLOBALS['config']['alerts']['disable'][$method]) {
                        $endpoints_result[$method] = 'disabled';
                        continue;
                    }
                    // Skip if method disabled globally
                    foreach ($endpoints as $endpoint) {
                        $method_include = $GLOBALS['config']['install_dir'] . '/includes/alerting/' . $method . '.inc.php';
                        if (is_file($method_include)) {
                            print_cli_data("Notifying", "[" . $method . "] " . $endpoint['contact_descr'] . ": " . $endpoint['contact_endpoint']);
                            // Split out endpoint data as stored JSON in the database into array for use in transport
                            // The original string also remains available as the contact_endpoint key
                            foreach (json_decode($endpoint['contact_endpoint']) as $field => $value) {
                                $endpoint[$field] = $value;
                            }
                            include $method_include;
                            // FIXME check success
                            // FIXME log notification + success/failure!
                            if ($notify_status['success']) {
                                $endpoints_result[$method] = 'ok';
                                $notification_count++;
                            } else {
                                $endpoints_result[$method] = 'false';
                            }
                        } else {
                            $endpoints_result[$method] = 'missing';
                            print_cli_data("Missing include", $method_include);
                        }
                    }
                }
            }
            // Remove notification from queue,
            // currently in any case, lifetime, added time and result status is ignored!
            switch ($notification_type) {
                case 'alert':
                    if ($notification_count) {
                        dbUpdate(array('notified' => 1), 'alert_log', '`event_id` = ?', array($notification['log_id']));
                    }
                    break;
                case 'syslog':
                    if ($notification_count) {
                        dbUpdate(array('notified' => 1), 'syslog_alerts', '`lal_id` = ?', array($notification['log_id']));
                    }
                    break;
                case 'web':
                    // Currently not used
                    break;
            }
            dbDelete('notifications_queue', '`notification_id` = ?', array($notification['notification_id']));
        }
    }
    return $endpoints_result;
}