acamposm/snmp-poller 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

acamposm/snmp-poller

Composer 安装命令:

composer require acamposm/snmp-poller

包简介

SNMP poller class

README 文档

README

Packagist PHP Version Support License Latest Stable Version StyleCI Total Downloads

This Laravel package allows you to run SNMP queries to the snmp-agent of network hosts through laravel applications.

Before you run any SNMP query in your Laravel application, you must install snmp in the operating system and enable the PHP extension ext-php in the php.ini to make queries.

Installation

Requirements

At the Operating System level, you need to install 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

At php.ini enable the extension ext-php.

Composer Install

You can install the package via composer:

composer require acamposm/snmp-poller

Publish vendor assets

Running this command, you can publish the vendor assets. This allows to modify the default package configuration.

php artisan snmp:install

Usage

Single SNMP Poller class

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();

The output of an SNMP query to the snmp-agent of a network host with a single SNMP Poller class returns an array of objects with the data inside the data field.

Note: For demonstration purposes, all ports between 3 and 22 have been removed from the output of the query.

=> [
  "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",
  },
]

Multiple SNMP Pollers classes

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();

The output of an SNMP query to the snmp-agent of a network host with multiple SNMP Poller classes returns an array of objects with the data inside the data field.

Note: For demonstration purposes, all ports between 3 and 22 have been removed from the output of the query.

=> [
  "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",
  },
]

Testing

For running the tests, in the console run:

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email angel.campos.m@outlook.com instead of using the issue tracker.

Standards

The php package IPv4 Address Converter, comply with the next standards:

Credits

License

The MIT License (MIT). Please see License File for more information.

acamposm/snmp-poller 适用场景与选型建议

acamposm/snmp-poller 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 420 次下载、GitHub Stars 达 16, 最近一次更新时间为 2020 年 07 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「snmp」 「acamposm」 「snmp-poller」 「poller」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 acamposm/snmp-poller 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 acamposm/snmp-poller 我们能提供哪些服务?
定制开发 / 二次开发

基于 acamposm/snmp-poller 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 420
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-11