// Some Unixes return hrSystemUptime as an integer count of ten millisecond ticks instead of the
     // as a Timetick type
     if (strstr($hrSystemUptime, 'Wrong Type')) {
         // HOST-RESOURCES-MIB::hrSystemUptime.0 = Wrong Type (should be Timeticks): 1632295600
         list($type_msg, $ten_ms) = explode(":", $hrSystemUptime);
         $uptime = $ten_ms / 100;
         echo "Found Wrong type: interpreting as seconds instead of timeticks ({$uptime} seconds)\n";
         $uptime_msg = "Using integer SNMP Agent hrSystemUptime";
     } else {
         // HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (63050465) 7 days, 7:08:24.65
         $uptime = timeticks_to_sec($hrSystemUptime);
         $uptime_msg = "Using SNMP Agent hrSystemUptime";
     }
 } else {
     // SNMPv2-MIB::sysUpTime.0 = Timeticks: (2542831) 7:03:48.31
     $uptime = timeticks_to_sec($poll_device['sysUpTime']);
     $uptime_msg = "Using SNMP Agent sysUpTime";
     // Last check snmpEngineTime and fix if needed uptime (sysUpTime 68 year rollover issue)
     // SNMP-FRAMEWORK-MIB::snmpEngineTime.0 = INTEGER: 72393514 seconds
     $snmpEngineTime = snmp_get($device, "snmpEngineTime.0", "-OUqv", "SNMP-FRAMEWORK-MIB", mib_dirs());
     if ($device['os'] == 'aos' && strlen($snmpEngineTime) > 8) {
         // Some Alcatel have bug with snmpEngineTime
         // http://jira.observium.org/browse/OBSERVIUM-763
         $snmpEngineTime = 0;
     } else {
         if (is_numeric($snmpEngineTime) && $snmpEngineTime > 0 && $snmpEngineTime > $uptime) {
             $polled = time();
             $uptime = $snmpEngineTime;
             $uptime_msg = "Using SNMP Agent snmpEngineTime";
         }
     }
            // Additional data for ICMP jitter
            $sla_poll = snmpwalk_cache_multi_oid($device, "rttMonLatestIcmpJitterOperEntry", $sla_poll, 'CISCO-RTTMON-ICMP-MIB');
            break;
    }
}
// Uptime offset for timestamps
$uptime = timeticks_to_sec($poll_device['sysUpTime']);
$uptime_offset = time() - intval($uptime) / 100;
/// WARNING. System timezone BOMB
foreach ($sla_poll as $sla_index => $entry) {
    if (!isset($entry['rttMonLatestRttOperCompletionTime']) && !isset($entry['rttMonLatestRttOperSense'])) {
        // Skip additional multiindex entries from table
        continue;
    }
    // Convert timestamps to unixtime
    $entry['UnixTime'] = intval(timeticks_to_sec($entry['rttMonLatestRttOperTime']) / 100 + $uptime_offset);
    $sla_state = array('rtt_value' => $entry['rttMonLatestRttOperCompletionTime'], 'rtt_sense' => $entry['rttMonLatestRttOperSense'], 'rtt_unixtime' => $entry['UnixTime']);
    // SLA event
    $sla_state['rtt_event'] = $sla_states[$sla_state['rtt_sense']]['event'];
    switch ($sla_db[$mib_lower][$sla_index]['rtt_type']) {
        case 'jitter':
            if (is_numeric($entry['rttMonLatestJitterOperNumOfRTT'])) {
                $sla_state['rtt_minimum'] = $entry['rttMonLatestJitterOperRTTMin'];
                $sla_state['rtt_maximum'] = $entry['rttMonLatestJitterOperRTTMax'];
                $sla_state['rtt_success'] = $entry['rttMonLatestJitterOperNumOfRTT'];
                $sla_state['rtt_loss'] = $entry['rttMonLatestJitterOperPacketLossSD'] + $entry['rttMonLatestJitterOperPacketLossDS'];
            }
            break;
        case 'icmpjitter':
            if (is_numeric($entry['rttMonLatestIcmpJitterNumRTT'])) {
                $sla_state['rtt_minimum'] = $entry['rttMonLatestIcmpJitterRTTMin'];
Example #3
0
        $value = $entry['upsHighPrecBatteryCapacity'];
        $limits = array('limit_low' => 15, 'limit_low_warn' => 30);
        discover_sensor($valid['sensor'], 'capacity', $device, $oid, "upsHighPrecBatteryCapacity.{$index}", 'apc', $descr, $scale, $value, $limits);
    } elseif ($entry['upsAdvBatteryCapacity'] && $entry['upsAdvBatteryCapacity'] != -1) {
        $oid = ".1.3.6.1.4.1.318.1.1.1.2.2.1.{$index}";
        $value = $entry['upsAdvBatteryCapacity'];
        $limits = array('limit_low' => 15, 'limit_low_warn' => 30);
        discover_sensor($valid['sensor'], 'capacity', $device, $oid, "upsAdvBatteryCapacity.{$index}", 'apc', $descr, 1, $value, $limits);
    }
    $descr = "Battery Runtime Remaining";
    if ($entry['upsAdvBatteryRunTimeRemaining']) {
        // Runtime stores data in minuntes
        $oid = ".1.3.6.1.4.1.318.1.1.1.2.2.3.{$index}";
        $value = timeticks_to_sec($entry['upsAdvBatteryRunTimeRemaining']);
        $limit_low = snmp_get($device, "upsAdvConfigLowBatteryRunTime.{$index}", "-Ovq", "PowerNet-MIB");
        $limit_low = timeticks_to_sec($limit_low);
        $limits = array('limit_low' => is_numeric($limit_low) ? $limit_low * $scale_min : 2);
        discover_sensor($valid['sensor'], 'runtime', $device, $oid, "upsAdvBatteryRunTimeRemaining.{$index}", 'apc', $descr, $scale_min, $value, $limits);
    }
    $descr = "Battery Replace";
    if ($entry['upsAdvBatteryReplaceIndicator']) {
        $oid = ".1.3.6.1.4.1.318.1.1.1.2.2.4.{$index}";
        if ($entry['upsBasicBatteryLastReplaceDate']) {
            $descr .= ' (last ' . reformat_us_date($entry['upsBasicBatteryLastReplaceDate']) . ')';
        }
        discover_status($device, $oid, "upsAdvBatteryReplaceIndicator.{$index}", 'powernet-upsbatteryreplace-state', $descr, $entry['upsAdvBatteryReplaceIndicator'], array('entPhysicalClass' => 'other'));
    }
}
// State sensors
// PowerNet-MIB::upsAdvTestDiagnosticSchedule.0 = INTEGER: biweekly(2)
// PowerNet-MIB::upsAdvTestDiagnostics.0 = INTEGER: noTestDiagnostics(1)
Example #4
0
function poll_sensor($device, $class, $unit, &$oid_cache)
{
    global $config, $agent_sensors, $ipmi_sensors, $graphs, $table_rows;
    $sql = "SELECT * FROM `sensors`";
    $sql .= " LEFT JOIN `sensors-state` USING(`sensor_id`)";
    $sql .= " WHERE `sensor_class` = ? AND `device_id` = ?";
    foreach (dbFetchRows($sql, array($class, $device['device_id'])) as $sensor_db) {
        $sensor_poll = array();
        //print_cli_heading("Sensor: ".$sensor_db['sensor_descr'], 3);
        if (OBS_DEBUG) {
            echo "Checking (" . $sensor_db['poller_type'] . ") {$class} " . $sensor_db['sensor_descr'] . " ";
            print_r($sensor_db);
        }
        if ($sensor_db['poller_type'] == "snmp") {
            # if ($class == "temperature" && $device['os'] == "papouch")
            // Why all temperature?
            if ($class == "temperature") {
                for ($i = 0; $i < 5; $i++) {
                    // Take value from $oid_cache if we have it, else snmp_get it
                    if (is_numeric($oid_cache[$sensor_db['sensor_oid']])) {
                        print_debug("value taken from oid_cache");
                        $sensor_poll['sensor_value'] = $oid_cache[$sensor_db['sensor_oid']];
                    } else {
                        $sensor_poll['sensor_value'] = snmp_get($device, $sensor_db['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
                    }
                    $sensor_poll['sensor_value'] = snmp_fix_numeric($sensor_poll['sensor_value']);
                    if (is_numeric($sensor_poll['sensor_value']) && $sensor_poll['sensor_value'] != 9999) {
                        break;
                    }
                    // Papouch TME sometimes sends 999.9 when it is right in the middle of an update;
                    sleep(1);
                    // Give the TME some time to reset
                }
                // If we received 999.9 degrees still, reset to Unknown.
                if ($sensor_poll['sensor_value'] == 9999) {
                    $sensor_poll['sensor_value'] = "U";
                }
            } else {
                if ($class == "runtime") {
                    if (isset($oid_cache[$sensor_db['sensor_oid']])) {
                        print_debug("value taken from oid_cache");
                        $sensor_poll['sensor_value'] = $oid_cache[$sensor_db['sensor_oid']];
                    } else {
                        $sensor_poll['sensor_value'] = snmp_get($device, $sensor_db['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
                    }
                    if (strpos($sensor_poll['sensor_value'], ':') !== FALSE) {
                        // Use timetick conversion only when snmpdata is formatted as timetick 0:0:21:00.00
                        $sensor_poll['sensor_value'] = timeticks_to_sec($sensor_poll['sensor_value']);
                    }
                } else {
                    // Take value from $oid_cache if we have it, else snmp_get it
                    if (is_numeric($oid_cache[$sensor_db['sensor_oid']])) {
                        print_debug("value taken from oid_cache");
                        $sensor_poll['sensor_value'] = $oid_cache[$sensor_db['sensor_oid']];
                    } else {
                        $sensor_poll['sensor_value'] = snmp_get($device, $sensor_db['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
                    }
                    $sensor_poll['sensor_value'] = snmp_fix_numeric($sensor_poll['sensor_value']);
                }
            }
        } else {
            if ($sensor_db['poller_type'] == "agent") {
                if (isset($agent_sensors)) {
                    $sensor_poll['sensor_value'] = $agent_sensors[$class][$sensor_db['sensor_type']][$sensor_db['sensor_index']]['current'];
                    // FIXME pass unit?
                } else {
                    print_warning("No agent sensor data available.");
                    continue;
                }
            } else {
                if ($sensor_db['poller_type'] == "ipmi") {
                    if (isset($ipmi_sensors)) {
                        $sensor_poll['sensor_value'] = $ipmi_sensors[$class][$sensor_db['sensor_type']][$sensor_db['sensor_index']]['current'];
                        $unit = $ipmi_sensors[$class][$sensor_db['sensor_type']][$sensor_db['sensor_index']]['unit'];
                    } else {
                        print_warning("No IPMI sensor data available.");
                        continue;
                    }
                } else {
                    print_warning("Unknown sensor poller type.");
                    continue;
                }
            }
        }
        $sensor_polled_time = time();
        // Store polled time for current sensor
        if (OBS_DEBUG) {
            print_r($sensor_poll);
        }
        if ($sensor_poll['sensor_value'] == -32768) {
            print_debug("Invalid (-32768) ");
            $sensor_poll['sensor_value'] = 0;
        }
        // Scale
        if (isset($sensor_db['sensor_multiplier']) && $sensor_db['sensor_multiplier'] != 0) {
            $sensor_poll['sensor_value'] *= $sensor_db['sensor_multiplier'];
        }
        // Unit conversion to SI (if required)
        $sensor_poll['sensor_value'] = value_to_si($sensor_poll['sensor_value'], $sensor_db['sensor_unit'], $class);
        //print_cli_data("Value", $sensor_poll['sensor_value'] . "$unit ", 3);
        // FIXME this block and the other block below it are kinda retarded. They should be merged and simplified.
        if ($sensor_poll['sensor_ignore'] || $sensor_poll['sensor_disable']) {
            $sensor_poll['sensor_event'] = 'ignore';
        } else {
            if ($sensor_db['sensor_limit_low'] != '' && $sensor_poll['sensor_value'] < $sensor_db['sensor_limit_low'] || $sensor_db['sensor_limit'] != '' && $sensor_poll['sensor_value'] > $sensor_db['sensor_limit']) {
                $sensor_poll['sensor_event'] = 'alert';
                $sensor_poll['sensor_status'] = 'Sensor critical thresholds exceeded.';
                // FIXME - be more specific
            } else {
                if ($sensor_db['sensor_limit_low_warn'] != '' && $sensor_poll['sensor_value'] < $sensor_db['sensor_limit_low_warn'] || $sensor_db['sensor_limit_warn'] != '' && $sensor_poll['sensor_value'] > $sensor_db['sensor_limit_warn']) {
                    $sensor_poll['sensor_event'] = 'warning';
                    $sensor_poll['sensor_status'] = 'Sensor warning thresholds exceeded.';
                    // FIXME - be more specific
                } else {
                    $sensor_poll['sensor_event'] = 'ok';
                    $sensor_poll['sensor_status'] = '';
                    //if ($sensor_db['sensor_event'] != 'up' && $sensor_db['sensor_event'] != '')
                    //{
                    //  $sensor_poll['sensor_status'] = 'Sensor thresholds cleared.'; // FIXME - be more specific
                    //}
                }
            }
        }
        // If last change never set, use current time
        if (empty($sensor_db['sensor_last_change'])) {
            $sensor_db['sensor_last_change'] = $sensor_polled_time;
        }
        if ($sensor_poll['sensor_event'] != $sensor_db['sensor_event']) {
            // Sensor event changed, log and set sensor_last_change
            $sensor_poll['status_last_change'] = $sensor_polled_time;
            if ($sensor_db['sensor_event'] == 'ignore') {
                print_message("[%ySensor Ignored%n]", 'color');
            } else {
                if ($sensor_db['sensor_limit_low'] != "" && $sensor_db['sensor_value'] >= $sensor_db['sensor_limit_low'] && $sensor_poll['sensor_value'] < $sensor_db['sensor_limit_low']) {
                    // If old value greater than low limit and new value less than low limit
                    $msg = ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor_db['sensor_descr'] . " is under threshold: " . $sensor_poll['sensor_value'] . "{$unit} (< " . $sensor_db['sensor_limit_low'] . "{$unit})";
                    log_event(ucfirst($class) . ' ' . $sensor_db['sensor_descr'] . " under threshold: " . $sensor_poll['sensor_value'] . " {$unit} (< " . $sensor_db['sensor_limit_low'] . " {$unit})", $device, 'sensor', $sensor_db['sensor_id'], 'warning');
                } else {
                    if ($sensor_db['sensor_limit'] != "" && $sensor_db['sensor_value'] <= $sensor_db['sensor_limit'] && $sensor_poll['sensor_value'] > $sensor_db['sensor_limit']) {
                        // If old value less than high limit and new value greater than high limit
                        $msg = ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor_db['sensor_descr'] . " is over threshold: " . $sensor_poll['sensor_value'] . "{$unit} (> " . $sensor_db['sensor_limit'] . "{$unit})";
                        log_event(ucfirst($class) . ' ' . $sensor_db['sensor_descr'] . " above threshold: " . $sensor_poll['sensor_value'] . " {$unit} (> " . $sensor_db['sensor_limit'] . " {$unit})", $device, 'sensor', $sensor_db['sensor_id'], 'warning');
                    }
                }
            }
        } else {
            // If sensor not changed, leave old last_change
            $sensor_poll['sensor_last_change'] = $sensor_db['sensor_last_change'];
        }
        // Send statistics array via AMQP/JSON if AMQP is enabled globally and for the ports module
        if ($config['amqp']['enable'] == TRUE && $config['amqp']['modules']['sensors']) {
            $json_data = array('value' => $sensor_poll['sensor_value']);
            messagebus_send(array('attribs' => array('t' => time(), 'device' => $device['hostname'], 'device_id' => $device['device_id'], 'e_type' => 'sensor', 'e_class' => $sensor_db['sensor_class'], 'e_type' => $sensor_db['sensor_type'], 'e_index' => $sensor_db['sensor_index']), 'data' => $json_data));
        }
        // Add table row
        $table_rows[] = array($sensor_db['sensor_descr'], $sensor_db['sensor_class'], $sensor_db['sensor_type'], $sensor_db['poller_type'], $sensor_poll['sensor_value'] . $unit, $sensor_poll['sensor_event'], format_unixtime($sensor_poll['sensor_last_change']));
        // Update StatsD/Carbon
        if ($config['statsd']['enable'] == TRUE) {
            StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'sensor' . '.' . $sensor_db['sensor_class'] . '.' . $sensor_db['sensor_type'] . '.' . $sensor_db['sensor_index'], $sensor_poll['sensor_value']);
        }
        // Update RRD - FIXME - can't convert to NG because filename is dynamic! new function should return index instead of filename.
        $rrd_file = get_sensor_rrd($device, $sensor_db);
        rrdtool_create($device, $rrd_file, "DS:sensor:GAUGE:600:-20000:U");
        rrdtool_update($device, $rrd_file, "N:" . $sensor_poll['sensor_value']);
        // Enable graph
        $graphs[$sensor_db['sensor_class']] = TRUE;
        // Check alerts
        $metrics = array();
        $metrics['sensor_value'] = $sensor_poll['sensor_value'];
        $metrics['sensor_event'] = $sensor_poll['sensor_event'];
        $metrics['sensor_event_uptime'] = $sensor_polled_time - $sensor_poll['sensor_last_change'];
        $metrics['sensor_status'] = $sensor_poll['sensor_status'];
        check_entity('sensor', $sensor_db, $metrics);
        // Update SQL State
        if (is_numeric($sensor_db['sensor_polled'])) {
            dbUpdate(array('sensor_value' => $sensor_poll['sensor_value'], 'sensor_event' => $sensor_poll['sensor_event'], 'sensor_status' => $sensor_poll['sensor_status'], 'sensor_last_change' => $sensor_poll['sensor_last_change'], 'sensor_polled' => $sensor_polled_time), 'sensors-state', '`sensor_id` = ?', array($sensor_db['sensor_id']));
        } else {
            dbInsert(array('sensor_id' => $sensor_db['sensor_id'], 'sensor_value' => $sensor_poll['sensor_value'], 'sensor_event' => $sensor_poll['sensor_event'], 'sensor_status' => $sensor_poll['sensor_status'], 'sensor_last_change' => $sensor_poll['sensor_last_change'], 'sensor_polled' => $sensor_polled_time), 'sensors-state');
        }
    }
}
Example #5
0
 /**
  * @dataProvider providerTimeticksToSec
  */
 public function testTimeticksToSec($value, $float, $result)
 {
     $this->assertSame($result, timeticks_to_sec($value, $float));
 }
Example #6
0
         // else { echo($oid . " "); }
     }
 }
 // ifLastChange
 if (isset($this_port['ifLastChange']) && $this_port['ifLastChange'] != '') {
     // Convert ifLastChange from timetick to timestamp
     /**
      * The value of sysUpTime at the time the interface entered
      * its current operational state. If the current state was
      * entered prior to the last re-initialization of the local
      * network management subsystem, then this object contains a
      * zero value.
      *
      * NOTE, observium uses last change timestamp.
      */
     $if_lastchange_uptime = timeticks_to_sec($this_port['ifLastChange']);
     if ($device_uptime['sysUpTime'] - $if_lastchange_uptime > 90) {
         $if_lastchange = $device_uptime['polled'] - $device_uptime['sysUpTime'] + $if_lastchange_uptime;
         print_debug('IFLASTCHANGE = ' . $device_uptime['polled'] . 's - ' . $device_uptime['sysUpTime'] . 's + ' . $if_lastchange_uptime . 's');
         if (abs($if_lastchange - strtotime($port['ifLastChange'])) > 90) {
             // Compare lastchange with previous, update only if more than 60 sec (for exclude random dispersion)
             $port['update']['ifLastChange'] = date('Y-m-d H:i:s', $if_lastchange);
             // Convert to timestamp
         }
     } else {
         // Device sysUpTime more than if uptime or too small difference.. impossible, seems as bug on device
         $if_lastchange_uptime = FALSE;
     }
 } else {
     // ifLastChange not exist
     $if_lastchange_uptime = FALSE;
Example #7
0
 #    if ($device['os'] == "aos") { include("port-alcatel.inc.php"); }
 //if ($this_port['ifOperStatus'] == 'down' && $this_port['ifAdminStatus'] == 'up')
 if (isset($port['update']['ifOperStatus']) || isset($port['update']['ifAdminStatus'])) {
     $if_lastchange = $polled;
     // by default set ifLastChange as current polled time
     /** The value of sysUpTime at the time the interface entered
      * its current operational state. If the current state was
      * entered prior to the last re-initialization of the local
      * network management subsystem, then this object contains a
      * zero value.
      *
      * NOTE. But observium uses last change timestamp.
      */
     // Convert ifLastChange from timetick to timestamp
     if (isset($this_port['ifLastChange']) && $this_port['ifLastChange'] != '' && $this_port['ifLastChange'] != '0:0:00:00.00') {
         $this_port['ifLastChange'] = timeticks_to_sec($this_port['ifLastChange']);
         if (isset($cache['devices']['uptime'][$device['device_id']])) {
             $device_uptime = $cache['devices']['uptime'][$device['device_id']];
             if ($device_uptime['uptime'] <= $this_port['ifLastChange']) {
                 $this_port['ifLastChange'] = 0;
             }
             print_debug('IFLASTCHANGE = ' . $device_uptime['polled'] . ' - ' . $device_uptime['uptime'] . ' + ' . $this_port['ifLastChange']);
             $if_lastchange = $device_uptime['polled'] - $device_uptime['uptime'] + $this_port['ifLastChange'];
         }
     }
     $port['update']['ifLastChange'] = date('Y-m-d H:i:s', $if_lastchange);
     // Convert to timestamp
     print_debug('IFLASTCHANGE: ' . $port['update']['ifLastChange']);
 }
 // Update Database
 if (count($port['update'])) {
    if ($entry['upsHighPrecBatteryCapacity'] && $entry['upsHighPrecBatteryCapacity'] != -1) {
        $oid = ".1.3.6.1.4.1.318.1.1.1.2.3.1.{$index}";
        $value = $entry['upsHighPrecBatteryCapacity'];
        discover_sensor($valid['sensor'], 'capacity', $device, $oid, "upsHighPrecBatteryCapacity.{$index}", 'apc', $descr, 10, 1, 15, 30, NULL, NULL, $value / 10);
    } elseif ($entry['upsAdvBatteryCapacity'] && $entry['upsAdvBatteryCapacity'] != -1) {
        $oid = ".1.3.6.1.4.1.318.1.1.1.2.2.1.{$index}";
        $value = $entry['upsAdvBatteryCapacity'];
        discover_sensor($valid['sensor'], 'capacity', $device, $oid, "upsAdvBatteryCapacity.{$index}", 'apc', $descr, 1, 1, 15, 30, NULL, NULL, $value);
    }
    $descr = "Battery Runtime Remaining";
    if ($entry['upsAdvBatteryRunTimeRemaining']) {
        //Runtime store data in min
        $oid = ".1.3.6.1.4.1.318.1.1.1.2.2.3.{$index}";
        $value = timeticks_to_sec($entry['upsAdvBatteryRunTimeRemaining']);
        $low_limit = snmp_get($device, "upsAdvConfigLowBatteryRunTime.{$index}", "-Ovq", "PowerNet-MIB", mib_dirs('apc'));
        $low_limit = timeticks_to_sec($low_limit);
        $low_limit = is_numeric($low_limit) ? $low_limit / 60 : 2;
        discover_sensor($valid['sensor'], 'runtime', $device, $oid, "upsAdvBatteryRunTimeRemaining.{$index}", 'apc', $descr, 60, 1, $low_limit, NULL, NULL, NULL, $value / 60);
    }
}
#### ATS #############################################################################################
$inputs = snmp_get($device, "atsNumInputs.0", "-Ovq", "PowerNet-MIB", mib_dirs('apc'));
$outputs = snmp_get($device, "atsNumOutputs.0", "-Ovq", "PowerNet-MIB", mib_dirs('apc'));
// Check if we have values for these, if not, try other code paths below.
if ($inputs || $outputs) {
    echo " ";
    $cache['apc'] = array();
    foreach (array("atsInputTable", "atsOutputTable", "atsInputPhaseTable", "atsOutputPhaseTable") as $table) {
        echo "{$table} ";
        $cache['apc'] = snmpwalk_cache_threepart_oid($device, $table, $cache['apc'], "PowerNet-MIB", mib_dirs('apc'), TRUE);
    }
Example #9
0
## Bypass Frequency
$oid = ".1.3.6.1.2.1.33.1.5.1.0";
# UPS-MIB:upsBypassFrequency.0
$value = snmp_get($device, $oid, "-Oqv");
if (is_numeric($value)) {
    discover_sensor($valid['sensor'], 'frequency', $device, $oid, "upsBypassFrequency", 'ups-mib', "Bypass", $scale, $value);
}
//UPS-MIB::upsTestId.0 = OID: UPS-MIB::upsTestNoTestsInitiated
//UPS-MIB::upsTestSpinLock.0 = INTEGER: 1
//UPS-MIB::upsTestResultsSummary.0 = INTEGER: noTestsInitiated(6)
//UPS-MIB::upsTestResultsDetail.0 = STRING: No test initiated.
//UPS-MIB::upsTestStartTime.0 = Timeticks: (0) 0:00:00.00
//UPS-MIB::upsTestElapsedTime.0 = INTEGER: 0
$ups_array = snmpwalk_cache_multi_oid($device, "upsTest", array(), "UPS-MIB");
if (isset($ups_array[0]['upsTestResultsSummary']) && $ups_array[0]['upsTestResultsSummary'] != 'noTestsInitiated') {
    $descr = "Diagnostics Results";
    $oid = ".1.3.6.1.2.1.33.1.7.3.0";
    $value = $ups_array[0]['upsTestResultsSummary'];
    $test_starttime = timeticks_to_sec($ups_array[0]['upsTestStartTime']);
    if ($test_starttime) {
        $test_sysUpime = timeticks_to_sec(snmp_get($device, "sysUpTime.0", "-OQUs", "SNMPv2-MIB"));
        if ($test_sysUpime) {
            $test_starttime = time() + $test_starttime - $test_sysUpime;
            // Unixtime of start test
            $descr .= ' (last ' . format_unixtime($test_starttime) . ')';
        }
    }
    discover_status($device, $oid, "upsTestResultsSummary.0", 'ups-mib-test-state', $descr, $value, array('entPhysicalClass' => 'other'));
}
unset($ups_array);
// EOF
Example #10
0
 }
 $pseudowire_polled_time = time();
 // Store polled time for current MIB
 if (OBS_DEBUG > 1 && count($cache_pseudowires[$mib_lower])) {
     print_vars($cache_pseudowires[$mib_lower]);
 }
 //pseudowires_db_count   += count(pseudowires_db[$mib_lower]);
 $pseudowires_snmp_count += count($cache_pseudowires[$mib_lower]);
 foreach ($pseudowires_db[$mib] as $index => $pw) {
     $rrd_filename = "pseudowire-" . $mib_lower . '-' . $index . ".rrd";
     $rrd_uptime = "pseudowire-" . $mib_lower . '-uptime-' . $index . ".rrd";
     $rrd_ds = '';
     if (isset($cache_pseudowires[$mib_lower][$index])) {
         $pw_poll =& $cache_pseudowires[$mib_lower][$index];
         // Uptime graph
         $pw_uptime = timeticks_to_sec($pw_poll[$oids['Uptime']['oid']]);
         // Convert uptime to sec
         rrdtool_create($device, $rrd_uptime, "DS:Uptime:GAUGE:600:0:U ");
         rrdtool_update($device, $rrd_uptime, "N:" . $pw_uptime);
         $graphs['pseudowire_uptime'] = TRUE;
         // Bits & Packets graphs
         $pw_values = array();
         foreach (array('InOctets', 'OutOctets', 'InPkts', 'OutPkts') as $oid_type) {
             if (!isset($oids[$oid_type])) {
                 break;
             }
             $rrd_ds .= 'DS:' . $oid_type . ':DERIVE:600:0:' . $config['max_port_speed'] . ' ';
             $pw_values[] = $pw_poll[$oids[$oid_type]['oid']];
         }
         if (count($pw_values)) {
             rrdtool_create($device, $rrd_filename, $rrd_ds);
    print_vars($sessions_array);
}
$timestamp = date('Y-m-d H:i:s', strtotime("now"));
// Goes through the SNMP sessions data
foreach ($sessions_array as $index => $session) {
    list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(".", $index);
    $clean_mac = zeropad(dechex($a_a)) . zeropad(dechex($a_b)) . zeropad(dechex($a_c)) . zeropad(dechex($a_d)) . zeropad(dechex($a_e)) . zeropad(dechex($a_f));
    // Mapping OIDs<>DB
    $db_oids = array('trpzClSessClientSessSessionId' => 'session_id', 'trpzClSessClientSessUsername' => 'username', 'trpzClSessClientSessIpAddress' => 'ipv4_addr', 'trpzClSessClientSessSsid' => 'ssid', 'trpzClSessClientSessSessionState' => 'state');
    $new_index = $clean_mac;
    foreach ($db_oids as $db_oid => $db_value) {
        $db_insert[$db_value] = $session[$db_oid];
    }
    $db_insert['device_id'] = $device['device_id'];
    $db_insert['mac_addr'] = $clean_mac;
    $db_insert['uptime'] = timeticks_to_sec($session['trpzClSessClientSessTimeStamp']);
    // FIXME. There timestamp, not timetick!
    $db_insert['timestamp'] = $timestamp;
    if ($session['trpzClSessClientSessRadioNum'] == "radio-1") {
        $radio_number = '1';
    } else {
        if ($session['trpzClSessClientSessradioNum'] == "radio-2") {
            $radio_number = '2';
        }
    }
    $db_insert['radio_id'] = $radios_sorted_db[$session['trpzClSessClientSessApNum']][$radio_number]['wifi_radio_id'];
    if (OBS_DEBUG > 1) {
        print_vars($db_insert);
    }
    if (!is_array($sessions_db[$new_index])) {
        $session_id = dbInsert($db_insert, 'wifi_sessions');
function poll_sensor($device, $class, $unit, &$oid_cache)
{
    global $config, $agent_sensors, $ipmi_sensors;
    $sql = "SELECT *, `sensors`.`sensor_id` AS `sensor_id`";
    $sql .= " FROM  `sensors`";
    $sql .= " LEFT JOIN  `sensors-state` ON  `sensors`.sensor_id =  `sensors-state`.sensor_id";
    $sql .= " WHERE `sensor_class` = ? AND `device_id` = ?";
    foreach (dbFetchRows($sql, array($class, $device['device_id'])) as $sensor) {
        echo "Checking (" . $sensor['poller_type'] . ") {$class} " . $sensor['sensor_descr'] . " ";
        $sensor_new = $sensor;
        // Cache non-humanized sensor array
        humanize_sensor($sensor);
        if ($sensor['poller_type'] == "snmp") {
            # if ($class == "temperature" && $device['os'] == "papouch")
            // Why all temperature?
            if ($class == "temperature" && !$sensor['sensor_state']) {
                for ($i = 0; $i < 5; $i++) {
                    // Take value from $oid_cache if we have it, else snmp_get it
                    if (is_numeric($oid_cache[$sensor['sensor_oid']])) {
                        print_debug("value taken from oid_cache");
                        $sensor_value = $oid_cache[$sensor['sensor_oid']];
                    } else {
                        $sensor_value = preg_replace("/[^0-9\\-\\.]/", "", snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB", mib_dirs()));
                    }
                    if (is_numeric($sensor_value) && $sensor_value != 9999) {
                        break;
                    }
                    // TME sometimes sends 999.9 when it is right in the middle of an update;
                    sleep(1);
                    # Give the TME some time to reset
                }
                // Also reduce value by 32 if sensor in Fahrenheit unit
                if ($sensor['sensor_divisor'] == 9 && $sensor['sensor_multiplier'] == 5) {
                    $sensor_value -= 32;
                }
            } else {
                if ($class == "runtime" && !$sensor['sensor_state']) {
                    if (isset($oid_cache[$sensor['sensor_oid']])) {
                        print_debug("value taken from oid_cache");
                        $sensor_value = timeticks_to_sec($oid_cache[$sensor['sensor_oid']]);
                    } else {
                        $sensor_value = trim(str_replace("\"", "", snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB", mib_dirs())));
                        $sensor_value = timeticks_to_sec($sensor_value);
                    }
                } else {
                    // Take value from $oid_cache if we have it, else snmp_get it
                    if (is_numeric($oid_cache[$sensor['sensor_oid']])) {
                        print_debug("value taken from oid_cache");
                        $sensor_value = $oid_cache[$sensor['sensor_oid']];
                    } else {
                        $sensor_value = trim(str_replace("\"", "", snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB", mib_dirs())));
                    }
                }
            }
        } else {
            if ($sensor['poller_type'] == "agent") {
                if (isset($agent_sensors)) {
                    $sensor_value = $agent_sensors[$class][$sensor['sensor_type']][$sensor['sensor_index']]['current'];
                    # FIXME pass unit?
                } else {
                    print_warning("No agent sensor data.");
                    continue;
                }
            } else {
                if ($sensor['poller_type'] == "ipmi") {
                    if (isset($ipmi_sensors)) {
                        $sensor_value = $ipmi_sensors[$class][$sensor['sensor_type']][$sensor['sensor_index']]['current'];
                        $unit = $ipmi_sensors[$class][$sensor['sensor_type']][$sensor['sensor_index']]['unit'];
                    } else {
                        print_warning("No IPMI sensor data.");
                        continue;
                    }
                } else {
                    print_warning("Unknown sensor poller type.");
                    continue;
                }
            }
        }
        if (!$sensor['sensor_state']) {
            if ($sensor_value == -32768) {
                echo "Invalid (-32768) ";
                $sensor_value = 0;
            }
            if ($sensor['sensor_divisor']) {
                $sensor_value = $sensor_value / $sensor['sensor_divisor'];
            }
            if ($sensor['sensor_multiplier']) {
                $sensor_value = $sensor_value * $sensor['sensor_multiplier'];
            }
        }
        $rrd_file = get_sensor_rrd($device, $sensor);
        if (!is_file($rrd_file)) {
            rrdtool_create($rrd_file, "DS:sensor:GAUGE:600:-20000:U");
            //DS:sensor:GAUGE:600:-20000:20000 ");
        }
        echo "{$sensor_value} {$unit} ";
        // Write new value and humanize (for alert checks)
        $sensor_new['sensor_value'] = $sensor_value;
        humanize_sensor($sensor_new);
        // FIXME also warn when crossing WARN level!!
        if ($sensor['state_event'] != 'ignore') {
            if (!$sensor['sensor_state']) {
                if ($sensor['sensor_limit_low'] != "" && $sensor['sensor_value'] >= $sensor['sensor_limit_low'] && $sensor_value < $sensor['sensor_limit_low']) {
                    $msg = ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is under threshold: " . $sensor_value . "{$unit} (< " . $sensor['sensor_limit_low'] . "{$unit})";
                    notify($device, ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
                    print_message("[%rAlerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "%n\n", 'color');
                    log_event(ucfirst($class) . ' ' . $sensor['sensor_descr'] . " under threshold: " . $sensor_value . " {$unit} (< " . $sensor['sensor_limit_low'] . " {$unit})", $device, $class, $sensor['sensor_id']);
                } else {
                    if ($sensor['sensor_limit'] != "" && $sensor['sensor_value'] <= $sensor['sensor_limit'] && $sensor_value > $sensor['sensor_limit']) {
                        $msg = ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is over threshold: " . $sensor_value . "{$unit} (> " . $sensor['sensor_limit'] . "{$unit})";
                        notify($device, ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
                        print_message("[%rAlerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "%n\n", 'color');
                        log_event(ucfirst($class) . ' ' . $sensor['sensor_descr'] . " above threshold: " . $sensor_value . " {$unit} (> " . $sensor['sensor_limit'] . " {$unit})", $device, $class, $sensor['sensor_id']);
                    }
                }
            } else {
                if ($sensor_value != $sensor['sensor_value'] && $sensor['state_value'] != '') {
                    $sensor_state_name = $sensor_new['state_name'];
                    $sensor_state_event = $sensor_new['state_event'];
                    switch ($sensor_state_event) {
                        case 'alert':
                            $msg = ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is under ALERT state: " . $sensor_state_name . " (previous state: " . $sensor['state_name'] . ")";
                            print_message("[%rSensor ALARM for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "%n\n", 'color');
                            notify($device, ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
                            log_event($msg, $device, $class, $sensor['sensor_id']);
                            break;
                        case 'warning':
                            $msg = ucfirst($class) . " Warning: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " in WARNING state: " . $sensor_state_name . " (previous state: " . $sensor['state_name'] . ")";
                            print_message("[%rSensor WARNING for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "%n\n", 'color');
                            log_event($msg, $device, $class, $sensor['sensor_id']);
                            break;
                        case 'up':
                            $msg = ucfirst($class) . " Up: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " in NORMAL state: " . $sensor_state_name . " (previous state: " . $sensor['state_name'] . ")";
                            print_message("[%rSensor UP for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "%n\n", 'color');
                            if ($sensor['state_event'] != 'warning') {
                                notify($device, ucfirst($class) . " Up: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
                            }
                            log_event($msg, $device, $class, $sensor['sensor_id']);
                            break;
                    }
                }
            }
        } else {
            print_message("[%ySensor Ignored%n]", 'color');
        }
        echo "\n";
        // Send statistics array via AMQP/JSON if AMQP is enabled globally and for the ports module
        if ($config['amqp']['enable'] == TRUE && $config['amqp']['modules']['sensors']) {
            $json_data = array('value' => $sensor_value);
            messagebus_send(array('attribs' => array('t' => time(), 'device' => $device['hostname'], 'device_id' => $device['device_id'], 'e_type' => 'sensor', 'e_class' => $sensor['sensor_class'], 'e_type' => $sensor['sensor_type'], 'e_index' => $sensor['sensor_index']), 'data' => $json_data));
        }
        // Update StatsD/Carbon
        if ($config['statsd']['enable'] == TRUE) {
            StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'sensor' . '.' . $sensor['sensor_class'] . '.' . $sensor['sensor_type'] . '.' . $sensor['sensor_index'], $sensor_value);
        }
        // Update RRD
        rrdtool_update($rrd_file, "N:{$sensor_value}");
        // Check alerts
        if (!$sensor['sensor_state']) {
            check_entity('sensor', $sensor, array('sensor_value' => $sensor_new['sensor_value']));
        }
        check_entity('sensor', $sensor, array('sensor_event' => $sensor_new['state_event']));
        // Update SQL State
        if (is_numeric($sensor['sensor_polled'])) {
            dbUpdate(array('sensor_value' => $sensor_value, 'sensor_polled' => time()), 'sensors-state', '`sensor_id` = ?', array($sensor['sensor_id']));
        } else {
            dbInsert(array('sensor_id' => $sensor['sensor_id'], 'sensor_value' => $sensor_value, 'sensor_polled' => time()), 'sensors-state');
        }
    }
}
function poll_sensor($device, $class, $unit, &$oid_cache)
{
    global $config, $agent_sensors, $ipmi_sensors, $graphs;
    $sql = "SELECT *, `sensors`.`sensor_id` AS `sensor_id`";
    $sql .= " FROM  `sensors`";
    $sql .= " LEFT JOIN  `sensors-state` ON  `sensors`.sensor_id =  `sensors-state`.sensor_id";
    $sql .= " WHERE `sensor_class` = ? AND `device_id` = ?";
    foreach (dbFetchRows($sql, array($class, $device['device_id'])) as $sensor_db) {
        $sensor_poll = array();
        if (OBS_DEBUG) {
            echo "检测中 (" . $sensor_db['poller_type'] . ") {$class} " . $sensor_db['sensor_descr'] . " ";
            print_r($sensor_db);
        }
        if ($sensor_db['poller_type'] == "snmp") {
            # if ($class == "temperature" && $device['os'] == "papouch")
            // Why all temperature?
            if ($class == "temperature") {
                for ($i = 0; $i < 5; $i++) {
                    // Take value from $oid_cache if we have it, else snmp_get it
                    if (is_numeric($oid_cache[$sensor_db['sensor_oid']])) {
                        print_debug("取值来自 oid_cache");
                        $sensor_poll['sensor_value'] = $oid_cache[$sensor_db['sensor_oid']];
                    } else {
                        $sensor_poll['sensor_value'] = snmp_fix_numeric(snmp_get($device, $sensor_db['sensor_oid'], "-OUqnv", "SNMPv2-MIB", mib_dirs()));
                    }
                    if (is_numeric($sensor_poll['sensor_value']) && $sensor_poll['sensor_value'] != 9999) {
                        break;
                    }
                    // Papouch TME sometimes sends 999.9 when it is right in the middle of an update;
                    sleep(1);
                    // Give the TME some time to reset
                }
                // If we received 999.9 degrees still, reset to Unknown.
                if ($sensor_poll['sensor_value'] == 9999) {
                    $sensor_poll['sensor_value'] = "U";
                }
            } else {
                if ($class == "runtime") {
                    if (isset($oid_cache[$sensor_db['sensor_oid']])) {
                        print_debug("value taken from oid_cache");
                        $sensor_poll['sensor_value'] = $oid_cache[$sensor_db['sensor_oid']];
                    } else {
                        $sensor_poll['sensor_value'] = snmp_get($device, $sensor_db['sensor_oid'], "-OUqnv", "SNMPv2-MIB", mib_dirs());
                    }
                    if (strpos($sensor_poll['sensor_value'], ':') !== FALSE) {
                        // Use timetick conversion only when snmpdata is formatted as timetick 0:0:21:00.00
                        $sensor_poll['sensor_value'] = timeticks_to_sec($sensor_poll['sensor_value']);
                    }
                } else {
                    // Take value from $oid_cache if we have it, else snmp_get it
                    if (is_numeric($oid_cache[$sensor_db['sensor_oid']])) {
                        print_debug("取值来自 oid_cache");
                        $sensor_poll['sensor_value'] = $oid_cache[$sensor_db['sensor_oid']];
                    } else {
                        $sensor_poll['sensor_value'] = snmp_fix_numeric(snmp_get($device, $sensor_db['sensor_oid'], "-OUqnv", "SNMPv2-MIB", mib_dirs()));
                    }
                }
            }
        } else {
            if ($sensor_db['poller_type'] == "agent") {
                if (isset($agent_sensors)) {
                    $sensor_poll['sensor_value'] = $agent_sensors[$class][$sensor_db['sensor_type']][$sensor_db['sensor_index']]['current'];
                    // FIXME pass unit?
                } else {
                    print_warning("传感器中的数据无可用的代理.");
                    continue;
                }
            } else {
                if ($sensor_db['poller_type'] == "ipmi") {
                    if (isset($ipmi_sensors)) {
                        $sensor_poll['sensor_value'] = $ipmi_sensors[$class][$sensor_db['sensor_type']][$sensor_db['sensor_index']]['current'];
                        $unit = $ipmi_sensors[$class][$sensor_db['sensor_type']][$sensor_db['sensor_index']]['unit'];
                    } else {
                        print_warning("IPMI传感器数据不可用.");
                        continue;
                    }
                } else {
                    print_warning("未知的系缆柱型传感器.");
                    continue;
                }
            }
        }
        if (OBS_DEBUG) {
            print_r($sensor_poll);
        }
        if ($sensor_poll['sensor_value'] == -32768) {
            print_debug("Invalid (-32768) ");
            $sensor_poll['sensor_value'] = 0;
        }
        /// FIXME. This is old pre 'scale' method, remove in r7000
        if (isset($sensor_db['sensor_divisor']) && $sensor_db['sensor_divisor'] > 1) {
            /// This is fix for r5351
            if ($sensor_db['sensor_multiplier'] >= 1) {
                $sensor_poll['sensor_value'] = $sensor_poll['sensor_value'] / $sensor_db['sensor_divisor'];
            }
        }
        if (isset($sensor_db['sensor_multiplier']) && $sensor_db['sensor_multiplier'] != 0) {
            $f2c = FALSE;
            if ($class == "temperature") {
                // This is weird hardcode for convert Fahrenheit to Celsius
                foreach (array(1, 0.1) as $scale_tmp) {
                    if (float_cmp($sensor_db['sensor_multiplier'], $scale_tmp * 5 / 9) === 0) {
                        $sensor_db['sensor_multiplier'] = $scale_tmp;
                        $f2c = TRUE;
                        break;
                    }
                }
            }
            $sensor_poll['sensor_value'] *= $sensor_db['sensor_multiplier'];
            if ($f2c) {
                $sensor_poll['sensor_value'] = f2c($sensor_poll['sensor_value']);
                print_debug('TEMPERATURE sensor: Fahrenheit -> Celsius');
            }
        }
        $rrd_file = get_sensor_rrd($device, $sensor_db);
        rrdtool_create($device, $rrd_file, "DS:sensor:GAUGE:600:-20000:U");
        echo $sensor_poll['sensor_value'] . "{$unit} ";
        // FIXME this block and the other block below it are kinda retarded. They should be merged and simplified.
        if ($sensor_poll['sensor_ignore'] || $sensor_poll['sensor_disable']) {
            $sensor_poll['sensor_event'] = 'ignore';
        } else {
            if ($sensor_db['sensor_limit_low_warn'] != '' && $sensor_poll['sensor_value'] < $sensor_db['sensor_limit_low_warn'] || $sensor_db['sensor_limit_warn'] != '' && $sensor_poll['sensor_value'] > $sensor_db['sensor_limit_warn']) {
                $sensor_poll['sensor_event'] = 'warning';
                $sensor_poll['sensor_status'] = 'Sensor warning thresholds exceeded.';
                // FIXME - be more specific
            } else {
                if (($sensor_db['sensor_limit_low'] != '' && $sensor_poll['sensor_value'] < $sensor_db['sensor_limit_low'] || $sensor_db['sensor_limit'] != '' && $sensor_poll['sensor_value'] > $sensor_db['sensor_limit']) && $sensor_db['sensor_value'] != '') {
                    $sensor_poll['sensor_event'] = 'alert';
                    $sensor_poll['sensor_status'] = 'Sensor critical thresholds exceeded.';
                    // FIXME - be more specific
                } else {
                    $sensor_poll['sensor_event'] = 'up';
                    $sensor_poll['sensor_status'] = '';
                    //if ($sensor_db['sensor_event'] != 'up' && $sensor_db['sensor_event'] != '')
                    //{
                    //  $sensor_poll['sensor_status'] = 'Sensor thresholds cleared.'; // FIXME - be more specific
                    //}
                }
            }
        }
        // FIXME I left the eventlog code for now, as soon as alerts send an entry to the eventlog this can go.
        if ($sensor_db['sensor_event'] != 'ignore') {
            if ($sensor_db['sensor_limit_low'] != "" && $sensor_db['sensor_value'] >= $sensor_db['sensor_limit_low'] && $sensor_poll['sensor_value'] < $sensor_db['sensor_limit_low']) {
                // If old value greater than low limit and new value less than low limit
                $msg = ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor_db['sensor_descr'] . " is under threshold: " . $sensor_poll['sensor_value'] . "{$unit} (< " . $sensor_db['sensor_limit_low'] . "{$unit})";
                log_event(ucfirst($class) . ' ' . $sensor_db['sensor_descr'] . " under threshold: " . $sensor_poll['sensor_value'] . " {$unit} (< " . $sensor_db['sensor_limit_low'] . " {$unit})", $device, 'sensor', $sensor_db['sensor_id'], 'warning');
            } else {
                if ($sensor_db['sensor_limit'] != "" && $sensor_db['sensor_value'] <= $sensor_db['sensor_limit'] && $sensor_poll['sensor_value'] > $sensor_db['sensor_limit']) {
                    // If old value less than high limit and new value greater than high limit
                    $msg = ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor_db['sensor_descr'] . " is over threshold: " . $sensor_poll['sensor_value'] . "{$unit} (> " . $sensor_db['sensor_limit'] . "{$unit})";
                    log_event(ucfirst($class) . ' ' . $sensor_db['sensor_descr'] . " above threshold: " . $sensor_poll['sensor_value'] . " {$unit} (> " . $sensor_db['sensor_limit'] . " {$unit})", $device, 'sensor', $sensor_db['sensor_id'], 'warning');
                }
            }
        } else {
            print_message("[%ySensor Ignored%n]", 'color');
        }
        echo PHP_EOL;
        // Send statistics array via AMQP/JSON if AMQP is enabled globally and for the ports module
        if ($config['amqp']['enable'] == TRUE && $config['amqp']['modules']['sensors']) {
            $json_data = array('value' => $sensor_poll['sensor_value']);
            messagebus_send(array('attribs' => array('t' => time(), 'device' => $device['hostname'], 'device_id' => $device['device_id'], 'e_type' => 'sensor', 'e_class' => $sensor_db['sensor_class'], 'e_type' => $sensor_db['sensor_type'], 'e_index' => $sensor_db['sensor_index']), 'data' => $json_data));
        }
        // Update StatsD/Carbon
        if ($config['statsd']['enable'] == TRUE) {
            StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'sensor' . '.' . $sensor_db['sensor_class'] . '.' . $sensor_db['sensor_type'] . '.' . $sensor_db['sensor_index'], $sensor_poll['sensor_value']);
        }
        // Update RRD
        rrdtool_update($device, $rrd_file, "N:" . $sensor_poll['sensor_value']);
        // Enable graph
        $graphs[$sensor_db['sensor_class']] = TRUE;
        // Check alerts
        $metrics = array();
        $metrics['sensor_value'] = $sensor_poll['sensor_value'];
        $metrics['sensor_event'] = $sensor_poll['sensor_event'];
        $metrics['sensor_status'] = $sensor_poll['sensor_status'];
        check_entity('sensor', $sensor_db, $metrics);
        // Update SQL State
        if (is_numeric($sensor_db['sensor_polled'])) {
            dbUpdate(array('sensor_value' => $sensor_poll['sensor_value'], 'sensor_event' => $sensor_poll['sensor_event'], 'sensor_status' => $sensor_poll['sensor_status'], 'sensor_polled' => time()), 'sensors-state', '`sensor_id` = ?', array($sensor_db['sensor_id']));
        } else {
            dbInsert(array('sensor_id' => $sensor_db['sensor_id'], 'sensor_value' => $sensor_poll['sensor_value'], 'sensor_event' => $sensor_poll['sensor_event'], 'sensor_status' => $sensor_poll['sensor_status'], 'sensor_polled' => time()), 'sensors-state');
        }
    }
}
Example #14
0
// SNMPv2-MIB::sysUpTime.0 = Timeticks: (2542831) 7:03:48.31
$uptimes = array('sysUpTime' => timeticks_to_sec($poll_device['sysUpTime']));
if (isset($agent_data['uptime'])) {
    list($agent_data['uptime']) = explode(' ', $agent_data['uptime']);
    $uptimes['unix-agent'] = round($agent_data['uptime']);
}
if (is_numeric($agent_data['uptime']) && $agent_data['uptime'] > 0) {
    // Unix-agent uptime is highest priority
    $uptimes['use'] = 'unix-agent';
    $uptimes['message'] = 'Using UNIX Agent Uptime';
} else {
    if ($device['os'] != 'windows' && $device['snmp_version'] != 'v1' && is_device_mib($device, 'HOST-RESOURCES-MIB')) {
        // HOST-RESOURCES-MIB::hrSystemUptime.0 = Wrong Type (should be Timeticks): 1632295600
        // HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (63050465) 7 days, 7:08:24.65
        $hrSystemUptime = snmp_get($device, 'hrSystemUptime.0', '-Oqv', 'HOST-RESOURCES-MIB');
        $uptimes['hrSystemUptime'] = timeticks_to_sec($hrSystemUptime);
        if (is_numeric($uptimes['hrSystemUptime']) && $uptimes['hrSystemUptime'] > 0) {
            // hrSystemUptime have second priority on unix systems
            $uptimes['use'] = 'hrSystemUptime';
        }
    }
    if ($uptimes['use'] != 'hrSystemUptime') {
        // sysUpTime used by default if all other agents data unavialable
        $uptimes['use'] = 'sysUpTime';
        // Last check snmpEngineTime
        if ($device['snmp_version'] != 'v1') {
            // SNMP-FRAMEWORK-MIB::snmpEngineTime.0 = INTEGER: 72393514 seconds
            $snmpEngineTime = snmp_get($device, 'snmpEngineTime.0', '-OUqv', 'SNMP-FRAMEWORK-MIB');
        } else {
            $snmpEngineTime = 0;
        }