mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
VMWare Guest State Traps and UI (#11035)
* Initial push * power trap tests * vmware heartbeat trap tests * heartbeat trap test * created utilclass for common functions * Changed util class name to better reflect its use * make vm power state changes to db * Traps will modify DB * Removed unecesarry relationship * Added vminfo modelfactory, tests, and fixed format * Added suspended state to ui
This commit is contained in:
committed by
Jellyfrog
parent
f25e3efa53
commit
a342a45b74
69
LibreNMS/Snmptrap/Handlers/VmwTrapUtil.php
Normal file
69
LibreNMS/Snmptrap/Handlers/VmwTrapUtil.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* VmwTrapUtil.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* Common utility class for handling VmWare ESXi traps.
|
||||
*
|
||||
* Assuming VMWare Tools is installed the VMHost will receive a periodic
|
||||
* heartbeat from a VMGuest. This trap is sent once a heartbeat is
|
||||
* received after not receiving heartbeats for a configured period
|
||||
* of time.
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 KanREN, Inc.
|
||||
* @author Heath Barnhart <hbarnhart@kanren.net>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Snmptrap\Handlers;
|
||||
|
||||
class VmwTrapUtil
|
||||
{
|
||||
/**
|
||||
* Get the VMGuest hostname
|
||||
*
|
||||
* @param Trap $trap
|
||||
* @return string
|
||||
*/
|
||||
public static function getGuestName($trap)
|
||||
{
|
||||
return $trap->getOidData($trap->findOid('VMWARE-VMINFO-MIB::vmwVmDisplayName'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the VMGuest ID number
|
||||
*
|
||||
* @param Trap $trap
|
||||
* @return string
|
||||
*/
|
||||
public static function getGuestId($trap)
|
||||
{
|
||||
return $trap->getOidData($trap->findOid('VMWARE-VMINFO-MIB::vmwVmID'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the VMGuest configuration path
|
||||
*
|
||||
* @param Trap $trap
|
||||
* @return string
|
||||
*/
|
||||
public static function getGuestConfigPath($trap)
|
||||
{
|
||||
return $trap->getOidData($trap->findOid('VMWARE-VMINFO-MIB::vmwVmConfigFilePath'));
|
||||
}
|
||||
}
|
54
LibreNMS/Snmptrap/Handlers/VmwVmHBDetected.php
Normal file
54
LibreNMS/Snmptrap/Handlers/VmwVmHBDetected.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* VmwVmHBDetected.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* Assuming VMWare Tools is installed the VMHost will receive a periodic
|
||||
* heartbeat from a VMGuest. This trap is sent once a heartbeat is
|
||||
* received after not receiving heartbeats for a configured period
|
||||
* of time.
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 KanREN, Inc.
|
||||
* @author Heath Barnhart <hbarnhart@kanren.net>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Snmptrap\Handlers;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Interfaces\SnmptrapHandler;
|
||||
use LibreNMS\Snmptrap\Handlers\VmwTrapUtil;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
use Log;
|
||||
|
||||
class VmwVmHBDetected implements SnmptrapHandler
|
||||
{
|
||||
/**
|
||||
* Handle snmptrap.
|
||||
* Data is pre-parsed and delivered as a Trap.
|
||||
*
|
||||
* @param Device $device
|
||||
* @param Trap $trap
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Device $device, Trap $trap)
|
||||
{
|
||||
$vmGuestName = VmwTrapUtil::getGuestName($trap);
|
||||
Log::event("Heartbeat from guest $vmGuestName detected", $device->device_id, 'trap', 1);
|
||||
}
|
||||
}
|
53
LibreNMS/Snmptrap/Handlers/VmwVmHBLost.php
Normal file
53
LibreNMS/Snmptrap/Handlers/VmwVmHBLost.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* VmwVmHBLost.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* If VMWaretools is install the VMGuest will periodically send a
|
||||
* heartbeat to the VMHost. If the host does not receive a heartbeat
|
||||
* within a configured time period this trap is sent.
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 KanREN, Inc.
|
||||
* @author Heath Barnhart <hbarnhart@kanren.net>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Snmptrap\Handlers;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Interfaces\SnmptrapHandler;
|
||||
use LibreNMS\Snmptrap\Handlers\VmwTrapUtil;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
use Log;
|
||||
|
||||
class VmwVmHBLost implements SnmptrapHandler
|
||||
{
|
||||
/**
|
||||
* Handle snmptrap.
|
||||
* Data is pre-parsed and delivered as a Trap.
|
||||
*
|
||||
* @param Device $device
|
||||
* @param Trap $trap
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Device $device, Trap $trap)
|
||||
{
|
||||
$vmGuestName = VmwTrapUtil::getGuestName($trap);
|
||||
Log::event("Heartbeat from guest $vmGuestName lost", $device->device_id, 'trap', 4);
|
||||
}
|
||||
}
|
57
LibreNMS/Snmptrap/Handlers/VmwVmPoweredOff.php
Normal file
57
LibreNMS/Snmptrap/Handlers/VmwVmPoweredOff.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* VmwVmPoweredOff.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* VMWare guest was powered off.
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 KanREN, Inc.
|
||||
* @author Heath Barnhart <hbarnhart@kanren.net>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Snmptrap\Handlers;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Interfaces\SnmptrapHandler;
|
||||
use LibreNMS\Snmptrap\Handlers\VmwTrapUtil;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
use Log;
|
||||
|
||||
class VmwVmPoweredOff implements SnmptrapHandler
|
||||
{
|
||||
/**
|
||||
* Handle snmptrap.
|
||||
* Data is pre-parsed and delivered as a Trap.
|
||||
*
|
||||
* @param Device $device
|
||||
* @param Trap $trap
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Device $device, Trap $trap)
|
||||
{
|
||||
$vmGuestName = VmwTrapUtil::getGuestName($trap);
|
||||
|
||||
$vminfo = $device->vminfo()->where('vmwVmDisplayName', $vmGuestName)->first();
|
||||
$vminfo->vmwVmState = "powered off";
|
||||
|
||||
Log::event("Guest $vmGuestName was powered off", $device->device_id, 'trap', 2);
|
||||
|
||||
$vminfo->save();
|
||||
}
|
||||
}
|
57
LibreNMS/Snmptrap/Handlers/VmwVmPoweredOn.php
Normal file
57
LibreNMS/Snmptrap/Handlers/VmwVmPoweredOn.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* VmwVmPoweredOn.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* VMWare guest was powered on.
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 KanREN, Inc.
|
||||
* @author Heath Barnhart <hbarnhart@kanren.net>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Snmptrap\Handlers;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Interfaces\SnmptrapHandler;
|
||||
use LibreNMS\Snmptrap\Handlers\VmwTrapUtil;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
use Log;
|
||||
|
||||
class VmwVmPoweredOn implements SnmptrapHandler
|
||||
{
|
||||
/**
|
||||
* Handle snmptrap.
|
||||
* Data is pre-parsed and delivered as a Trap.
|
||||
*
|
||||
* @param Device $device
|
||||
* @param Trap $trap
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Device $device, Trap $trap)
|
||||
{
|
||||
$vmGuestName = VmwTrapUtil::getGuestName($trap);
|
||||
|
||||
$vminfo = $device->vminfo()->where('vmwVmDisplayName', $vmGuestName)->first();
|
||||
$vminfo->vmwVmState = "powered on";
|
||||
|
||||
Log::event("Guest $vmGuestName was powered on", $device->device_id, 'trap', 2);
|
||||
|
||||
$vminfo->save();
|
||||
}
|
||||
}
|
57
LibreNMS/Snmptrap/Handlers/VmwVmSuspended.php
Normal file
57
LibreNMS/Snmptrap/Handlers/VmwVmSuspended.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* VmwVmSuspended.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* VMWare guest was suspended.
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 KanREN, Inc.
|
||||
* @author Heath Barnhart <hbarnhart@kanren.net>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Snmptrap\Handlers;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Interfaces\SnmptrapHandler;
|
||||
use LibreNMS\Snmptrap\Handlers\VmwTrapUtil;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
use Log;
|
||||
|
||||
class VmwVmSuspended implements SnmptrapHandler
|
||||
{
|
||||
/**
|
||||
* Handle snmptrap.
|
||||
* Data is pre-parsed and delivered as a Trap.
|
||||
*
|
||||
* @param Device $device
|
||||
* @param Trap $trap
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Device $device, Trap $trap)
|
||||
{
|
||||
$vmGuestName = VmwTrapUtil::getGuestName($trap);
|
||||
|
||||
$vminfo = $device->vminfo()->where('vmwVmDisplayName', $vmGuestName)->first();
|
||||
$vminfo->vmwVmState = "suspended";
|
||||
|
||||
Log::event("Guest $vmGuestName has been suspended", $device->device_id, 'trap', 2);
|
||||
|
||||
$vminfo->save();
|
||||
}
|
||||
}
|
@@ -717,6 +717,11 @@ class Device extends BaseModel
|
||||
return $this->belongsToMany('App\Models\User', 'devices_perms', 'device_id', 'user_id');
|
||||
}
|
||||
|
||||
public function vminfo()
|
||||
{
|
||||
return $this->hasMany('App\Models\Vminfo', 'device_id');
|
||||
}
|
||||
|
||||
public function vrfLites()
|
||||
{
|
||||
return $this->hasMany('App\Models\VrfLite', 'device_id');
|
||||
|
@@ -70,5 +70,10 @@ return [
|
||||
'RUCKUS-SZ-EVENT-MIB::ruckusSZClusterBackToInServiceTrap' => \LibreNMS\Snmptrap\Handlers\RuckusSzClusterInService::class,
|
||||
'SNMPv2-MIB::authenticationFailure' => \LibreNMS\Snmptrap\Handlers\AuthenticationFailure::class,
|
||||
'SNMPv2-MIB::coldStart' => \LibreNMS\Snmptrap\Handlers\ColdBoot::class,
|
||||
'VMWARE-VMINFO-MIB::vmwVmHBDetected' => \LibreNMS\Snmptrap\Handlers\VmwVmHBDetected::class,
|
||||
'VMWARE-VMINFO-MIB::vmwVmHBLost' => \LibreNMS\Snmptrap\Handlers\VmwVmHBLost::class,
|
||||
'VMWARE-VMINFO-MIB::vmwVmPoweredOn' => \LibreNMS\Snmptrap\Handlers\VmwVmPoweredOn::class,
|
||||
'VMWARE-VMINFO-MIB::vmwVmPoweredOff' => \LibreNMS\Snmptrap\Handlers\VmwVmPoweredOff::class,
|
||||
'VMWARE-VMINFO-MIB::vmwVmSuspended' => \LibreNMS\Snmptrap\Handlers\VmwVmSuspended::class,
|
||||
]
|
||||
];
|
||||
|
@@ -9,7 +9,7 @@
|
||||
| you a convenient way to create models for testing and seeding your
|
||||
| database. Just tell the factory how a default model should look.
|
||||
|
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
||||
|
||||
@@ -43,24 +43,24 @@ $factory->state(App\Models\User::class, 'read', function ($faker) {
|
||||
|
||||
$factory->define(\App\Models\Bill::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'bill_name' => $faker->text
|
||||
'bill_name' => $faker->text,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(\App\Models\Device::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'hostname' => $faker->domainWord.'.'.$faker->domainName,
|
||||
'ip' => $faker->randomElement([$faker->ipv4, $faker->ipv6]),
|
||||
'status' => $status = random_int(0, 1),
|
||||
'hostname' => $faker->domainWord . '.' . $faker->domainName,
|
||||
'ip' => $faker->randomElement([$faker->ipv4, $faker->ipv6]),
|
||||
'status' => $status = random_int(0, 1),
|
||||
'status_reason' => $status == 0 ? $faker->randomElement(['snmp', 'icmp']) : '', // allow invalid states?
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(\App\Models\Port::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'ifIndex' => $faker->unique()->numberBetween(),
|
||||
'ifName' => $faker->text(20),
|
||||
'ifDescr' => $faker->text(255),
|
||||
'ifIndex' => $faker->unique()->numberBetween(),
|
||||
'ifName' => $faker->text(20),
|
||||
'ifDescr' => $faker->text(255),
|
||||
'ifLastChange' => $faker->unixTime(),
|
||||
];
|
||||
});
|
||||
@@ -101,7 +101,7 @@ $factory->define(\App\Models\Ipv4Address::class, function (Faker\Generator $fake
|
||||
|
||||
$factory->define(\App\Models\Ipv4Network::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'ipv4_network' => $faker->ipv4 . '/' . $faker->numberBetween(0, 32),
|
||||
'ipv4_network' => $faker->ipv4 . '/' . $faker->numberBetween(0, 32),
|
||||
];
|
||||
});
|
||||
|
||||
@@ -119,3 +119,15 @@ $factory->define(\App\Models\Syslog::class, function (Faker\Generator $faker) {
|
||||
'msg' => $faker->text(),
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(\App\Models\Vminfo::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'vm_type' => $faker->text(16),
|
||||
'vmwVmVMID' => $faker->randomDigit,
|
||||
'vmwVmDisplayName' => $faker->domainWord . '.' . $faker->domainName,
|
||||
'vmwVmGuestOS' => $faker->text(128),
|
||||
'vmwVmMemSize' => $faker->randomDigit,
|
||||
'vmwVmCpus' => $faker->randomDigit,
|
||||
'vmwVmState' => $faker->randomElement(['powered on', 'powered off', 'suspended']),
|
||||
];
|
||||
});
|
||||
|
@@ -16,7 +16,6 @@
|
||||
* @author Aldemir Akpinar <aldemir.akpinar@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
$pagetitle[] = 'Virtual Machines';
|
||||
?>
|
||||
<div class="table-responsive">
|
||||
@@ -69,6 +68,8 @@ var grid = $("#vminfo").bootgrid({
|
||||
var response = '<span class="label label-success">ON</span>';
|
||||
} else if (row.powerstat == "powered off") {
|
||||
var response = '<span class="label label-default">OFF</span>';
|
||||
} else if (row.powerstat == "suspended") {
|
||||
var response = '<span class="label label-warning">SUSPEND</span>';
|
||||
}
|
||||
return response;
|
||||
},
|
||||
|
@@ -12,8 +12,10 @@ echo '</td>';
|
||||
|
||||
if ($vm['vmwVmState'] == 'powered off') {
|
||||
echo '<td class="list"><span style="min-width:40px; display:inline-block;" class="label label-default">OFF</span></td>';
|
||||
} else {
|
||||
} elseif ($vm['vmwVmState'] == 'powered on') {
|
||||
echo '<td class="list"><span style="min-width:40px; display:inline-block;" class="label label-success">ON</span></td>';
|
||||
} elseif ($vm['vmwVmState'] == 'suspended') {
|
||||
echo '<td class="list"><span style="min-width:40px; display:inline-block;" class="label label-warning">SUSPEND</span></td>';
|
||||
}
|
||||
|
||||
if ($vm['vmwVmGuestOS'] == 'E: tools not installed') {
|
||||
|
80
tests/Feature/SnmpTraps/VmwHBTest.php
Normal file
80
tests/Feature/SnmpTraps/VmwHBTest.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* VmwHBTest.php
|
||||
* -Description-
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
* Tests vmwVmHBLost and vmwVmHBDetected traps from VMWare ESXi hosts.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 KanREN, Inc
|
||||
* @author Heath Barnhart <hbarnhart@kanren.net>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Tests;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Snmptrap\Dispatcher;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
use LibreNMS\Tests\Feature\SnmpTraps\SnmpTrapTestCase;
|
||||
|
||||
class VmwHBTest extends SnmpTrapTestCase
|
||||
{
|
||||
public function testVmwVmHBLostTrap()
|
||||
{
|
||||
$device = factory(Device::class)->create();
|
||||
$guest = factory(Device::class)->create();
|
||||
|
||||
$trapText = "$device->hostname
|
||||
UDP: [$device->ip]:28386->[10.10.10.100]:162
|
||||
DISMAN-EVENT-MIB::sysUpTimeInstance 5:18:30:26.00
|
||||
SNMPv2-MIB::snmpTrapOID.0 VMWARE-VMINFO-MIB::vmwVmHBLost
|
||||
VMWARE-VMINFO-MIB::vmwVmID.0 28 VMWARE-VMINFO-MIB::vmwVmConfigFilePath.0 /vmfs/volumes/50101bda-eaf6ac7e-7e44-d4ae5267fb9f/$guest->hostname/$guest->hostname.vmx
|
||||
VMWARE-VMINFO-MIB::vmwVmDisplayName.28 $guest->hostname
|
||||
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 $guest->ip
|
||||
SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 \"public\"
|
||||
SNMPv2-MIB::snmpTrapEnterprise.0 VMWARE-PRODUCTS-MIB::vmwESX";
|
||||
|
||||
$trap = new Trap($trapText);
|
||||
$message = "Heartbeat from guest $guest->hostname lost";
|
||||
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4);
|
||||
|
||||
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle VmwVmHBLostTrap');
|
||||
}
|
||||
|
||||
public function testVmwVmHBDetectedTrap()
|
||||
{
|
||||
$device = factory(Device::class)->create();
|
||||
$guest = factory(Device::class)->create();
|
||||
|
||||
$trapText = "$device->hostname
|
||||
UDP: [$device->ip]:28386->[10.10.10.100]:162
|
||||
DISMAN-EVENT-MIB::sysUpTimeInstance 5:18:30:26.00
|
||||
SNMPv2-MIB::snmpTrapOID.0 VMWARE-VMINFO-MIB::vmwVmHBDetected
|
||||
VMWARE-VMINFO-MIB::vmwVmID.0 28 VMWARE-VMINFO-MIB::vmwVmConfigFilePath.0 /vmfs/volumes/50101bda-eaf6ac7e-7e44-d4ae5267fb9f/$guest->hostname/$guest->hostname.vmx
|
||||
VMWARE-VMINFO-MIB::vmwVmDisplayName.28 $guest->hostname
|
||||
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 $guest->ip
|
||||
SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 \"public\"
|
||||
SNMPv2-MIB::snmpTrapEnterprise.0 VMWARE-PRODUCTS-MIB::vmwESX";
|
||||
|
||||
$trap = new Trap($trapText);
|
||||
$message = "Heartbeat from guest $guest->hostname detected";
|
||||
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 1);
|
||||
|
||||
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle VmwVmHBDetectedTrap');
|
||||
}
|
||||
}
|
103
tests/Feature/SnmpTraps/VmwPowerStateTest.php
Normal file
103
tests/Feature/SnmpTraps/VmwPowerStateTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* VmwPowerStateTest.php
|
||||
* -Description-
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
* Tests vmwVmPoweredOff, vmwVmPoweredOn, and vmwVmSuspended traps from VMWare ESXi hosts.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2019 KanREN, Inc
|
||||
* @author Heath Barnhart <hbarnhart@kanren.net>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Tests;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\Vminfo;
|
||||
use LibreNMS\Snmptrap\Dispatcher;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
use LibreNMS\Tests\Feature\SnmpTraps\SnmpTrapTestCase;
|
||||
|
||||
class VmwPowerStateTest extends SnmpTrapTestCase
|
||||
{
|
||||
public function testVmwVmPoweredOffTrap()
|
||||
{
|
||||
$device = factory(Device::class)->create();
|
||||
$guest = factory(Vminfo::class)->create(['device_id' => $device->device_id]);
|
||||
|
||||
$trapText = "$device->hostname
|
||||
UDP: [$device->ip]:28386->[10.10.10.100]:162
|
||||
DISMAN-EVENT-MIB::sysUpTimeInstance 5:18:30:26.00
|
||||
SNMPv2-MIB::snmpTrapOID.0 VMWARE-VMINFO-MIB::vmwVmPoweredOff
|
||||
VMWARE-VMINFO-MIB::vmwVmID.0 28 VMWARE-VMINFO-MIB::vmwVmConfigFilePath.0 /vmfs/volumes/50101bda-eaf6ac7e-7e44-d4ae5267fb9f/$guest->vmwVmDisplayName/$guest->vmwVmDisplayName.vmx
|
||||
VMWARE-VMINFO-MIB::vmwVmDisplayName.28 $guest->vmwVmDisplayName
|
||||
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 $device->ip
|
||||
SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 \"public\"
|
||||
SNMPv2-MIB::snmpTrapEnterprise.0 VMWARE-PRODUCTS-MIB::vmwESX";
|
||||
|
||||
$trap = new Trap($trapText);
|
||||
$message = "Guest $guest->vmwVmDisplayName was powered off";
|
||||
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
|
||||
|
||||
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle VmwVmPoweredOffTrap');
|
||||
}
|
||||
|
||||
public function testVmwVmPoweredONTrap()
|
||||
{
|
||||
$device = factory(Device::class)->create();
|
||||
$guest = factory(Vminfo::class)->create(['device_id' => $device->device_id]);
|
||||
|
||||
$trapText = "$device->hostname
|
||||
UDP: [$device->ip]:28386->[10.10.10.100]:162
|
||||
DISMAN-EVENT-MIB::sysUpTimeInstance 5:18:30:26.00
|
||||
SNMPv2-MIB::snmpTrapOID.0 VMWARE-VMINFO-MIB::vmwVmPoweredOn
|
||||
VMWARE-VMINFO-MIB::vmwVmID.0 28 VMWARE-VMINFO-MIB::vmwVmConfigFilePath.0 /vmfs/volumes/50101bda-eaf6ac7e-7e44-d4ae5267fb9f/$guest->vmwVmDisplayName/$guest->vmwVmDisplayName.vmx
|
||||
VMWARE-VMINFO-MIB::vmwVmDisplayName.28 $guest->vmwVmDisplayName
|
||||
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 $device->ip
|
||||
SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 \"public\"
|
||||
SNMPv2-MIB::snmpTrapEnterprise.0 VMWARE-PRODUCTS-MIB::vmwESX";
|
||||
|
||||
$trap = new Trap($trapText);
|
||||
$message = "Guest $guest->vmwVmDisplayName was powered on";
|
||||
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
|
||||
|
||||
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle VmwVmPoweredOnTrap');
|
||||
}
|
||||
|
||||
public function testVmwVmSuspendedTrap()
|
||||
{
|
||||
$device = factory(Device::class)->create();
|
||||
$guest = factory(Vminfo::class)->create(['device_id' => $device->device_id]);
|
||||
|
||||
$trapText = "$device->hostname
|
||||
UDP: [$device->ip]:28386->[10.10.10.100]:162
|
||||
DISMAN-EVENT-MIB::sysUpTimeInstance 5:18:30:26.00
|
||||
SNMPv2-MIB::snmpTrapOID.0 VMWARE-VMINFO-MIB::vmwVmSuspended
|
||||
VMWARE-VMINFO-MIB::vmwVmID.0 28 VMWARE-VMINFO-MIB::vmwVmConfigFilePath.0 /vmfs/volumes/50101bda-eaf6ac7e-7e44-d4ae5267fb9f/$guest->vmwVmDisplayName/$guest->vmwVmDisplayName.vmx
|
||||
VMWARE-VMINFO-MIB::vmwVmDisplayName.28 $guest->vmwVmDisplayName
|
||||
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 $device->ip
|
||||
SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 \"public\"
|
||||
SNMPv2-MIB::snmpTrapEnterprise.0 VMWARE-PRODUCTS-MIB::vmwESX";
|
||||
|
||||
$trap = new Trap($trapText);
|
||||
$message = "Guest $guest->vmwVmDisplayName has been suspended";
|
||||
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
|
||||
|
||||
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle VmwVmSuspendedTrap');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user