SNMP setup examples

Following are the examples showing SNMP configuration for SNMP versions 1, 2 or 3.

In the following examples IPv4 address is used in --snmp_ip_address parameter, but you can also provide a hostname of the host of the trap destination instead.

The IP address used in the examples are for the host which was receiving traps for demonstration. Port 162 is a default port used for SNMP traps, but it can be changed.

Before you start the setup process, list all alert rules in your system to verify that you have a rule set for an alert of your choice to send SNMP traps. If not, set the rule as in the following example, that is, for a hardware test alert 199 the value is set to 4 - Send SNMP trap:
[apuser@node0101 ~]# ap config --list alerts_rules

Action rules
+----------------------+--------------------------+----------+
| Scope                | Value                    | Built-in |
+----------------------+--------------------------+----------+
| default              | 1 (send email)           |      YES |
| ACTION_FAILED        | 0 (do nothing)           |      YES |
| APPLIANCE_EVENT      | 0 (do nothing)           |      YES |
| DB_SERVICE_REQUESTED | 2 (open Service Request) |      YES |
| HW_SERVICE_REQUESTED | 2 (open Service Request) |      YES |
| STARTUP_FAILED       | 0 (do nothing)           |      YES |
| SW_SERVICE_REQUESTED | 2 (open Service Request) |      YES |
| 152                  | 2 (open Service Request) |      YES |
+----------------------+--------------------------+----------+

Email rules
+-------+------+-------+
| Scope | Mode | Value |
+-------+------+-------+
+-------+------+-------+
[apuser@node0101 ~]# ap config --set alerts_rules --type action --scope 199 --value 4
Successfully set rule
[apuser@node0101 ~]$ ap config --list alerts_rules ; 
Action rules
+----------------------+--------------------------+----------+
| Scope                | Value                    | Built-in |
+----------------------+--------------------------+----------+
| default              | 1 (send email)           |      YES |
| ACTION_FAILED        | 0 (do nothing)           |      YES |
| APPLIANCE_EVENT      | 0 (do nothing)           |      YES |
| DB_SERVICE_REQUESTED | 2 (open Service Request) |      YES |
| HW_SERVICE_REQUESTED | 2 (open Service Request) |      YES |
| STARTUP_FAILED       | 0 (do nothing)           |      YES |
| SW_SERVICE_REQUESTED | 2 (open Service Request) |      YES |
| 152                  | 2 (open Service Request) |      YES |
| 199                  | 4 (send SNMP trap)       |       NO |
+----------------------+--------------------------+----------+
Email rules
+-------+------+-------+
| Scope | Mode | Value |
+-------+------+-------+
+-------+------+-------+

In the above example, 199 stands for a reason code for the alert HW Test Alert. With this setting, only the traps with this reason code would be sent. In your environment, you should set the Reason Codes or Issues Types which you are interested in monitoring.

For example, you can also set SNMP trap rule for all alerts with a specific scope:
[apuser@node0101 ~]$ ap config --set alerts_rules --type action --scope HW_SERVICE_REQUESTED --value 4
Successfully set rule
[apuser@node0101 ~]$ ap config --list alerts_rules ; 
Action rules
+----------------------+--------------------------+----------+
| Scope                | Value                    | Built-in |
+----------------------+--------------------------+----------+
| default              | 1 (send email)           |      YES |
| ACTION_FAILED        | 0 (do nothing)           |      YES |
| APPLIANCE_EVENT      | 0 (do nothing)           |      YES |
| DB_SERVICE_REQUESTED | 2 (open Service Request) |      YES |
| HW_SERVICE_REQUESTED | 4 (send SNMP trap)       |       NO |
| STARTUP_FAILED       | 0 (do nothing)           |      YES |
| SW_SERVICE_REQUESTED | 2 (open Service Request) |      YES |
| 152                  | 2 (open Service Request) |      YES |
| 199                  | 4 (send SNMP trap)       |       NO |
+----------------------+--------------------------+----------+
Email rules
+-------+------+-------+
| Scope | Mode | Value |
+-------+------+-------+
+-------+------+-------+
To view all available alerts in your system, run the following command:
ap issues --show_registry

