snmp_trap_listen()

Start accumulating incoming PATROL SNMP event traps.

Syntax

snmp_trap_listen()

Parameter

This function does not accept any parameters.

Description

The snmp_trap_listen() opens a socket to accumulate incoming event traps to the SNMP agent. The socket number is chosen in the following order:

  1. value of the /snmp/trap_port variable
  2. the snmp-trap/udp service
  3. 162

The snmp_trap_listen() function does not block the process from which it is called. The snmp_trap_listen() function returns the characters OK if it is successful and the NULL string if it is not. The snmp_trap_listen() function can also set the PSL errno variable as follows:

errno Value

Description

98

E_PSL_SNMP_ALREADY_LISTENING 
socket is already active to accumulate SNMP traps

94

E_PSL_SOCKET_BUSY 
socket that the snmp_trap_listen() function is attempting to use a socket that is already in use

Example

The following PSL script is uses the snmp_trap_ignore(), snmp_trap_listen(), and snmp_trap_receive() functions:

# Stop accumulating traps. Clears any snmp_trap_listen().
snmp_trap_ignore();
# Start listening for (accumulating) traps
ret = snmp_trap_listen();
if ( ret == "") {
ret = "NULL";
}
printf("Listen status = %s Errno = %s\n", ret, errno);
print("Running...\n");
print("\n");
# Return the first accumulated trap in blocking mode. Wait until a trap
# has been received.
res = snmp_trap_receive();
if(res == "")
{
print("No SNMP trap available...errno =".errno."\n");
}
else
{
printf(res);
}
print("\n");
sleep(10);
# snmp_trap_receive() in blocking mode. Return the next snmp trap if one exists.
# Don't wait.
res = snmp_trap_receive(2);
if(res == "")
{
print("No SNMP trap available...errno=".errno."\n");
}
else
{
print("SNMP Trap received:\n");
printf(res);
}
# Stop accumulating SNMP traps.
snmp_trap_ignore();

Sample output when two SNMP traps are received. The first SNMP trap is the result of a manual SNMP trap sent using snmp_trap_send. The second SNMP trap is the result a parameter alarm:

Listen status = OK Errno = 0
Running...
SNMP Trap received:
172.19.201.36 1.3.6.1.4.1.1031 1 3743142
1.3.6.1.4.1.1031.1 6 string test 1
1.3.6.1.4.1.1031.2 6 string test 2
1.3.6.1.4.1.1031.2 6 string test 2
1.3.6.1.4.1.1031.2 6 string test 2
SNMP Trap received:
172.19.201.36 1.3.6.1.4.1.1031.1.1.2 5 3743929
1.3.6.1.4.1.1031.1.1.2.1.0 84 string Alarm #2 of global parameter 'mystate'
1.3.6.1.4.1.1031.1.1.2.2.0 22 string /PSLCOM/PSLCOM/mystate
1.3.6.1.4.1.1031.1.1.2.3.0 0 string

Sample output when only one SNMP trap is received. The SNMP trap is the result of a parameter alarm.

Listen status = OK Errno = 0
Running...
172.19.201.36 1.3.6.1.4.1.1031.1.1.2 5 3782736
1.3.6.1.4.1.1031.1.1.2.1.0 87 string Alarm #2 of global parameter 'MEMWCache'
1.3.6.1.4.1.1031.1.1.2.2.0 24 string /MEMORY/MEMORY/MEMWCache
1.3.6.1.4.1.1031.1.1.2.3.0 0 string
No SNMP trap available...errno=0
Was this page helpful? Yes No Submitting... Thank you

Comments