Example #1
0
 // If not has standard IF-MIB table, use NETAPP specific tables
 $mib = 'NETAPP-MIB';
 //NETAPP-MIB::netifDescr.11 = STRING: "vega-01:MGMT_PORT_ONLY e0P"
 //NETAPP-MIB::netifDescr.12 = STRING: "vega-01:MGMT_PORT_ONLY e0M"
 //NETAPP-MIB::netifDescr.15 = STRING: "vega-01:a0m"
 //NETAPP-MIB::netifDescr.16 = STRING: "vega-01:a0m-40"
 print_cli($mib . '::netifDescr ');
 $netif_stat = snmpwalk_cache_oid($device, 'netifDescr', array(), $mib);
 if (OBS_DEBUG > 1 && count($netif_stat)) {
     print_vars($netif_stat);
 }
 $flags = OBS_SNMP_ALL ^ OBS_QUOTES_STRIP;
 $netport_stat = snmpwalk_cache_twopart_oid($device, 'netportLinkState', array(), $mib, NULL, $flags);
 print_cli($mib . '::netportLinkState ');
 $netport_stat = snmpwalk_cache_twopart_oid($device, 'netportType', $netport_stat, $mib, NULL, $flags);
 print_cli($mib . '::netportType ');
 if (OBS_DEBUG > 1 && count($netport_stat)) {
     print_vars($netport_stat);
 }
 $mib_config =& $config['mibs'][$mib]['ports']['oids'];
 // Attach MIB options/translations
 //print_vars($mib_config);
 // Now rewrite to standard IF-MIB array
 foreach ($netif_stat as $ifIndex => $port) {
     list($port['netportNode'], $port['netportPort']) = explode(':', $port['netifDescr'], 2);
     $port['netportPort'] = str_ireplace('MGMT_PORT_ONLY ', '', $port['netportPort']);
     if (isset($netport_stat[$port['netportNode']][$port['netportPort']])) {
         // ifDescr
         $oid = 'ifDescr';
         $port[$oid] = $port[$mib_config[$oid]['oid']];
         $port_stats[$ifIndex][$oid] = $port[$oid];
Example #2
0
function print_cli_data_field($field, $level = 2)
{
    if (OBS_QUIET) {
        return;
    }
    $level_colours = array('0' => '%W', '1' => '%g', '2' => '%c', '3' => '%p');
    // print_cli(str_repeat("  ", $level) . $level_colours[$level]."  o %W".str_pad($field, 20). "%n ");
    print_cli($level_colours[$level] . " o %W" . str_pad($field, 20) . "%n ");
}
Example #3
0
include "includes/include-dir-mib.inc.php";
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));
Example #4
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
Example #5
0
       // ifXEntry
       'ifName', 'ifAlias', 'ifHighSpeed', 'ifPromiscuousMode', 'ifConnectorPresent',
     );
     */
     $data_oids_netport = array('ifType', 'ifMtu', 'ifAdminStatus', 'ifOperStatus', 'ifHighSpeed', 'ifDuplex', 'ifVlan');
     $flags = OBS_SNMP_ALL ^ OBS_QUOTES_STRIP;
     $netport_stat = array();
     foreach ($data_oids_netport as $oid) {
         $netport_oid = $mib_config[$oid]['oid'];
         print_cli($mib . '::' . $netport_oid . ' ');
         $netport_stat = snmpwalk_cache_twopart_oid($device, $netport_oid, $netport_stat, $mib, NULL, $flags);
     }
     // disable hex to string conversion for ifPhysAddress
     $flags = $flags | OBS_SNMP_HEX;
     $netport_oid = $mib_config['ifPhysAddress']['oid'];
     print_cli($mib . '::' . $netport_oid . ' ');
     $netport_stat = snmpwalk_cache_twopart_oid($device, $netport_oid, $netport_stat, $mib, NULL, $flags);
     if (OBS_DEBUG > 1 && count($netport_stat)) {
         print_vars($netport_stat);
     }
 }
 // Now rewrite to standard IF-MIB array
 foreach ($netif_stat as $ifIndex => $port) {
     list($port['netportNode'], $port['netportPort']) = explode(':', $port['netifDescr'], 2);
     $port['netportPort'] = str_ireplace('MGMT_PORT_ONLY ', '', $port['netportPort']);
     if (isset($netport_stat[$port['netportNode']][$port['netportPort']])) {
         // ifDescr
         $oid = 'ifDescr';
         $port[$oid] = $port[$mib_config[$oid]['oid']];
         $port_stats[$ifIndex][$oid] = $port[$oid];
         // ifName, ifAlias
Example #6
0
/**
 * This function echoes text with specific styles (different for cli and web output).
 *
 * @param string $text
 * @param string $type Supported types: default, success, warning, error, debug
 * @param boolean $strip Stripe special characters (for web) or html tags (for cli)
 */
function print_message($text, $type = '', $strip = TRUE)
{
    global $config;
    // Do nothing if input text not any string (like NULL, array or other). (Empty string '' still printed).
    if (!is_string($text) && !is_numeric($text)) {
        return NULL;
    }
    $type = trim(strtolower($type));
    switch ($type) {
        case 'success':
            $color = array('cli' => '%g', 'cli_color' => FALSE, 'class' => 'alert alert-success');
            // green
            $icon = 'oicon-tick-circle';
            break;
        case 'warning':
            $color = array('cli' => '%b', 'cli_color' => FALSE, 'class' => 'alert alert-warning');
            // yellow
            $icon = 'oicon-bell';
            break;
        case 'error':
            $color = array('cli' => '%r', 'cli_color' => FALSE, 'class' => 'alert alert-danger');
            // red
            $icon = 'oicon-exclamation-red';
            break;
        case 'debug':
            $color = array('cli' => '%r', 'cli_color' => FALSE, 'class' => 'alert alert-danger');
            // red
            $icon = 'oicon-exclamation-red';
            break;
        case 'color':
            $color = array('cli' => '', 'cli_color' => TRUE, 'class' => 'alert alert-info');
            // blue
            $icon = 'oicon-information';
            break;
        case 'console':
            // This is special type used nl2br conversion for display console messages on WUI with correct line breaks
            $color = array('cli' => '', 'cli_color' => TRUE, 'class' => 'alert alert-suppressed');
            // purple
            $icon = 'oicon-information';
            break;
        default:
            $color = array('cli' => '%W', 'cli_color' => FALSE, 'class' => 'alert alert-info');
            // blue
            $icon = 'oicon-information';
            break;
    }
    if (is_cli()) {
        if ($strip) {
            $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
            // Convert special HTML entities back to characters
            $text = str_ireplace(array('<br />', '<br>', '<br/>'), PHP_EOL, $text);
            // Convert html <br> to into newline
            $text = strip_tags($text);
        }
        if ($type == 'debug' && !$color['cli_color']) {
            // For debug just echo message.
            echo $text . PHP_EOL;
        } else {
            print_cli($color['cli'] . $text . '%n' . PHP_EOL, $color['cli_color']);
        }
    } else {
        if ($text === '') {
            return NULL;
        }
        // Do not web output if the string is empty
        if ($strip) {
            if ($text == strip_tags($text)) {
                // Convert special characters to HTML entities only if text not have html tags
                $text = escape_html($text);
            }
            if ($color['cli_color']) {
                // Replace some Pear::Console_Color2 color codes with html styles
                $replace = array('%', '</span>', '<span class="label label-warning">', '<span class="label label-success">', '<span class="label label-danger">', '<span class="label label-primary">', '<span class="label label-info">', '<span class="label label-default">', '<span class="label label-default" style="color:black;">', '<span style="font-weight: bold;">', '<span style="text-decoration: underline;">');
            } else {
                $replace = array('%', '');
            }
            $text = str_replace(array('%%', '%n', '%y', '%g', '%r', '%b', '%c', '%W', '%k', '%_', '%U'), $replace, $text);
        }
        $msg = PHP_EOL . '    <div class="' . $color['class'] . '">';
        if ($type != 'warning' && $type != 'error') {
            $msg .= '<button type="button" class="close" data-dismiss="alert">&times;</button>';
        }
        if ($type == 'console') {
            $text = nl2br(trim($text));
            // Convert newline to <br /> for console messages with line breaks
        }
        $msg .= '
      <div>' . $text . '</div>
    </div>' . PHP_EOL;
        echo $msg;
    }
}
Example #7
0
                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}");
                    discover_status($device, $entry['oid_num'], "{$oid}.{$index}", $entry['type'], $entry['descr'], $value, array('entPhysicalClass' => $entry['measured']));
                }
            }
            print_cli('] ');
        }
        print_cli('] ');
    }
}
if (OBS_DEBUG > 1 && count($valid['sensor'])) {
    print_vars($valid['sensor']);
}
foreach (array_keys($config['sensor_types']) as $type) {
    check_valid_sensors($device, $type, $valid['sensor']);
}
if (OBS_DEBUG > 1 && count($valid['status'])) {
    print_vars($valid['status']);
}
check_valid_status($device, $GLOBALS['valid']['status']);
echo PHP_EOL;
// EOF
Example #8
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
}