diff --git a/includes/discovery/sensors/states/dsm.inc.php b/includes/discovery/sensors/states/dsm.inc.php index 430eb06faf..41ba89d2c1 100644 --- a/includes/discovery/sensors/states/dsm.inc.php +++ b/includes/discovery/sensors/states/dsm.inc.php @@ -1,68 +1,264 @@ - * - * 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. - */ echo 'DSM States'; // System Status (Value : 1 Normal, 2 Failed) -$system_status_oid = '.1.3.6.1.4.1.6574.1.1.0'; -$system_status = snmp_get($device, $system_status_oid, '-Oqv'); -discover_sensor($valid['sensor'], 'state', $device, $system_status_oid, 'SystemStatus', 'snmp', 'System Status', '1', '1', null, null, null, null, $system_status); +$state = snmp_get($device, "systemStatus.0", "-Ovqe", 'SYNOLOGY-SYSTEM-MIB'); +$cur_oid = '.1.3.6.1.4.1.6574.1.1.0'; +$index = '0'; + +if (is_numeric($state)) { + //Create State Index + $state_name = 'systemStatusState'; + $state_index_id = create_state_index($state_name); + + //Create State Translation + if ($state_index_id) { + $states = array( + array($state_index_id,'Normal',0,1,0) , + array($state_index_id,'Failed',0,2,2) , + ); + 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'); + } + } + + //Discover Sensors + discover_sensor($valid['sensor'], 'state', $device, $cur_oid, $index, $state_name, 'System Status', '1', '1', null, null, null, null, $state, 'snmp', $index); + + //Create Sensor To State Index + create_sensor_to_state_index($device, $state_name, $index); +} // Power Status OID (Value : 1 Normal, 2 Failed) -$power_status_oid = '.1.3.6.1.4.1.6574.1.3.0'; -$power_status = snmp_get($device, $power_status_oid, '-Oqv'); -discover_sensor($valid['sensor'], 'state', $device, $power_status_oid, 'PowerStatus', 'snmp', 'Power Status', '1', '1', null, null, null, null, $power_status); +$state = snmp_get($device, "powerStatus.0", "-Ovqe", 'SYNOLOGY-SYSTEM-MIB'); +$cur_oid = '.1.3.6.1.4.1.6574.1.3.0'; +$index = '0'; + +if (is_numeric($state)) { + //Create State Index + $state_name = 'powerStatusState'; + $state_index_id = create_state_index($state_name); + + //Create State Translation + if ($state_index_id) { + $states = array( + array($state_index_id,'Normal',0,1,0) , + array($state_index_id,'Failed',0,2,2) , + ); + 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'); + } + } + + //Discover Sensors + discover_sensor($valid['sensor'], 'state', $device, $cur_oid, $index, $state_name, 'Power Status', '1', '1', null, null, null, null, $state, 'snmp', $index); + + //Create Sensor To State Index + create_sensor_to_state_index($device, $state_name, $index); +} // System Fan Status OID (Value : 1 Normal, 2 Failed) -$system_fan_status_oid = '.1.3.6.1.4.1.6574.1.4.1.0'; -$system_fan_status = snmp_get($device, $system_fan_status_oid, '-Oqv'); -discover_sensor($valid['sensor'], 'state', $device, $system_fan_status_oid, 'SystemFanStatus', 'snmp', 'System Fan Status', '1', '1', null, null, null, null, $system_fan_status); +$state = snmp_get($device, "systemFanStatus.0", "-Ovqe", 'SYNOLOGY-SYSTEM-MIB'); +$cur_oid = '.1.3.6.1.4.1.6574.1.4.1.0'; +$index = '0'; + +if (is_numeric($state)) { + //Create State Index + $state_name = 'systemFanStatusState'; + $state_index_id = create_state_index($state_name); + + //Create State Translation + if ($state_index_id) { + $states = array( + array($state_index_id,'Normal',0,1,0) , + array($state_index_id,'Failed',0,2,2) , + ); + 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'); + } + } + + + //Discover Sensors + discover_sensor($valid['sensor'], 'state', $device, $cur_oid, $index, $state_name, 'System Fan Status', '1', '1', null, null, null, null, $state, 'snmp', $index); + + //Create Sensor To State Index + create_sensor_to_state_index($device, $state_name, $index); +} // CPU Fan Status OID (Value : 1 Normal, 2 Failed) -$cpu_fan_status_oid = '.1.3.6.1.4.1.6574.1.4.2.0'; -$cpu_fan_status = snmp_get($device, $cpu_fan_status_oid, '-Oqv'); -discover_sensor($valid['sensor'], 'state', $device, $cpu_fan_status_oid, 'CPUFanStatus', 'snmp', 'CPU Fan Status', '1', '1', null, null, null, null, $cpu_fan_status); +$state = snmp_get($device, "cpuFanStatus.0", "-Ovqe", 'SYNOLOGY-SYSTEM-MIB'); +$cur_oid = '.1.3.6.1.4.1.6574.1.4.2.0'; +$index = '0'; -// UPS Status OID (Value : OL - On Line, OB - On Battery) -$ups_status_oid = '.1.3.6.1.4.1.6574.4.2.1.0'; -$ups_status = snmp_get($device, $ups_status_oid, '-Oqv'); -// Temp because only support INT -if ((string) $ups_status == '"OL"') { - $ups_status = 1; -} else { - $ups_status = 2; +if (is_numeric($state)) { + //Create State Index + $state_name = 'cpuFanStatusState'; + $state_index_id = create_state_index($state_name); + + //Create State Translation + if ($state_index_id) { + $states = array( + array($state_index_id,'Normal',0,1,0) , + array($state_index_id,'Failed',0,2,2) , + ); + 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'); + } + } + + //Discover Sensors + discover_sensor($valid['sensor'], 'state', $device, $cur_oid, $index, $state_name, 'CPU Fan Status', '1', '1', null, null, null, null, $state, 'snmp', $index); + + //Create Sensor To State Index + create_sensor_to_state_index($device, $state_name, $index); } -discover_sensor($valid['sensor'], 'state', $device, $ups_status_oid, 'UPSStatus', 'snmp', 'UPS Status', '1', '1', null, null, null, null, $ups_status); - // DSM Upgrade Available OID (Value : 1 Available, 2 Unavailable, 3 Connecting, 4 Disconnected, 5 Others) -$dsm_upgrade_available_oid = '.1.3.6.1.4.1.6574.1.5.4.0'; -$dsm_upgrade_available = snmp_get($device, $dsm_upgrade_available_oid, '-Oqv'); -discover_sensor($valid['sensor'], 'state', $device, $dsm_upgrade_available_oid, 'DSMUpgradeStatus', 'snmp', 'DSM Upgrade Status', '1', '1', null, null, null, null, $dsm_upgrade_available); +$state = snmp_get($device, "upgradeAvailable.0", "-Ovqe", 'SYNOLOGY-SYSTEM-MIB'); +$cur_oid = '.1.3.6.1.4.1.6574.1.5.4.0'; +$index = '0'; + +if (is_numeric($state)) { + //Create State Index + $state_name = 'upgradeAvailableState'; + $state_index_id = create_state_index($state_name); + //Create State Translation + if ($state_index_id) { + $states = array( + array($state_index_id,'Available',0,1,1) , + array($state_index_id,'Unavailable',0,2,0) , + array($state_index_id,'Connecting',0,3,3) , + array($state_index_id,'Disconnected',0,4,3) , + array($state_index_id,'Others',0,5,3) , + ); + 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'); + } + } + + //Discover Sensors + discover_sensor($valid['sensor'], 'state', $device, $cur_oid, $index, $state_name, 'Upgrade Availability', '1', '1', null, null, null, null, $state, 'snmp', $index); + + //Create Sensor To State Index + create_sensor_to_state_index($device, $state_name, $index); +} // RAID Status OID (Value : 1 Normal, 2 Repairing, 3 Migrating, 4 Expanding, 5 Deleting, 6 Creating, 7 RaidSyncing, 8 RaidParityChecking, 9 RaidAssembling, 10 Canceling, 11 Degrade, 12 Crashed) -$raid_status_oid = '.1.3.6.1.4.1.6574.3.1.1.3'; -$raid_status = snmp_get($device, $raid_status_oid, '-Oqv'); -discover_sensor($valid['sensor'], 'state', $device, $raid_status_oid, 'RAIDStatus', 'snmp', 'RAID Status', '1', '1', null, null, null, null, $raid_status); +$oids = snmpwalk_cache_multi_oid($device, 'raidTable', array(), 'SYNOLOGY-RAID-MIB'); +$cur_oid = '.1.3.6.1.4.1.6574.3.1.1.3.'; -// Disks Status OID (Value : 1 Normal, 2 Initialized, 3 Not Initialized, 4 System Partition Failed, 5 Crashed ) -$disks_status_oid = '.1.3.6.1.4.1.6574.2.1.1.5.'; -$disks = snmpwalk_cache_multi_oid($device, 'diskTable', array(), 'SYNOLOGY-DISK-MIB'); -if (is_array($disks)) { - foreach ($disks as $disk_number => $entry) { - $disk_oid = $disks_status_oid.$disk_number; - $disk_status = $entry['diskStatus']; - $disk_information = $entry['diskID'].' '.$entry['diskModel'].' Status'; - discover_sensor($valid['sensor'], 'state', $device, $disk_oid, 'DiskStatus'.$disk_number, 'snmp', $disk_information, '1', '1', null, null, null, null, $disk_status); +if (is_array($oids)) { + //Create State Index + $state_name = 'raidStatusState'; + $state_index_id = create_state_index($state_name); + + //Create State Translation + if ($state_index_id) { + $states = array( + array($state_index_id,'Normal',0,1,0) , + array($state_index_id,'Repairing',0,2,1) , + array($state_index_id,'Migrating',0,3,1) , + array($state_index_id,'Expanding',0,4,1) , + array($state_index_id,'Deleting',0,5,1) , + array($state_index_id,'Creating',0,6,1) , + array($state_index_id,'RaidSyncing',0,7,1) , + array($state_index_id,'RaidParityChecking',0,8,1) , + array($state_index_id,'RaidAssembling',0,9,1) , + array($state_index_id,'Canceling',0,10,1) , + array($state_index_id,'Degrade',0,11,2) , + array($state_index_id,'Crashed',0,12,2) , + ); + 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'); + } + } + foreach ($oids as $index => $entry) { + //Discover Sensors + discover_sensor($valid['sensor'], 'state', $device, $cur_oid.$index, $index, $state_name, 'RAID Status', '1', '1', null, null, null, null, $entry['raidStatus'], 'snmp', $index); + + //Create Sensor To State Index + create_sensor_to_state_index($device, $state_name, $index); + } +} + +// Disks Status OID (Value : 1 Normal, 2 Initialized, 3 Not Initialized, 4 System Partition Failed, 5 Crashed ) +$oids = snmpwalk_cache_multi_oid($device, 'diskTable', array(), 'SYNOLOGY-DISK-MIB'); +$cur_oid = '.1.3.6.1.4.1.6574.2.1.1.5.'; + +if (is_array($oids)) { + //Create State Index + $state_name = 'diskStatusState'; + $state_index_id = create_state_index($state_name); + + //Create State Translation + if ($state_index_id) { + $states = array( + array($state_index_id,'Normal',0,1,0) , + array($state_index_id,'Initialized',0,2,1) , + array($state_index_id,'Not Initialized',0,3,1) , + array($state_index_id,'System Partition Failed',0,4,2) , + array($state_index_id,'Crashed',0,5,2) , + ); + 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'); + } + } + foreach ($oids as $index => $entry) { + //Discover Sensors + discover_sensor($valid['sensor'], 'state', $device, $cur_oid.$index, $index, $state_name, 'Disk Status '.$index, '1', '1', null, null, null, null, $entry['diskStatus'], 'snmp', $index); + + //Create Sensor To State Index + create_sensor_to_state_index($device, $state_name, $index); } } diff --git a/mibs/synology/SYNOLOGY-RAID-MIB b/mibs/synology/SYNOLOGY-RAID-MIB new file mode 100644 index 0000000000..97136bebc6 --- /dev/null +++ b/mibs/synology/SYNOLOGY-RAID-MIB @@ -0,0 +1,106 @@ +SYNOLOGY-RAID-MIB DEFINITIONS ::= BEGIN + +IMPORTS + OBJECT-GROUP, MODULE-COMPLIANCE + FROM SNMPv2-CONF + enterprises, MODULE-IDENTITY, OBJECT-TYPE, Integer32 + FROM SNMPv2-SMI; + +synoRaid MODULE-IDENTITY + LAST-UPDATED "201309110000Z" + ORGANIZATION "www.synology.com" + CONTACT-INFO + "postal: Jay Pan + email: jaypan@synology.com" + DESCRIPTION + "Characteristics of the raid information" + REVISION "201309110000Z" + DESCRIPTION + "Second draft." + ::= { synology 3 } + +synology OBJECT IDENTIFIER + ::= { enterprises 6574 } + +raidTable OBJECT-TYPE + SYNTAX SEQUENCE OF RaidEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Synology raid table" + ::= { synoRaid 1 } + +raidEntry OBJECT-TYPE + SYNTAX RaidEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "For all raid entry" + INDEX { raidIndex } + ::= { raidTable 1 } + +RaidEntry ::= SEQUENCE { + raidIndex Integer32, + raidName OCTET STRING, + raidStatus Integer32 +} + +raidIndex OBJECT-TYPE + SYNTAX Integer32(0..2147483647) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "The index of raid table" + ::= { raidEntry 1 } + +raidName OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "Synology raid name + The name of each raid will be showed here. + " + ::= { raidEntry 2 } + +raidStatus OBJECT-TYPE + SYNTAX Integer32(1..12) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "Synology Raid status + Each meanings of status represented describe below. + Normal(1): The raid functions normally. + Degrade(11): Degrade happens when a tolerable failure of disk(s) occurs. + Crashed(12): Raid has crashed and just uses for read-only operation. + + Note: + Other status will be showed when creating or deleting raids, including below status, Repairing(2), Migrating(3), Expanding(4), Deleting(5), Creating(6), RaidSyncing(7), RaidParityChecking(8), RaidAssembling(9) and Canceling(10). + " + ::= { raidEntry 3 } + + +raidConformance OBJECT IDENTIFIER ::= { synoRaid 2 } +raidCompliances OBJECT IDENTIFIER ::= { raidConformance 1 } +raidGroups OBJECT IDENTIFIER ::= { raidConformance 2 } + +raidCompliance MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for synoRaid entities which + implement the SYNOLOGY RAID MIB." + MODULE -- this module + MANDATORY-GROUPS { raidGroup } + + ::= { raidCompliances 1 } + +raidGroup OBJECT-GROUP + OBJECTS { raidName, + raidStatus} + STATUS current + DESCRIPTION + "A collection of objects providing basic instrumentation and + control of an synology raid entity." + ::= { raidGroups 1 } + +END