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