0

SNMP トラップを送信するための単純な python アプリを作成しようとしています。既に MIB テーブルを作成しており、localhost へのトラップの送信は正常に機能します。

from pysnmp.entity.rfc3413.oneliner import ntforg

ntfOrg = ntforg.NotificationOriginator()

errorIndication = ntfOrg.sendNotification(
    ntforg.CommunityData('public'),
    ntforg.UdpTransportTarget(('localhost', 162)),
    'trap',
    ntforg.MibVariable('MY-MIB', 'my_trap'),
    ( ntforg.MibVariable('MY-MIB', 'my_trap_var'), 0xAABBCCDD )
)

if errorIndication:
    print('Notification not sent: %s' % errorIndocation)

次に、トラップをプライベート サブネットワークに送信するようにコードを変更する必要があります。

その IP アドレス、サブネット マスク、およびゲートウェイ IP があります。仮定しましょう:

IP: 20.40.34.14

サブネットマスク: 255.255.255.224

ゲートウェイ: 20.40.34.10

ntforg.UdpTransportTarget(...)適切な議論を通じてこれを解決する方法はありますか?このクラス ( target.py) のソース コードを調べたところ、内部的には以下が使用されています。

socket.getaddrinfo(transportAddr[0], # localhost in example
                   transportAddr[1], # 162 in example
                   socket.AF_INET,
                   socket.SOCK_DGRAM,
                   socket.IPPROTO_UDP)[0][4][:2]
4

1 に答える 1

0

これは SNMP 固有のものではありません。おそらく、IP ルーティングにより関連性があります。

ホスト間の IP 接続を取得したら、20.40.34.14 を UdpTransportTarget に入れるだけです。UDP/162 パケットが Notification Receiver ホストに到達できる限り、問題なく動作するはずです。

ブロードキャスト TRAP を送信するオプションもあります。

于 2015-07-29T09:58:44.433 に答える