Rich Bennett | 9847631 | 2018-08-25 10:43:15 -0400 | [diff] [blame] | 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 | |
Ladue, David (dl3158) | bb89689 | 2018-10-16 16:29:58 -0400 | [diff] [blame] | 7 | **trapd** supports the Simple Network Management Protocol (SNMP) |
Rich Bennett | 9847631 | 2018-08-25 10:43:15 -0400 | [diff] [blame] | 8 | standard. It is a well documented and pervasive protocol, |
| 9 | used in all networks worldwide. |
| 10 | |
Ladue, David (dl3158) | bb89689 | 2018-10-16 16:29:58 -0400 | [diff] [blame] | 11 | As an API offering, the only way to interact with **trapd** is |
Rich Bennett | 9847631 | 2018-08-25 10:43:15 -0400 | [diff] [blame] | 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 | |
Ladue, David (dl3158) | bb89689 | 2018-10-16 16:29:58 -0400 | [diff] [blame] | 21 | 2. Simulate a SNMP trap using various freely available utilities. Two |
| 22 | examples are provided below, *be sure to change the target |
Rich Bennett | 9847631 | 2018-08-25 10:43:15 -0400 | [diff] [blame] | 23 | ("localhost") and port ("162") to applicable values in your |
Ladue, David (dl3158) | bb89689 | 2018-10-16 16:29:58 -0400 | [diff] [blame] | 24 | environment.* |
Rich Bennett | 9847631 | 2018-08-25 10:43:15 -0400 | [diff] [blame] | 25 | |
Ladue, David (dl3158) | bb89689 | 2018-10-16 16:29:58 -0400 | [diff] [blame] | 26 | NetSNMP snmptrap |
| 27 | ---------------- |
Rich Bennett | 9847631 | 2018-08-25 10:43:15 -0400 | [diff] [blame] | 28 | |
Ladue, David (dl3158) | bb89689 | 2018-10-16 16:29:58 -0400 | [diff] [blame] | 29 | One way to simulate an arriving SNMP trap is to use the Net-SNMP utility/command snmptrap. |
| 30 | This command can send V1, V2c or V3 traps to a manager based on the parameters provided. |
Rich Bennett | 9847631 | 2018-08-25 10:43:15 -0400 | [diff] [blame] | 31 | |
Ladue, David (dl3158) | bb89689 | 2018-10-16 16:29:58 -0400 | [diff] [blame] | 32 | The example below sends a SNMP V1 trap to the specified host. Prior to running this command, export |
| 33 | the values of *to_ip_address* (set it to the IP of the VM hosting the ONAP trapd container) and *to_port* (typically |
| 34 | set to "162"): |
| 35 | |
| 36 | ``export to_ip_address=192.168.1.1`` |
| 37 | |
| 38 | ``export to_port=162`` |
| 39 | |
| 40 | Then 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 Bennett | 9847631 | 2018-08-25 10:43:15 -0400 | [diff] [blame] | 43 | |
| 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) | bb89689 | 2018-10-16 16:29:58 -0400 | [diff] [blame] | 50 | python using pysnmp |
| 51 | ------------------- |
| 52 | |
| 53 | Another way to simulate an arriving SNMP trap is to send one with the python *pysnmp* module. (Note that this |
| 54 | is the same module that ONAP trapd is based on). |
| 55 | |
| 56 | To do this, create a python script called "send_trap.py" with the following contents. You'll need to change the |
| 57 | target (from "localhost" to whatever the destination IP/hostname of the trap receiver is) before saving: |
Rich Bennett | 9847631 | 2018-08-25 10:43:15 -0400 | [diff] [blame] | 58 | |
| 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) | bb89689 | 2018-10-16 16:29:58 -0400 | [diff] [blame] | 78 | print("successfully sent trap") |
| 79 | |
| 80 | To run the pysnmp example: |
| 81 | |
| 82 | ``python ./send_trap.py`` |