Alerts Registry
+-------------+----------------------------+-------+---------------------------------------------------------------+----------+
| Reason Code | Type                       | Group | Title                                                         | Stateful |
+-------------+----------------------------+-------+---------------------------------------------------------------+----------+
| 101         | HW_SERVICE_REQUESTED       | HW    | Server is unreachable and cannot be recovered                 | YES      |
| 102         | HW_SERVICE_REQUESTED       | HW    | Server failed and was disabled                                | YES      |
| 103         | HW_SERVICE_REQUESTED       | HW    | Major component is unreachable                                | YES      |
| 104         | HW_SERVICE_REQUESTED       | HW    | Major component failed                                        | YES      |
(...)

SNMP v1

Appliance:
[root@node0101 ~]# echo "Setting up parameters. Version of SNMP is: SNMPv1" > /dev/null; \
> ap config --del snmp; \
> ap config --list snmp; \
> ap config --set snmp \
>           --snmp_version 1 \
>           --snmp_community snmpv1public \
>           --snmp_ip_address 9.158.134.215 \
>           --snmp_port 162 \
> ;\
> ap config --list snmp;
Deleted successfully
Ip Address/Hostname      : 
Port                     : 
Version                  : 
Community                : 
Engine Id                : 
Security Level           : 
Security Name            : 
Authentication Key       : 
Authentication Protocol  : 
Encryption Key           : 
Encryption Protocol      : 
Updated successfully
Ip Address/Hostname      : 9.158.134.215
Port                     : 162
Version                  : 1
Community                : ***
Engine Id                : 
Security Level           : 
Security Name            : 
Authentication Key       : 
Authentication Protocol  : 
Encryption Key           : 
Encryption Protocol      : 
[root@node0101 ~]# echo -e TIMESTAMP: $(date +%F\ %T) \\n ; ap issues --generate_test_alert ; sleep 15 ; ap issues --close_test_alert ;
TIMESTAMP: 2020-03-03 10:53:44 

Test issue generated

Test issue closed

[root@node0101 ~]# 
Workstation:
snmptrapd    | 
snmptrapd    | 09:53:57 2020/03/03 TRAP 9.0.226.16
snmptrapd    | PDU INFO:
snmptrapd    |   receivedfrom:      9.0.226.16
snmptrapd    |   agent hostname:    9.0.226.16
snmptrapd    |   community:         TRAP, SNMP v1, community snmpv1public
snmptrapd    |   enterprise OID:    IIAS-MIB::applianceNotifications
snmptrapd    |   trap type:         Enterprise Specific
snmptrapd    |   trap sub-type:     IIAS-MIB::testHWAlert199
snmptrapd    | VARBINDS:
snmptrapd    |   IIAS-MIB::applianceSN.0 = NZTULET
snmptrapd    |   IIAS-MIB::alertId.0 = 9748
snmptrapd    |   IIAS-MIB::alertTimestamp.0 = 2020-03-03 10:53:45.014211
snmptrapd    |   IIAS-MIB::alertType.0 = HW_SERVICE_REQUESTED
snmptrapd    |   IIAS-MIB::alertTarget.0 = hw://hadomain1.node1
snmptrapd    |   IIAS-MIB::alertTargetType.0 = node
snmptrapd    |   IIAS-MIB::alertSeverity.0 = INFORMATION
snmptrapd    |   IIAS-MIB::alertDescription.0 = Test HW alert

SNMP v2c

Appliance:
[root@node0101 ~]# echo "Setting up parameters. Version of SNMP is: SNMPv2c" > /dev/null; \
> ap config --del snmp; \
> ap config --list snmp; \
> ap config --set snmp \
>           --snmp_version 2 \
>           --snmp_community snmpv2public \
>           --snmp_ip_address 9.158.134.215 \
>           --snmp_port 162 \
> ;\
> ap config --list snmp;
Deleted successfully
Ip Address/Hostname      : 
Port                     : 
Version                  : 
Community                : 
Engine Id                : 
Security Level           : 
Security Name            : 
Authentication Key       : 
Authentication Protocol  : 
Encryption Key           : 
Encryption Protocol      : 
Updated successfully
Ip Address/Hostname      : 9.158.134.215
Port                     : 162
Version                  : 2
Community                : ***
Engine Id                : 
Security Level           : 
Security Name            : 
Authentication Key       : 
Authentication Protocol  : 
Encryption Key           : 
Encryption Protocol      : 
[root@node0101 ~]# echo -e TIMESTAMP: $(date +%F\ %T) \\n ; ap issues --generate_test_alert ; sleep 15 ; ap issues --close_test_alert ;
TIMESTAMP: 2020-03-03 10:59:03 

