blob: 48b40d11e086666d74fb3d7e5a157fcd01885a72 [file] [log] [blame]
Rich Bennett98476312018-08-25 10:43:15 -04001.. This work is licensed under a Creative Commons Attribution 4.0 International License.
2.. http://creativecommons.org/licenses/by/4.0
3
4Offered APIs
5============
6
Ladue, David (dl3158)bb896892018-10-16 16:29:58 -04007**trapd** supports the Simple Network Management Protocol (SNMP)
Rich Bennett98476312018-08-25 10:43:15 -04008standard. It is a well documented and pervasive protocol,
9used in all networks worldwide.
10
Ladue, David (dl3158)bb896892018-10-16 16:29:58 -040011As an API offering, the only way to interact with **trapd** is
Rich Bennett98476312018-08-25 10:43:15 -040012to send traps that conform to the industry standard specification
13(RFC1215 - available at https://tools.ietf.org/html/rfc1215 ) to a
14running instance. To accomplish this, you may:
15
161. Configure SNMP agents to send native traps to a SNMPTRAP instance.
17 In SNMP agent configurations, this is usually accomplished by
18 setting the "trap target" or "snmp manager" to the IP address
19 of the running VM/container hosting SNMPTRAP.
20
Ladue, David (dl3158)bb896892018-10-16 16:29:58 -0400212. Simulate a SNMP trap using various freely available utilities. Two
22 examples are provided below, *be sure to change the target
Rich Bennett98476312018-08-25 10:43:15 -040023 ("localhost") and port ("162") to applicable values in your
Ladue, David (dl3158)bb896892018-10-16 16:29:58 -040024 environment.*
Rich Bennett98476312018-08-25 10:43:15 -040025
Ladue, David (dl3158)bb896892018-10-16 16:29:58 -040026NetSNMP snmptrap
27----------------
Rich Bennett98476312018-08-25 10:43:15 -040028
Ladue, David (dl3158)bb896892018-10-16 16:29:58 -040029One way to simulate an arriving SNMP trap is to use the Net-SNMP utility/command snmptrap.
30This command can send V1, V2c or V3 traps to a manager based on the parameters provided.
Rich Bennett98476312018-08-25 10:43:15 -040031
Ladue, David (dl3158)bb896892018-10-16 16:29:58 -040032The example below sends a SNMP V1 trap to the specified host. Prior to running this command, export
33the values of *to_ip_address* (set it to the IP of the VM hosting the ONAP trapd container) and *to_port* (typically
34set to "162"):
35
36 ``export to_ip_address=192.168.1.1``
37
38 ``export to_port=162``
39
40Then run the Net-SNMP command/utility:
41
42 ``snmptrap -d -v 1 -c not_public ${to_ip_address}:${to_portt} .1.3.6.1.4.1.99999 localhost 6 1 '55' .1.11.12.13.14.15 s "test trap"``
Rich Bennett98476312018-08-25 10:43:15 -040043
44.. note::
45
46 This will display some "read_config_store open failure" errors;
47 they can be ignored, the trap has successfully been sent to the
48 specified destination.
49
Ladue, David (dl3158)bb896892018-10-16 16:29:58 -040050python using pysnmp
51-------------------
52
53Another way to simulate an arriving SNMP trap is to send one with the python *pysnmp* module. (Note that this
54is the same module that ONAP trapd is based on).
55
56To do this, create a python script called "send_trap.py" with the following contents. You'll need to change the
57target (from "localhost" to whatever the destination IP/hostname of the trap receiver is) before saving:
Rich Bennett98476312018-08-25 10:43:15 -040058
59.. code-block:: python
60
61 from pysnmp.hlapi import *
62 from pysnmp import debug
63
64 # debug.setLogger(debug.Debug('msgproc'))
65
66 errorIndication, errorStatus, errorIndex, varbinds = next(sendNotification(SnmpEngine(),
67 CommunityData('not_public'),
68 UdpTransportTarget(('localhost', 162)),
69 ContextData(),
70 'trap',
71 [ObjectType(ObjectIdentity('.1.3.6.1.4.1.999.1'), OctetString('test trap - ignore')),
72 ObjectType(ObjectIdentity('.1.3.6.1.4.1.999.2'), OctetString('ONAP pytest trap'))])
73 )
74
75 if errorIndication:
76 print(errorIndication)
77 else:
Ladue, David (dl3158)bb896892018-10-16 16:29:58 -040078 print("successfully sent trap")
79
80To run the pysnmp example:
81
82 ``python ./send_trap.py``