Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
3.8 KiB
PHP
Raw Permalink Normal View History

2018-02-05 07:39:13 -06:00
<?php
/**
* Comware.php
*
* H3C/HPE Comware OS
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2021-02-09 00:29:04 +01:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-02-05 07:39:13 -06:00
*
2021-02-09 00:29:04 +01:00
* @link https://www.librenms.org
2021-09-10 20:09:53 +02:00
*
2018-02-05 07:39:13 -06:00
* @copyright 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\OS;
2020-09-18 08:12:07 -05:00
use App\Models\Device;
2020-11-23 15:35:35 -06:00
use App\Models\Mempool;
use Illuminate\Support\Collection;
2018-02-05 07:39:13 -06:00
use LibreNMS\Device\Processor;
2020-11-23 15:35:35 -06:00
use LibreNMS\Interfaces\Discovery\MempoolsDiscovery;
2018-02-05 07:39:13 -06:00
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\OS;
2020-11-23 15:35:35 -06:00
class Comware extends OS implements MempoolsDiscovery, ProcessorDiscovery
2018-02-05 07:39:13 -06:00
{
2020-09-18 08:12:07 -05:00
public function discoverOS(Device $device): void
{
parent::discoverOS($device); // yaml
// serial
$serial_nums = explode("\n", snmp_walk($this->getDeviceArray(), 'hh3cEntityExtManuSerialNum', '-Osqv', 'HH3C-ENTITY-EXT-MIB'));
$this->getDevice()->serial = $serial_nums[0]; // use the first s/n
}
2018-02-05 07:39:13 -06:00
/**
* Discover processors.
* Returns an array of LibreNMS\Device\Processor objects that have been discovered
*
* @return array Processors
*/
public function discoverProcessors()
{
2020-11-23 15:35:35 -06:00
$processors = [];
$procdata = snmpwalk_group($this->getDeviceArray(), 'hh3cEntityExtCpuUsage', 'HH3C-ENTITY-EXT-MIB');
2018-02-05 07:39:13 -06:00
2020-11-23 15:35:35 -06:00
if (empty($procdata)) {
return $processors;
2018-02-05 07:39:13 -06:00
}
2020-11-23 15:35:35 -06:00
$entity_data = $this->getCacheByIndex('entPhysicalName', 'ENTITY-MIB');
2018-02-05 07:39:13 -06:00
foreach ($procdata as $index => $usage) {
2020-11-23 15:35:35 -06:00
if ($usage['hh3cEntityExtCpuUsage'] != 0) {
2018-02-05 07:39:13 -06:00
$processors[] = Processor::discover(
$this->getName(),
$this->getDeviceId(),
".1.3.6.1.4.1.25506.2.6.1.1.1.1.6.$index",
$index,
$entity_data[$index],
1,
2020-11-23 15:35:35 -06:00
$usage['hh3cEntityExtCpuUsage'],
2018-02-05 07:39:13 -06:00
null,
$index
);
}
}
return $processors;
}
2020-11-23 15:35:35 -06:00
public function discoverMempools()
{
$mempools = new Collection();
2020-11-23 15:35:35 -06:00
$data = snmpwalk_group($this->getDeviceArray(), 'hh3cEntityExtMemUsage', 'HH3C-ENTITY-EXT-MIB');
if (empty($data)) {
return $mempools; // avoid additional walks
}
$data = snmpwalk_group($this->getDeviceArray(), 'hh3cEntityExtMemSize', 'HH3C-ENTITY-EXT-MIB', 1, $data);
$entity_name = $this->getCacheByIndex('entPhysicalName', 'ENTITY-MIB');
$entity_class = $this->getCacheByIndex('entPhysicalClass', 'ENTITY-MIB');
foreach ($data as $index => $entry) {
if ($entity_class[$index] == 'module' && $entry['hh3cEntityExtMemUsage'] > 0) {
$mempools->push((new Mempool([
'mempool_index' => $index,
'mempool_type' => 'comware',
'mempool_class' =>'system',
'mempool_descr' => $entity_name[$index],
'mempool_precision' => 1,
'mempool_perc_oid' => ".1.3.6.1.4.1.25506.2.6.1.1.1.1.8.$index",
2021-11-14 14:58:13 -06:00
]))->fillUsage(null, $entry['hh3cEntityExtMemSize'] ?? null, null, $entry['hh3cEntityExtMemUsage'] ?? null));
2020-11-23 15:35:35 -06:00
}
}
return $mempools;
}
2018-02-05 07:39:13 -06:00
}