Test issue generated

Test issue closed

[root@node0101 ~]#
Workstation:
snmptrapd    | 
snmptrapd    | 09:59:16 2020/03/03 TRAP 172.18.0.1
snmptrapd    | PDU INFO:
snmptrapd    |   receivedfrom:      UDP: [172.18.0.1]:41762->[172.18.0.2]:162
snmptrapd    |   community:         TRAP2, SNMP v2c, community snmpv2public
snmptrapd    | VARBINDS:
snmptrapd    |   DISMAN-EVENT-MIB::sysUpTimeInstance = 6:0:58:44.14
snmptrapd    |   SNMPv2-MIB::snmpTrapOID.0 = IIAS-MIB::testHWAlert199
snmptrapd    |   IIAS-MIB::applianceSN.0 = NZTULET
snmptrapd    |   IIAS-MIB::alertId.0 = 9749
snmptrapd    |   IIAS-MIB::alertTimestamp.0 = 2020-03-03 10:59:03.880438
snmptrapd    |   IIAS-MIB::alertType.0 = HW_SERVICE_REQUESTED
snmptrapd    |   IIAS-MIB::alertTarget.0 = hw://hadomain1.node1
snmptrapd    |   IIAS-MIB::alertTargetType.0 = node
snmptrapd    |   IIAS-MIB::alertSeverity.0 = INFORMATION
snmptrapd    |   IIAS-MIB::alertDescription.0 = Test HW alert

SNMP v3, version set up implicitly

When parameter --snmp_version is not set, SNMPv3 is used implicitly. The rest of parameters used in the command ap config --set snmp are required in order to send the trap using SNMPv3, otherwise the log contains the following record: Incomplete SNMP configuration. Set following parameters in order to make SNMP traps sending possible: <list of missing parameters>

The order in which the parameters are set via ap config --set snmp does not matter. They can be set all at once, or separately.

Appliance:
[root@node0101 ~]# echo "Setting up parameters. Version of SNMP is implicit: SNMPv3" > /dev/null; \
> ap config --del snmp; \
> ap config --list snmp; \
> ap config --set snmp \
>           --snmp_ip_address 9.158.134.215 \
>           --snmp_port 162 \
>           --snmp_engine_id 80000002044536 \
>           --snmp_security_name usm-sha-aes \
>           --snmp_security_level 2 \
>           --snmp_auth_protocol 2 \
>           --snmp_enc_protocol 2 \
>           --snmp_auth_key sha.auth \
>           --snmp_enc_key aes.priv \
> ;\
> ap config --list snmp;
Deleted successfully
Ip Address/Hostname      : 
Port                     : 
Version                  : 
Community                : 
Engine Id                : 
Security Level           : 
Security Name            : 
Authentication Key       : 
Authentication Protocol  : 
Encryption Key           : 
Encryption Protocol      : 
Updated successfully
Ip Address/Hostname      : 9.158.134.215
Port                     : 162
Version                  : 
Community                : 
Engine Id                : 80000002044536
Security Level           : 2
Security Name            : usm-sha-aes
Authentication Key       : ***
Authentication Protocol  : 2
Encryption Key           : ***
Encryption Protocol      : 2

[root@node0101 ~]# echo -e TIMESTAMP: $(date +%F\ %T) \\n ; ap issues --generate_test_alert ; sleep 15 ; ap issues --close_test_alert ;
TIMESTAMP: 2020-03-03 10:33:56 

Test issue generated

Test issue closed

[root@node0101 ~]# 
Workstation:

