// GWIASTAT.TSK // Author: Gregory M. Palumbo, CNE // Begun: 08-09-01 // // Purpose: Accumulate Outbound and Inbound GWIA totals into a CSV file // which can be read into Excel and a monthly statistical // graph can be produced. // // Overview: The GWIA gateway NLM keeps a running total on it's screen, but // unless you use the accounting feature and a third party app // to parse the accounting log files, you can't get a simple // chart showing the daily totals. Also, the counter never // resets so you have to remember to grab the totals every day. // What this script does is save the screen to a temp file every // day at the same time. Then it parses the file for the OUTBOUND // and INBOUND numbers and appends them to a monthly log in CSV // format. Then on the 1st of the month at 12:01AM, it activates // the GWIA screen and resets the counters by KEYIN statements. ////////////// Variables used /////////////////////// // %9 - Used to hold current line in the file. // %8 - OUTBOUND counter // %7 - INBOUND counter // %6 - OUTBOUND Bytes // %5 - INBOUND Bytes // %4 - Comment string - This is basically used to // tell us why we don't have a // log entry for a given day. ////////////// Variables used /////////////////////// // Before we proceed much further, we want to make sure that any snapshots // we take are written to a specific directory. Therefore, we should set // the Current Working Directory (CWD) using the CD batch command. CD // can be used with a specific destination directory (e.g., SYS:\SYSTEM) // or a relative directory (e.g., ..\NEW_DIR). It is best to set the // initial CWD to a specific destination directory in order to assure the // validity of subsequent relative directory changes. // First save the Current Working Directory (CWD) DEFINE %0 %CWD% // Now define a new CWD (or default directory) where the // captured screen images and logs should be saved CD SYS:\SYSTEM\TASKMSTR\LOGS // Each entry will have a comment of "Normal Entry" unless GWIA isn't running. Define %4 "Normal entry" // Check if GWIA loaded. We will note this in the log if it isn't. IF NOT LOADED GWIA.NLM THEN BEGIN Define %4 "GWIA not running during stat_check." OPEN_WRITE %CWD%\GWIA-%MONTH%.LOG WRITE "%MONTH%/%DAY%/%YEAR%",%8,%7,,,%6,%5,,,%4 CLOSE ABORT ENDIF // Change to GWIA screen CHANGE_SCREEN "GroupWise Internet Agent" // SLEEP for 1 second (to allow a busy system to activate the screen) SLEEP 1 IF NOT CURRENT_SCREEN "GroupWise Internet Agent" //DEBUG: Extra logic for CURRENT_SCREEN / CHANGE_SCREEN debugging DEFINE %0 %SCREEN_NAME% IF SCREEN_LOCKED DEFINE %0 %0 [Locked] ELSE DEFINE %0 %0 [Unlocked] ENDIF //DEBUG: Extra logic for CURRENT_SCREEN / CHANGE_SCREEN debugging CHANGE_SCREEN "GroupWise Internet Agent" // SLEEP for 1 second (to allow a busy system to activate the screen) SLEEP 1 IF NOT CURRENT_SCREEN "GroupWise Internet Agent" THEN begin OPEN_WRITE %CWD%\GWIA-%MONTH%.LOG WRITE "%MONTH%/%DAY%/%YEAR%",%8,%7,,,,,,,"Screen change failed (Before: %0 / After: %SCREEN_NAME%)" CLOSE ABORT ENDIF ENDIF // Save the current screen image to a temp text file SAVE_SCREEN %CWD%\GWIA-TMP.LOG // Open the file to read and search for the in/out stats... OPEN_READ %CWD%\GWIA-TMP.LOG IF ERRORLEVEL // ECHO the error to the screen ECHO ERROR: Unable to open the %CWD%\GWIA-TMP.LOG file ECHO ABORT: Task aborted before processing could begin... // Abort further processing of the task ABORT ENDIF // Use a WHILE/LOOP to read and scan the file contents // NOTE: The Outbound and Inbound stats follow the word "Normal" // in the GWIA screen. Outbound ends on position 44 and // Inbound ends on position 66. If we allow for 7 chars, we // can track up to a billion messages a month. That should // be enough! The leading chars will be spaces, but when pulled // into Excel, they become numbers, so they'll be thrown out. WHILE // Read the next text line in the file into variable %9 READ %9 // The ERRORLEVEL flag is set on End Of File (EOF) and errors IF ERRORLEVEL THEN BEGIN //Sam: This is where I'm having intermittant problems. echo broke out of loop because of errorlevel BREAK endif // No need to check a null string so CONTINUE (i.e., resume at WHILE) IF "%9"=="" THEN CONTINUE // Check if the line just READ into %9 contains the keyword "Normal" IF SCAN_STRING "Normal" "%9" // There are two lines that contain "Normal", if log level is // set to "Normal" so we have to filter out the undesired line. // If we don't, then %8 and %7 will get reset to 0 before the loop ends. IF NOT SCAN_STRING "Log Level" "%9" // If TRUE then we have the right "Normal" line. Now we // need to grab the line and parse it to pick out the // two numbers we want. // %9 contains the whole line containing the word "Normal" // AFTER the PARSE commands execute: // %8 will contain the OUTBOUND GWIA counter // %7 will contain the INBOUND GWIA counter PARSE %8 %9 38-44 PACK PARSE %7 %9 60-66 PACK ECHO Current GWIA Statistics are: ECHO MESSAGES OUT: %8 ECHO MESSAGES IN: %7 ENDIF ENDIF // Check if the line just READ into %9 contains the keyword "Total Bytes" // This gets our Byte counts, and works the same way as the Message counts // in the above IF/ENDIF loop. IF SCAN_STRING "Total Bytes" "%9" // If TRUE then we need to grab the line and parse it to pick out the // two numbers. // %9 contains the whole line containing the word "Normal" // AFTER the PARSE commands execute: // %6 will contain the OUTBOUND GWIA Byte Count // %5 will contain the INBOUND GWIA Byte Count PARSE %6 %9 38-44 PACK PARSE %5 %9 60-66 PACK ECHO BYTES OUT : %6 ECHO BYTES IN : %5 CLOSE // GWIA_TMP.LOG // Now we create or open the file for this month. // If the file doesn't exist, we create the first line // with header information so we know what the numbers mean. IF NOT EXIST %CWD%\GWIA-%MONTH%.LOG THEN BEGIN OPEN_WRITE %CWD%\GWIA-%MONTH%.LOG WRITE "DATE","OUTBOUND","INBOUND","OUT/DAY","IN/DAY","BYTES OUT","BYTES IN","BYTES OUT/DAY","BYTES IN/DAY","COMMENT" CLOSE ENDIF OPEN_WRITE %CWD%\GWIA-%MONTH%.LOG WRITE "%MONTH%/%DAY%/%YEAR%",%8,%7,,,%6,%5,,,%4 CLOSE // BREAK out of the WHILE/LOOP since we got what we came for... BREAK ENDIF // Process the next READ if a match did not BREAK out LOOP // Return to intial working dir CD %0