/************************************************************************/ /* */ /* Script to sort WEASEL.LOG */ /* */ /* The original WEASEL.LOG is sorted by time. This script acts as a */ /* filter (from standard input) that produces three output files: */ /* the ONLINE and SORTER and SENDxx entries, the SMTP input entries, */ /* and the POP3 entries. The three output file names must be given */ /* as parameters to this script. */ /* */ /* Programmer: P. Moylan */ /* Last modified: 28 January 2013 */ /* */ /* Installation: */ /* Put this file in the same directory as WEASEL.LOG (normally */ /* the main Weasel directory, but possibly the directory in which */ /* you archive your log files). Alternatively, create a */ /* program object whose working directory is the directory that */ /* contains the transaction log. */ /* */ /* Usage: SortLog 0 current = LINEIN() label = SUBSTR(current, 21, 7) content = SUBSTR(current, 30) /* The correct action now depends on what sort of label it is. */ IF LEFT(label, 5) = 'Setup' THEN DO /* ignore this record */ END ELSE /****************************/ /* SMTP OUTPUT SECTION */ /****************************/ IF LEFT(label, 5) = 'Send_' THEN DO /* Record for an SMTP output session. */ daemon = STRIP(SUBSTR(label, 6)) IF DATATYPE(SMTPOUT.daemon.count, Number) = 0 THEN DO SMTPOUT.daemon.count = 1 END ELSE SMTPOUT.daemon.count = SMTPOUT.daemon.count + 1 vcount = SMTPOUT.daemon.count SMTPOUT.daemon.fullline.vcount = current IF (LEFT(content, 9) = "Delivered") | (LEFT(content, 6) = "Failed") THEN DO /* We have come to the end of an output session, */ /* so write its records to the sendfile file. */ vcount = SMTPOUT.daemon.count CALL LINEOUT sendfile, "" DO j = 1 TO vcount CALL LINEOUT sendfile, SMTPOUT.daemon.fullline.j END DROP SMTPOUT.daemon.count DROP SMTPOUT.daemon END END ELSE /****************************/ /* SMTP INPUT SECTION */ /****************************/ IF LEFT(label, 1) = 'S' THEN DO /* Record for an SMTP input session. */ sessnum = STRIP(SUBSTR(label, 2)) IF DATATYPE(SMTP.sessnum.count, Number) = 0 THEN DO SMTP.sessnum.count = 1 END ELSE SMTP.sessnum.count = SMTP.sessnum.count + 1 vcount = SMTP.sessnum.count SMTP.sessnum.fullline.vcount = current IF content = "End of session" THEN DO /* We have come to the end of a SMTP session, */ /* so write its records to the SMTPfile file. */ vcount = SMTP.sessnum.count CALL LINEOUT smtpfile, "" DO j = 1 TO vcount CALL LINEOUT smtpfile, SMTP.sessnum.fullline.j END DROP SMTP.sessnum.count DROP SMTP.sessnum END END ELSE /****************************/ /* POP3 SECTION */ /****************************/ IF LEFT(label, 1) = 'P' THEN DO /* Record for a POP3 session. */ sessnum = STRIP(SUBSTR(label, 2)) IF DATATYPE(POP.sessnum.count, Number) = 0 THEN DO POP.sessnum.count = 1 END ELSE POP.sessnum.count = POP.sessnum.count + 1 vcount = POP.sessnum.count POP.sessnum.fullline.vcount = current IF content = "End of session" THEN DO /* We have come to the end of a POP3 session, */ /* so write its records to the popfile file. */ vcount = POP.sessnum.count CALL LINEOUT popfile, "" DO j = 1 TO vcount CALL LINEOUT popfile, POP.sessnum.fullline.j END DROP POP.sessnum.count DROP POP.sessnum END END END /* Write out the sessions that we didn't find termination lines for. */ DO daemon = 0 to 63 IF DATATYPE(SMTPOUT.daemon.count, Number) = 1 THEN DO vcount = SMTPOUT.daemon.count IF vcount > 0 THEN DO CALL LINEOUT sendfile, "" DO j = 1 TO vcount CALL LINEOUT sendfile, SMTPOUT.daemon.fullline.j END END DROP SMTPOUT.daemon END END DO sessnum = 0 to 32767 IF DATATYPE(SMTP.sessnum.count, Number) = 1 THEN DO vcount = SMTP.sessnum.count IF vcount > 0 THEN DO CALL LINEOUT smtpfile, "" DO j = 1 TO vcount CALL LINEOUT smtpfile, SMTP.sessnum.fullline.j END END DROP SMTP.sessnum END END DO sessnum = 0 to 32767 IF DATATYPE(POP.sessnum.count, Number) = 1 THEN DO vcount = POP.sessnum.count IF vcount > 0 THEN DO CALL LINEOUT popfile, "" DO j = 1 TO vcount CALL LINEOUT popfile, POP.sessnum.fullline.j END END DROP POP.sessnum END END SAY "Finished. The results are in files "sendfile", "smtpfile", and "popfile EXIT 0 /****************************************************************/