Creating network "snmptools_default" with the default driver
Creating snmptrapd ... done
Attaching to snmptrapd
snmptrapd    | Created directory: /var/lib/net-snmp/mib_indexes
snmptrapd    | NET-SNMP version 5.8
snmptrapd    | 
snmptrapd    | 09:34:09 2020/03/03 TRAP 172.18.0.1
snmptrapd    | PDU INFO:
snmptrapd    |   receivedfrom:      UDP: [172.18.0.1]:36382->[172.18.0.2]:162
snmptrapd    |   community:         TRAP2, SNMP v3, user usm-sha-aes, context 
snmptrapd    | VARBINDS:
snmptrapd    |   DISMAN-EVENT-MIB::sysUpTimeInstance = 6:0:33:37.48
snmptrapd    |   SNMPv2-MIB::snmpTrapOID.0 = IIAS-MIB::testHWAlert199
snmptrapd    |   IIAS-MIB::applianceSN.0 = NZTULET
snmptrapd    |   IIAS-MIB::alertId.0 = 9746
snmptrapd    |   IIAS-MIB::alertTimestamp.0 = 2020-03-03 10:33:57.098711
snmptrapd    |   IIAS-MIB::alertType.0 = HW_SERVICE_REQUESTED
snmptrapd    |   IIAS-MIB::alertTarget.0 = hw://hadomain1.node1
snmptrapd    |   IIAS-MIB::alertTargetType.0 = node
snmptrapd    |   IIAS-MIB::alertSeverity.0 = INFORMATION
snmptrapd    |   IIAS-MIB::alertDescription.0 = Test HW alert

SNMP v3, version set up explicitly

Appliance
[root@node0101 ~]# echo "Setting up parameters. Version of SNMP is explicit: SNMPv3" > /dev/null; \
> ap config --del snmp; \
> ap config --list snmp; \
> ap config --set snmp \
>           --snmp_version 3 \
>           --snmp_ip_address 9.158.134.215 \
>           --snmp_port 162 \
>           --snmp_engine_id 80000002044536 \
>           --snmp_security_name usm-sha-aes \
>           --snmp_security_level 2 \
>           --snmp_auth_protocol 2 \
>           --snmp_enc_protocol 2 \
>           --snmp_auth_key sha.auth \
>           --snmp_enc_key aes.priv \
> ;\
> ap config --list snmp;
Deleted successfully
Ip Address/Hostname      : 
Port                     : 
Version                  : 
Community                : 
Engine Id                : 
Security Level           : 
Security Name            : 
Authentication Key       : 
Authentication Protocol  : 
Encryption Key           : 
Encryption Protocol      : 
Updated successfully
Ip Address/Hostname      : 9.158.134.215
Port                     : 162
Version                  : 3
Community                : 
Engine Id                : 80000002044536
Security Level           : 2
Security Name            : usm-sha-aes
Authentication Key       : ***
Authentication Protocol  : 2
Encryption Key           : ***
Encryption Protocol      : 2
[root@node0101 ~]# echo -e TIMESTAMP: $(date +%F\ %T) \\n ; ap issues --generate_test_alert ; sleep 15 ; ap issues --close_test_alert ;
TIMESTAMP: 2020-03-03 10:42:59 

Test issue generated

Test issue closed

[root@node0101 ~]#
Workstation
snmptrapd    | 
snmptrapd    | 09:43:11 2020/03/03 TRAP 172.18.0.1
snmptrapd    | PDU INFO:
snmptrapd    |   receivedfrom:      UDP: [172.18.0.1]:53745->[172.18.0.2]:162
snmptrapd    |   community:         TRAP2, SNMP v3, user usm-sha-aes, context 
snmptrapd    | VARBINDS:
snmptrapd    |   DISMAN-EVENT-MIB::sysUpTimeInstance = 6:0:42:39.30
snmptrapd    |   SNMPv2-MIB::snmpTrapOID.0 = IIAS-MIB::testHWAlert199
snmptrapd    |   IIAS-MIB::applianceSN.0 = NZTULET
snmptrapd    |   IIAS-MIB::alertId.0 = 9747
snmptrapd    |   IIAS-MIB::alertTimestamp.0 = 2020-03-03 10:42:59.855632
snmptrapd    |   IIAS-MIB::alertType.0 = HW_SERVICE_REQUESTED
snmptrapd    |   IIAS-MIB::alertTarget.0 = hw://hadomain1.node1
snmptrapd    |   IIAS-MIB::alertTargetType.0 = node
snmptrapd    |   IIAS-MIB::alertSeverity.0 = INFORMATION
snmptrapd    |   IIAS-MIB::alertDescription.0 = Test HW alert