/** * Helper function to improve readability * Can't use mib based polling, because the snmp implentation and mibs are terrible * * @param (device) array - device array * @param (sensor) array(id, oid, type, descr, descr_oid, min, max, divisor) */ function avtech_add_sensor($device, $sensor) { global $valid; // set the id, must be unique if (isset($sensor['id'])) { $id = $sensor['id']; } else { d_echo('Error: No id set for this sensor' . "\n"); return false; } d_echo('Sensor id: ' . $id . "\n"); // set the sensor oid if ($sensor['oid']) { $oid = $sensor['oid']; } else { d_echo('Error: No oid set for this sensor' . "\n"); return false; } d_echo('Sensor oid: ' . $oid . "\n"); // get the sensor value $value = snmp_get($device, $oid, '-OvQ'); // if the sensor doesn't exist abort if ($value === false || $type == 'temperature' && $value == 0) { //issue unfortunately some non-existant sensors return 0 d_echo('Error: sensor returned no data, skipping' . "\n"); return false; } d_echo('Sensor value: ' . $value . "\n"); // get the type $type = $sensor['type'] ? $sensor['type'] : 'temperature'; d_echo('Sensor type: ' . $type . "\n"); $type_name = $device['os']; if ($type == 'switch') { // set up state sensor $type_name .= ucfirst($type); $type = 'state'; $state_index_id = create_state_index($type_name); //Create State Translation if (isset($state_index_id)) { $states = array(array($state_index_id, 'Off', 1, 0, -1), array($state_index_id, 'On', 1, 1, 0)); foreach ($states as $value) { $insert = array('state_index_id' => $value[0], 'state_descr' => $value[1], 'state_draw_graph' => $value[2], 'state_value' => $value[3], 'state_generic_value' => $value[4]); dbInsert($insert, 'state_translations'); } } } // set the description if ($sensor['descr_oid']) { $descr = trim(snmp_get($device, $sensor['descr_oid'], '-OvQ'), '"'); } elseif ($sensor['descr']) { $descr = $sensor['descr']; } else { d_echo('Error: No description set for this sensor' . "\n"); return false; } d_echo('Sensor description: ' . $descr . "\n"); // set divisor if ($sensor['divisor']) { $divisor = $sensor['divisor']; } elseif ($type == 'temperature') { $divisor = 100; } else { $divisor = 1; } d_echo('Sensor divisor: ' . $divisor . "\n"); // set min for alarm if ($sensor['min_oid']) { $min = snmp_get($device, $sensor['min_oid'], '-OvQ') / $divisor; } else { $min = null; } d_echo('Sensor alarm min: ' . $min . "\n"); // set max for alarm if ($sensor['max_oid']) { $max = snmp_get($device, $sensor['max_oid'], '-OvQ') / $divisor; } else { $max = null; } d_echo('Sensor alarm max: ' . $max . "\n"); // add the sensor discover_sensor($valid['sensor'], $type, $device, $oid, $id, $type_name, $descr, $divisor, '1', $min, null, null, $max, $value / $divisor); if ($type == 'state') { create_sensor_to_state_index($device, $type_name, $id); } return true; }
* Copyright (c) 2016 Søren Friis Rosiak <*****@*****.**> * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ if (strstr($device['hardware'], 'Dell')) { $tables = array(array('processorDeviceStatusTable', '.1.3.6.1.4.1.674.10892.1.1100.32.1.5.', 'processorDeviceStatusStatus', 'processorDeviceStatusLocationName', 'MIB-Dell-10892'), array('memoryDeviceTable', '.1.3.6.1.4.1.674.10892.1.1100.50.1.5.', 'memoryDeviceStatus', 'memoryDeviceLocationName', 'MIB-Dell-10892'), array('powerSupplyTable', '.1.3.6.1.4.1.674.10892.1.600.12.1.5.', 'powerSupplyStatus', 'powerSupplyLocationName', 'MIB-Dell-10892'), array('intrusionTable', '.1.3.6.1.4.1.674.10892.1.300.70.1.5.', 'intrusionStatus', 'Intrusion', 'MIB-Dell-10892'), array('controllerTable', '.1.3.6.1.4.1.674.10893.1.20.130.1.1.5.', 'controllerState', 'controllerName', 'StorageManagement-MIB'), array('arrayDiskTable', '.1.3.6.1.4.1.674.10893.1.20.130.4.1.4.', 'arrayDiskState', 'arrayDiskName', 'StorageManagement-MIB'), array('virtualDiskTable', '.1.3.6.1.4.1.674.10893.1.20.140.1.1.4.', 'virtualDiskState', 'virtualDiskDeviceName', 'StorageManagement-MIB'), array('batteryTable', '.1.3.6.1.4.1.674.10893.1.20.130.15.1.4.', 'batteryState', 'batteryName', 'StorageManagement-MIB')); foreach ($tables as $tablevalue) { $temp = snmpwalk_cache_multi_oid($device, $tablevalue[0], array(), $tablevalue[4]); $cur_oid = $tablevalue[1]; if (is_array($temp)) { //Create State Index $state_name = $tablevalue[2]; $state_index_id = create_state_index($state_name); //Create State Translation if ($state_index_id !== null) { if ($state_name == 'processorDeviceStatusStatus' || $state_name == 'memoryDeviceStatus' || $state_name == 'powerSupplyStatus' || $state_name == 'intrusionStatus') { $states = array(array($state_index_id, 'other', 0, 1, 3), array($state_index_id, 'unknown', 0, 2, 3), array($state_index_id, 'ok', 0, 3, 0), array($state_index_id, 'nonCritical', 0, 4, 1), array($state_index_id, 'critical', 0, 5, 2), array($state_index_id, 'nonRecoverable', 0, 6, 2)); } elseif ($state_name == 'controllerState') { $states = array(array($state_index_id, 'ready', 0, 1, 0), array($state_index_id, 'failed', 0, 2, 2), array($state_index_id, 'online', 0, 3, 0), array($state_index_id, 'offline', 0, 4, 1), array($state_index_id, 'degraded', 0, 6, 2)); } elseif ($state_name == 'arrayDiskState') { $states = array(array($state_index_id, 'ready', 0, 1, 0), array($state_index_id, 'failed', 0, 2, 2), array($state_index_id, 'online', 0, 3, 0), array($state_index_id, 'offline', 0, 4, 2), array($state_index_id, 'degraded', 0, 5, 2), array($state_index_id, 'recovering', 0, 6, 1), array($state_index_id, 'removed', 0, 7, 1), array($state_index_id, 'non-raid', 0, 8, 3), array($state_index_id, 'notReady', 0, 9, 1), array($state_index_id, 'resynching', 0, 10, 1), array($state_index_id, 'replacing', 0, 11, 1), array($state_index_id, 'spinningDown', 0, 12, 1), array($state_index_id, 'rebuild', 0, 13, 1), array($state_index_id, 'noMedia', 0, 14, 1), array($state_index_id, 'formatting', 0, 15, 1), array($state_index_id, 'diagnostics', 0, 16, 1), array($state_index_id, 'predictiveFailure', 0, 17, 2), array($state_index_id, 'initializing', 0, 18, 1), array($state_index_id, 'foreign', 0, 19, 1), array($state_index_id, 'clear', 0, 20, 1), array($state_index_id, 'unsupported', 0, 21, 2), array($state_index_id, 'incompatible', 0, 22, 2), array($state_index_id, 'readOnly', 0, 23, 2)); } elseif ($state_name == 'virtualDiskState') { $states = array(array($state_index_id, 'unknown', 0, 0, 3), array($state_index_id, 'ready', 1, 1, 0), array($state_index_id, 'failed', 1, 2, 2), array($state_index_id, 'online', 1, 3, 1), array($state_index_id, 'offline', 1, 4, 2), array($state_index_id, 'degraded', 1, 6, 2), array($state_index_id, 'verifying', 1, 7, 1), array($state_index_id, 'resynching', 1, 15, 1), array($state_index_id, 'regenerating', 1, 16, 1), array($state_index_id, 'failedRedundancy', 1, 18, 2), array($state_index_id, 'rebuilding', 1, 24, 1), array($state_index_id, 'formatting', 1, 26, 1), array($state_index_id, 'reconstructing', 1, 32, 1), array($state_index_id, 'initializing', 1, 35, 1), array($state_index_id, 'backgroundInit', 1, 36, 1), array($state_index_id, 'permanentlyDegraded', 1, 52, 2)); } elseif ($state_name == 'batteryState') { $states = array(array($state_index_id, 'ready', 0, 1, 0), array($state_index_id, 'failed', 1, 2, 2), array($state_index_id, 'degraded', 1, 6, 2), array($state_index_id, 'reconditioning', 1, 7, 1), array($state_index_id, 'high', 1, 9, 1), array($state_index_id, 'low', 1, 10, 1), array($state_index_id, 'charging', 1, 12, 1), array($state_index_id, 'missing', 1, 21, 2), array($state_index_id, 'learning', 1, 36, 1)); } foreach ($states as $value) { $insert = array('state_index_id' => $value[0], 'state_descr' => $value[1], 'state_draw_graph' => $value[2], 'state_value' => $value[3], 'state_generic_value' => $value[4]);
.1.3.6.1.4.1.12740.2.1.8.1.2.1.329840783.1 = Power Cooling Module 0 .1.3.6.1.4.1.12740.2.1.8.1.2.1.329840783.2 = Power Cooling Module 1 **/ $base_oid = '.1.3.6.1.4.1.12740.2.1.8.1.3.1.'; // eqlMemberHealthDetailsPowerSupplyCurrentState if (!empty($oids1)) { /* eqlMemberHealthDetailsPowerSupplyCurrentState INTEGER { on-and-operating (1), no-ac-power (2), failed-or-no-data (3) -- has ac but no dc out or we have no data } */ $state_name1 = 'eqlMemberPowerSupplyCurrentState'; $state_index_id1 = create_state_index($state_name1); if ($state_index_id1) { $states1 = array(array($state_index_id1, 'on-and-operating', 1, 1, 0), array($state_index_id1, 'no-ac-power', 1, 2, 1), array($state_index_id1, 'failed-or-no-data', 1, 3, 2)); foreach ($states1 as $value) { $insert = array('state_index_id' => $value[0], 'state_descr' => $value[1], 'state_draw_graph' => $value[2], 'state_value' => $value[3], 'state_generic_value' => $value[4]); dbInsert($insert, 'state_translations'); } } foreach (explode("\n", $oids1) as $data) { $data = trim($data); if (!empty($data)) { list($oid, $descr) = explode(' = ', $data, 2); $split_oid = explode('.', $oid); $num_index = $split_oid[count($split_oid) - 1]; $index = (int) $num_index + 0; $member_id = $split_oid[count($split_oid) - 2];