Add RST Files for SNMPTRAP
[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
4 Offered APIs
5 ============
6
7 **SNMPTRAP** supports the Simple Network Management Protocol (SNMP)
8 standard.  It is a well documented and pervasive protocol,
9 used in all networks worldwide.
10
11 As an API offering, the only way to interact with **SNMPTRAP** is
12 to send traps that conform to the industry standard specification
13 (RFC1215 - available at https://tools.ietf.org/html/rfc1215 ) to a
14 running instance.  To accomplish this, you may:
15
16 1. 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
21 2. Mimic a SNMP trap using various freely available utilities.  Two
22    examples are provided below, be sure to change the target
23    ("localhost") and port ("162") to applicable values in your
24    environment.
25
26 Net-SNMP
27 --------
28
29 .. code-block:: bash
30
31    snmptrap -d -v 1 -c 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"
32
33 .. note::
34
35    This will display some "read_config_store open failure" errors;
36    they can be ignored, the trap has successfully been sent to the
37    specified destination.
38
39 pysnmp
40 ------
41
42 .. code-block:: python
43
44         from pysnmp.hlapi import *
45         from pysnmp import debug
46         
47         # debug.setLogger(debug.Debug('msgproc'))
48         
49         errorIndication, errorStatus, errorIndex, varbinds = next(sendNotification(SnmpEngine(),
50              CommunityData('not_public'),
51              UdpTransportTarget(('localhost', 162)),
52              ContextData(),
53              'trap',
54              [ObjectType(ObjectIdentity('.1.3.6.1.4.1.999.1'), OctetString('test trap - ignore')),
55               ObjectType(ObjectIdentity('.1.3.6.1.4.1.999.2'), OctetString('ONAP pytest trap'))])
56         )
57         
58         if errorIndication:
59             print(errorIndication)
60         else:
61             print("successfully sent first trap example, number %d" % i)