acamposm / snmp-poller
SNMP轮询类
1.1.0
2021-05-18 09:38 UTC
Requires
- php: ^8.0
- ext-snmp: *
- illuminate/console: ^8.41
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-25 16:38:07 UTC
README
此Laravel包允许您通过Laravel应用程序对网络主机的snmp-agent运行SNMP查询。
在您的Laravel应用程序中运行任何SNMP查询之前,您必须在操作系统中安装snmp,并在php.ini中启用PHP扩展ext-php以进行查询。
安装
要求
在操作系统级别,您需要安装net-snmp。
Debian
apt-get install -y snmp
Centos / RHEL
yum install \ net-snmp.x86_64 \ net-snmp-agent-libs.x86_64 \ net-snmp-libs.x86_64 \ php-snmp.x86_64
在php.ini中启用扩展ext-php。
Composer安装
您可以通过composer安装此包
composer require acamposm/snmp-poller
发布供应商资源
运行此命令,您可以发布供应商资源。这允许修改默认包配置。
php artisan snmp:install
用法
单个SNMP轮询类
use Acamposm\SnmpPoller\SnmpPoller; use Acamposm\SnmpPoller\Pollers\IfTablePoller; use SNMP; $session = new SNMP(SNMP::VERSION_2C, '192.168.10.254', 'csnmpv2c'); $poller = new SnmpPoller(); $poller->setSnmpSession($session)->addPoller(IfTablePoller::class)->run();
使用单个SNMP轮询类对网络主机的snmp-agent进行SNMP查询的输出返回包含数据字段中数据的对象数组。
注意:出于演示目的,查询输出中已删除3到22之间的所有端口。
=> [
"IfTablePoller" => {#653
+"data": [
1 => [
"ifIndex" => 1,
"ifDescr" => "",
"ifType" => 6,
"ifMtu" => 1500,
"ifSpeed" => 1000000000,
"ifPhysAddress" => "90:6C:AC:62:82:5B",
"ifAdminStatus" => 1,
"ifOperStatus" => 1,
"ifLastChange" => 0,
"ifInOctets" => 3808861579,
"ifInUcastPkts" => 1130144532,
"ifInDiscards" => 0,
"ifInErrors" => 2,
"ifInUnknownProtos" => 0,
"ifOutOctets" => 1986123900,
"ifOutUcastPkts" => 735043481,
"ifOutDiscards" => 0,
"ifOutErrors" => 0,
],
2 => [
"ifIndex" => 2,
"ifDescr" => "",
"ifType" => 6,
"ifMtu" => 1500,
"ifSpeed" => 0,
"ifPhysAddress" => "90:6C:AC:62:82:5C",
"ifAdminStatus" => 1,
"ifOperStatus" => 2,
"ifLastChange" => 0,
"ifInOctets" => 0,
"ifInUcastPkts" => 0,
"ifInDiscards" => 0,
"ifInErrors" => 0,
"ifInUnknownProtos" => 0,
"ifOutOctets" => 0,
"ifOutUcastPkts" => 0,
"ifOutDiscards" => 0,
"ifOutErrors" => 0,
],
3 => [ ... ],
4 => [ ... ],
5 => [ ... ],
6 => [ ... ],
7 => [ ... ],
8 => [ ... ],
9 => [ ... ],
10 => [ ... ],
11 => [ ... ],
12 => [ ... ],
13 => [ ... ],
14 => [ ... ],
15 => [ ... ],
16 => [ ... ],
17 => [ ... ],
18 => [ ... ],
19 => [ ... ],
20 => [ ... ],
21 => [ ... ],
22 => [ ... ],
],
+"poller": "Acamposm\SnmpPoller\Pollers\IfTablePoller",
+"result": "OK",
+"table": "ifTable",
},
]
多个SNMP轮询类
use Acamposm\SnmpPoller\SnmpPoller; use Acamposm\SnmpPoller\Pollers\IfTablePoller; use Acamposm\SnmpPoller\Pollers\IfExtendedTablePoller; use Acamposm\SnmpPoller\Pollers\EntPhysicalTablePoller; use Acamposm\SnmpPoller\Pollers\LldpRemoteTablePoller; use SNMP; $session = new SNMP(SNMP::VERSION_2C, '192.168.10.254', 'csnmpv2c'); $poller = new SnmpPoller(); $pollerClasses = [ IfTablePoller::class, IfExtendedTablePoller::class, EntPhysicalTablePoller::class, LldpRemoteTablePoller::class, ]; $poller->setSnmpSession($session) ->addPollers($pollerClasses) ->run();
使用多个SNMP轮询类对网络主机的snmp-agent进行SNMP查询的输出返回包含数据字段中数据的对象数组。
注意:出于演示目的,查询输出中已删除3到22之间的所有端口。
=> [
"IfTablePoller" => {
+"data" => [
1 => [
"ifIndex" => 1,
"ifDescr" => "",
"ifType" => 6,
"ifMtu" => 1500,
"ifSpeed" => 1000000000,
"ifPhysAddress" => "90:6C:AC:62:82:5B",
"ifAdminStatus" => 1,
"ifOperStatus" => 1,
"ifLastChange" => 0,
"ifInOctets" => 2518775779,
"ifInUcastPkts" => 1129071509,
"ifInDiscards" => 0,
"ifInErrors" => 2,
"ifInUnknownProtos" => 0,
"ifOutOctets" => 1941896771,
"ifOutUcastPkts" => 734653319,
"ifOutDiscards" => 0,
"ifOutErrors" => 0,
],
2 => [
"ifIndex" => 2,
"ifDescr" => "",
"ifType" => 6,
"ifMtu" => 1500,
"ifSpeed" => 0,
"ifPhysAddress" => "90:6C:AC:62:82:5C",
"ifAdminStatus" => 1,
"ifOperStatus" => 2,
"ifLastChange" => 0,
"ifInOctets" => 0,
"ifInUcastPkts" => 0,
"ifInDiscards" => 0,
"ifInErrors" => 0,
"ifInUnknownProtos" => 0,
"ifOutOctets" => 0,
"ifOutUcastPkts" => 0,
"ifOutDiscards" => 0,
"ifOutErrors" => 0,
],
3 => [ ... ],
4 => [ ... ],
5 => [ ... ],
6 => [ ... ],
7 => [ ... ],
8 => [ ... ],
9 => [ ... ],
10 => [ ... ],
11 => [ ... ],
12 => [ ... ],
13 => [ ... ],
14 => [ ... ],
15 => [ ... ],
16 => [ ... ],
17 => [ ... ],
18 => [ ... ],
19 => [ ... ],
20 => [ ... ],
21 => [ ... ],
22 => [ ... ],
],
+"poller": "Acamposm\SnmpPoller\Pollers\IfTablePoller",
+"result": "OK",
+"table": "ifTable",
},
"IfExtendedTablePoller" => {
+"data" => [
1 => [
"ifName" => "wan1",
"ifInMulticastPkts" => 0,
"ifInBroadcastPkts" => 0,
"ifOutMulticastPkts" => 0,
"ifOutBroadcastPkts" => 0,
"ifHCInOctets" => 1123505241577,
"ifHCInUcastPkts" => 1129071513,
"ifHCInMulticastPkts" => 0,
"ifHCInBroadcastPkts" => 0,
"ifHCOutOctets" => 255344967343,
"ifHCOutUcastPkts" => 734653320,
"ifHCOutMulticastPkts" => 0,
"ifHCOutBroadcastPkts" => 0,
"ifLinkUpDownTrapEnable" => 1,
"ifHighSpeed" => 1000,
"ifPromiscuousMode" => 2,
"ifConnectorPresent" => 1,
"ifAlias" => "",
"ifCounterDiscontinuityTime" => 0,
],
2 => [
"ifName" => "wan2",
"ifInMulticastPkts" => 0,
"ifInBroadcastPkts" => 0,
"ifOutMulticastPkts" => 0,
"ifOutBroadcastPkts" => 0,
"ifHCInOctets" => 0,
"ifHCInUcastPkts" => 0,
"ifHCInMulticastPkts" => 0,
"ifHCInBroadcastPkts" => 0,
"ifHCOutOctets" => 0,
"ifHCOutUcastPkts" => 0,
"ifHCOutMulticastPkts" => 0,
"ifHCOutBroadcastPkts" => 0,
"ifLinkUpDownTrapEnable" => 1,
"ifHighSpeed" => 0,
"ifPromiscuousMode" => 2,
"ifConnectorPresent" => 1,
"ifAlias" => "",
"ifCounterDiscontinuityTime" => 0,
],
3 => [ ... ],
4 => [ ... ],
5 => [ ... ],
6 => [ ... ],
7 => [ ... ],
8 => [ ... ],
9 => [ ... ],
10 => [ ... ],
11 => [ ... ],
12 => [ ... ],
13 => [ ... ],
14 => [ ... ],
15 => [ ... ],
16 => [ ... ],
17 => [ ... ],
18 => [ ... ],
19 => [ ... ],
20 => [ ... ],
21 => [ ... ],
22 => [ ... ],
],
+"poller" => "Acamposm\SnmpPoller\Pollers\IfExtendedTablePoller",
+"result" => "OK",
+"table" => "ifXTable",
},
"EntPhysicalTablePoller" => {
+"data" => [
1 => [
"entPhysicalDescr" => "Fortinet FWF_51E, HW Serial#: FWF51E3U16000691",
"entPhysicalVendorType" => ".1.3.6.1.4.1.12356.516.516.0",
"entPhysicalContainedIn" => 0,
"entPhysicalClass" => 3,
"entPhysicalParentRelPos" => -1,
"entPhysicalName" => "FWF_51E",
"entPhysicalHardwareRev" => "",
"entPhysicalFirmwareRev" => "",
"entPhysicalSoftwareRev" => "FortiWiFi-51E v6.2.3,build1066,191218 (GA)",
"entPhysicalSerialNum" => "FWF51E3U16000691",
"entPhysicalMfgName" => "Fortinet",
"entPhysicalModelName" => "FWF_51E",
"entPhysicalAlias" => "",
"entPhysicalAssetID" => "",
"entPhysicalIsFRU" => 1,
],
2 => [
"entPhysicalDescr" => "Ethernet Port, Vitual Domain: root",
"entPhysicalVendorType" => ".0.0.0",
"entPhysicalContainedIn" => 1,
"entPhysicalClass" => 10,
"entPhysicalParentRelPos" => 1,
"entPhysicalName" => "wan1",
"entPhysicalHardwareRev" => "",
"entPhysicalFirmwareRev" => "",
"entPhysicalSoftwareRev" => "",
"entPhysicalSerialNum" => "",
"entPhysicalMfgName" => "",
"entPhysicalModelName" => "",
"entPhysicalAlias" => "",
"entPhysicalAssetID" => "",
"entPhysicalIsFRU" => 2,
],
3 => [
"entPhysicalDescr" => "Ethernet Port, Vitual Domain: root",
"entPhysicalVendorType" => ".0.0.0",
"entPhysicalContainedIn" => 1,
"entPhysicalClass" => 10,
"entPhysicalParentRelPos" => 2,
"entPhysicalName" => "wan2",
"entPhysicalHardwareRev" => "",
"entPhysicalFirmwareRev" => "",
"entPhysicalSoftwareRev" => "",
"entPhysicalSerialNum" => "",
"entPhysicalMfgName" => "",
"entPhysicalModelName" => "",
"entPhysicalAlias" => "",
"entPhysicalAssetID" => "",
"entPhysicalIsFRU" => 2,
],
4 => [
"entPhysicalDescr" => "Ethernet Port, Vitual Domain: root",
"entPhysicalVendorType" => ".0.0.0",
"entPhysicalContainedIn" => 1,
"entPhysicalClass" => 10,
"entPhysicalParentRelPos" => 3,
"entPhysicalName" => "modem",
"entPhysicalHardwareRev" => "",
"entPhysicalFirmwareRev" => "",
"entPhysicalSoftwareRev" => "",
"entPhysicalSerialNum" => "",
"entPhysicalMfgName" => "",
"entPhysicalModelName" => "",
"entPhysicalAlias" => "",
"entPhysicalAssetID" => "",
"entPhysicalIsFRU" => 2,
],
],
+"poller": "Acamposm\SnmpPoller\Pollers\EntPhysicalTablePoller",
+"result": "OK",
+"table": "entPhysical",
},
"LldpRemoteTablePoller" => {
+"data" => [
"710800216.10.1" => [
"lldpRemChassisIdSubtype" => 4,
"lldpRemChassisId" => "2C:FA:A2:27:2F:5C",
"lldpRemPortIdSubtype" => 7,
"lldpRemPortId" => "1021",
"lldpRemPortDesc" => "Alcatel-Lucent Enterprise 1/21",
"lldpRemSysName" => "WTG-OS6450P24-SW01",
"lldpRemSysDesc" => "Alcatel-Lucent Enterprise OS6450-P24 6.7.2.191.R04 GA, June 20, 2018.",
"lldpRemSysCapSupported" => "(",
"lldpRemSysCapEnabled" => "(",
],
],
+"poller" => "Acamposm\SnmpPoller\Pollers\LldpRemoteTablePoller",
+"result" => "OK",
+"table" => "lldpRemTable",
},
]
测试
要运行测试,请在控制台中运行
composer test
变更日志
请参阅变更日志以获取有关最近更改的更多信息。
贡献
请参阅贡献以获取详细信息。
安全性
如果您发现任何安全相关的问题,请通过电子邮件angel.campos.m@outlook.com而不是使用问题跟踪器。
标准
PHP包IPv4地址转换器符合以下标准
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。