Sending SNMP Traps to mulitiple destinations when one Event triggers
From TDiWiki
Many people have asked for a feature to send traps to multiple destinations when an event occurs. Below is an example on how to do this on an OpenVMS platform. Of course, you'd have to copy this routine into the appropriate action routine directory and associate it with the appropriate consoles and events, but you know all of that. If you need help with this example, or want us to offer it on another platform, drop us a line at support@tditx.com.
$!*****************************************************************************
$!* Copyright © TECSYS Development, Inc., 2004 *
$!* All Rights Reserved. *
$!* *
$!* This software is furnished under a license and may be used and copied *
$!* only in accordance with the terms of such license and with the inclusion *
$!* of the above copyright notice. This software or any other copies thereof *
$!* may not be provided or otherwise made available to any other person. No *
$!* title to and ownership of the software is hereby transferred. *
$!* *
$!* The information in this software is subject to change without notice and *
$!* should not be construed as a commitment by TECSYS Development. *
$!* *
$!* This command file will send the console name, event name, event *
$!* sequence number, and event time as an ASCII string to an snmp sink *
$!* designated by the IP address or DNS name in the Contact field of the *
$!* Event Action Routine configuration. Note that it does not require *
$!* the installation of a MIB but as a result, on receipt, it does not *
$!* identify the trap as coming from a particular MIB. *
$!* *
$!* Usage: *
$!* *
$!* @send_snmp_trap [Console] [Event] [Seq #] [Ctx File] [Contact] [Param] *
$!* *
$!* Parameters: *
$!* *
$!* P1: Console Name *
$!* P2: Event Name *
$!* P3: Sequence Number *
$!* P4: Context File *
$!* P5: Contact == , delimited list of targets (ip addresses) *
$!* P6: Parameter == community name *
$!* *
$!*****************************************************************************
$!* *
$!* Modified: *
$!* *
$!* 2008.02.13 TDI Initial release *
$!* *
$!*****************************************************************************
$!
$ snmp_trapsnd == "$SYS$SYSTEM:TCPIP$SNMP_TRAPSND"
$! Open the context file for reading
$open/read ctx_file 'p4'
$! Loop reading tagged lines until we find the event time line
$read_loop:
$read/end_of_file=the_end ctx_file ctx_line
$ if "f$extract(0,5,ctx_line)'" .eqs. "TIME:"
$ then
$ event_time = f$extract(6,50,ctx_line)
$ goto read_loop
$ endif
$!
$ if "f$extract(0,5,ctx_line)'" .eqs. "CONTE"
$ then
$ ctx_string = ""
$ctx_loop:
$ read/end_of_file=process_sender_list ctx_file ctx_line
$ if "f$extract(0,5,ctx_line)'" .nes. "CONTE"
$ then
$ ctx_string = ctx_string + ctx_line + " "
$ else
$ goto ctx_processing_done
$ endif
$ goto ctx_loop
$ endif
$ goto read_loop
$!
$ctx_processing_done:
$ sender_list = "p5'"
$process_sender_list:
$ if f$locate(",",sender_list) .eq. f$length(sender_list)
$ then
$ current_sender = sender_list
$ sender_list = ""
$ goto last_one
$ endif
$ current_sender = f$extract(0,f$locate(",",sender_list),sender_list)
$ sender_list = f$extract(f$locate(",",sender_list)+1,f$length(sender_list),sender_list)
$!
$last_one:
$ event_trap_info = "Console: " + p1 + " Name: " + p2 + " Sequence: " + p3 + " Time: " + event_time + "CTX: " + ctx_string
$ snmp_trapsnd 1.3.6.1.4.1.12730 localhost 6 17 0 -c 'p6' -h 'current_sender' 0.0.0 "-D" "event_trap_info'"
$ if f$length(sender_list) .eq. 0
$ then
$ goto the_end
$ endif
$ goto process_sender_list
$the_end:
$! Close and delete the context file
$close ctx_file
$delete 'f$parse(p4,";*")'/log
$exit
