Write database records to a log file

This section of the Listener example script sets up an appropriate loop for "listening" to records inserted, deleted, or updated in the MODEL database and then sending the information to a log file. Use this part of the example script as a guide to setting up appropriate loops to capture record activity and then send this activity to some log file in Listener Perl scripts.

The Listener example script sets up an appropriate loop for capturing record activity in the MODEL database as follows:


 open(LOGFILE, ">>model.log)"; 1
 while(1){ 2
 	my ($tag, $data) = $snmp->GetResult(-1);
 	foreach $key (@$data){
 	foreach $rec (keys %$key){
 	  {
 		print LOGFILE "$rec : $key->{$rec}","\n"; 3
 	  }
 	}
 }

The following list explains the specific numbered items in the previously listed section of the Listener Perl script example:

  1. Calls the open operator to open the file handle LOGFILE for output (or appending) to the new (or existing) file model.log.
  2. Sets up a while loop that executes until all inserted, deleted, and updated database records are processed and written to the model.log file.
  3. Writes the desired information to the model.log file. However, if you want to send the information to a third-party database management application, such as Sybase or Oracle, or a trouble-ticketing system, such as ClearQuest®, use the Perl DBI module. To accomplish this, replace this line of code with the DBI connect method and then send the information.