我在Windows上使用net-snmp C库.我想从MIB文件中解析与陷阱相关的信息.
我需要一些示例代码来执行此操作.我在http://www.net-snmp.org/上找不到任何有用的东西
我已经在带有 debian 10 buster 的 Linux 机器上安装了 net-snmp,现在我需要安装 snmp-mibs-downloader。
虽然我之前也跑过
sudo apt-get update
Run Code Online (Sandbox Code Playgroud)
执行时:
sudo apt-get install snmp-mibs-downloader
Run Code Online (Sandbox Code Playgroud)
显示以下屏幕输出,表明找不到请求的数据包:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package snmp-mibs-downloader is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'snmp-mibs-downloader' has no installation candidate
Run Code Online (Sandbox Code Playgroud)
我在网上看到可以通过编辑文件来解决这个问题
/etc/apt/sources.list.d/nonfree.list
Run Code Online (Sandbox Code Playgroud)
但它没有解释其中应该写什么。
感谢任何允许我安装 snmp-mibs-downloader 的帮助。
我对SNMP有一点了解,但还不够.我需要开发一个可以读取标准SNMP MIB并读/写各种属性的应用程序.网络端没有问题,但实际的MIB以及它们可能包含的内容对我来说是一种黑色艺术.
我相信我应该能够使用LIBSMI来"解析"MIB,但我真的不明白'解析器'的输出是什么,以及如何最好地使用它.
欢迎所有建议......
我正在从MIB编写SNMP管理器和模拟SNMP代理(以测试管理器).我有一个类似于下面的表,管理员应该能够添加/删除行.使用RowStatus执行此操作的习惯方法是什么?RowStatus是第一个设置的吗?PDU中可以包含其他OID吗?
我最初的用例是启动时表是空的.所以,如果我发送这样的SET PDU:
createStuffEntry.1.1.1 = 1
createStuffEntry.2.1.1 = 1
createStuffEntry.3.1.1 = 99
createStuffEntry.4.1.1 = "Dustbunnies"
createStuffEntry.5.1.1 = 5
Run Code Online (Sandbox Code Playgroud)
这应该适用于下面的定义吗?如果省略cRowStatus会发生什么?
createStuffTable OBJECT-TYPE
SYNTAX SEQUENCE OF CreateStuffEntry
ACCESS not-accessible
STATUS mandatory
DESCRIPTION
"A table for creating stuff."
::= { parentGroup 1 }
createStuffEntry OBJECT-TYPE
SYNTAX CreateStuffEntry
ACCESS not-accessible
STATUS mandatory
DESCRIPTION
"An entry for building a stuff to create."
INDEX { cPlanID, cID }
::= { createStuffTable 1 }
CreateStuffEntry ::=
SEQUENCE {
cPlanID
INTEGER,
cID
INTEGER,
cTemplateID
INTEGER,
cStuffName
DisplayString,
cRowStatus …
Run Code Online (Sandbox Code Playgroud) 这是我在net:snmp
使用perl时用于遍历表的代码:
#! /usr/local/bin/perl
use strict;
use warnings;
use Net::SNMP qw(:snmp);
my $OID_hrSystem = '1.3.6.1.2.1.25.1';
my $OID_ifPhysAddress = '1.3.6.1.2.1.2.2.1.6';
my ($session, $error) = Net::SNMP->session(
-hostname => shift || 'localhost',
-community => shift || 'public',
-nonblocking => 1,
-translate => [-octetstring => 0],
-version => 'snmpv2c',
);
if (!defined $session) {
printf "ERROR: %s.\n", $error;
exit 1;
}
my %table; # Hash to store the results
my $result = $session->get_bulk_request(
-varbindlist => [ $OID_hrSystem ],
-callback => [ \&table_callback, \%table …
Run Code Online (Sandbox Code Playgroud) 我使用以下简单脚本:
from pysnmp.entity.rfc3413.oneliner import cmdgen
errorIndication, errorStatus, errorIndex, \
varBindTable = cmdgen.CommandGenerator().bulkCmd(
cmdgen.CommunityData('test-agent', 'public'),
cmdgen.UdpTransportTarget(('IP.IP.IP.IP', 161)),
0,
1,
(1,3,6,1,2,1,4,24,4,1,2,169,254)
)
if errorIndication:
print errorIndication
else:
if errorStatus:
print '%s at %s\n' % (
errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
)
else:
for varBindTableRow in varBindTable:
for name, val in varBindTableRow:
print '%s = %s' % (name.prettyPrint(), val.prettyPrint())
Run Code Online (Sandbox Code Playgroud)
从命令行使用snmpwalk到此设备返回预期结果.但脚本返回超时之前未收到SNMP响应.如果我省略这个OID,那么一切正常.所以问题在于这个OID
这里tcpdump统计:
/usr/sbin/tcpdump -nn -vv -s0 -A host HOST and udp
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
12:15:31.494920 …
Run Code Online (Sandbox Code Playgroud) 我最近更改了我的自定义 MIB 文件以包含表,而不仅仅是标量,它会验证,我可以创建子代理等,但是如果我尝试阅读它,它会说没有条目:
snmptable -v1 -c public hostname:10161 myMibName::myTable
myMibName::myTable: No entries
Run Code Online (Sandbox Code Playgroud)
好吧,我没有在我的代理代码中向该表添加任何默认/示例行。
如果我尝试使用 snmpset 设置表的某些值,就像我在标量上所做的那样,它总是失败,因此表需要自己的语法。
如何使用 snmpset 或类似内容向表中添加一行?
例如,示例表可能看起来如此简单,其中 'myString' 是索引:
MyTableEntrySequence::= SEQUENCE {
myString
OCTET STRING,
test1
Integer32,
test2
Integer32
Run Code Online (Sandbox Code Playgroud)
}
编辑:我没有在我的表中使用 RowStatus。我是否需要使用 RowStatus 才能添加新行?
EDIT2:我已经从 net-snmp 样本编译了 data_set.c 代理,它用一些数据填充样本表,并可以使用 snmptable 查询其内容:
snmpwalk -v 1 -c public hostname:10161 netSnmpIETFWGTable
NET-SNMP-EXAMPLES-MIB::nsIETFWGChair1."snmpv3" = STRING: "Russ Mundy"
NET-SNMP-EXAMPLES-MIB::nsIETFWGChair2."snmpv3" = STRING: "David Harrington"
Run Code Online (Sandbox Code Playgroud) 客户要求我们将 SNMP 陷阱发送到他们的 Nagios 服务器,而不是电子邮件警报。昨天之前我对 SNMP 唯一了解的是它听起来像一个缩写词,所以请原谅(并纠正我)我对它可能有的任何误解。
陷阱中需要发送的唯一信息与我们向客户端发出警报的事件的数据有关,这只是从我们的数据库中提取的几个值。不用说,这些不在任何类型的 MIB 中,也没有任何 OID,这就是我无法找到答案的地方。
我无法弄清楚如何在不使用 MIB OID(我没有)的情况下将特定数据添加到陷阱中。
我正在使用 PySNMP 生成请求,但现在只有不完整的代码,因为我不确定如何将我们的数据合并到数据包中。
from pysnmp.hlapi import *
def sendSNMP(destination, community_string, data):
community = CommunityData(community_string, mpModel = 0)
target = UdpTransportTarget((destination, 162))
notification_type = None
req = sendNotification(SnmpEngine(), community, target, ContextData(), 'trap', notification_type)
errorIndication, errorStatus, errorIndex, varBinds = next(req)
Run Code Online (Sandbox Code Playgroud)
任何帮助表示感谢!谢谢。
我正在尝试编写一个python SNMP代理,我可以将其嵌入到我的python应用程序中,以便OpenNMS可以远程监视应用程序.OpenNMS希望代理实现HOST-RESOURCES-MIB
查询两个字段 hrSWRunName
和hrSWRunStatus
.
我把一个pysnmp示例作为我的代码的基础,并在我认为必要时编辑它.生成的代码如下所示:
import logging
from pysnmp import debug
from pysnmp.carrier.asyncore.dgram import udp
from pysnmp.entity import engine, config
from pysnmp.entity.rfc3413 import cmdrsp, context
from pysnmp.proto.api import v2c
from pysnmp.smi import builder, instrum, exval
# debug.setLogger(debug.Debug('all'))
formatting = '[%(asctime)s-%(levelname)s]-(%(module)s) %(message)s'
logging.basicConfig(level=logging.DEBUG, format=formatting, )
logging.info("Starting....")
# Create SNMP engine
snmpEngine = engine.SnmpEngine()
# Transport setup
# UDP over IPv4
config.addTransport(
snmpEngine,
udp.domainName,
udp.UdpTransport().openServerMode(('localhost', 12345))
)
# SNMPv2c setup
# SecurityName <-> CommunityName mapping.
config.addV1System(snmpEngine, 'my-area', 'public') …
Run Code Online (Sandbox Code Playgroud)