Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending an email on keyword in capture file

Status
Not open for further replies.

kgornek

Technical User
Mar 11, 2004
50
0
0
US
I've played with this a little but I'm just not familiar enough with ASPECT to make it work. I have a constant capture file running from an output from a 5ESS switch. Is there a way that I can have an email sent whenever a specific keyword scrolls across the screen? This is a XP OS computer which is on a LAN with Outlook 2003 installed. Outlook can be made to be running in the background full time if need be.

I read the previous post on this, but it wasn't very specific and I don't think it applied to my situation.
 
This script runs on a output only file and I'm looking for the script to notify me anytime I have a *C alarm. Disregard the "waitfor op:clk" in the script above, that was just for testing purposes. The real script will read waitfor "*C" meaning a critical alarm which could be a various amount of alarms.

Most alarms can be 3-4+ lines long but if I could just get at least the first two lines I would be happy. That way I would know if I needed to react or not to that specific alarm.

Here is one example of a message that might come out:
*C RMV TRK TKGMN=1024-0 NEN=1-0-1-1-1-7-3-24 PRIGRP=1025 COMPLETED
OOS MTCE FAF AUTO OOS MTCE FAF AUTO

If you can take the above script and manipulate it or give some detailed examples to show me what you mean by global string variables and how they would apply to my script, I would really appreciate it. I am at a loss and have been working several days to try and figure this all out. The rget help in ProComm isn't much help at all.
 
Is there a line/prompt/string that would indicate the alarm text has all been received?

To define a global variable, say sLine, you declare it before proc main as such:

string sLine

proc main
...

To use the rget command, you would use:

rget sLine

to read the remainder of the line coming from the remote system. You may need to use multiple rget commands to get the line, and don't forget you will need a separate string variable for each possible alarm line. While debugging just how many rget commands you need, you can use the usermsg command to spit the grabbed line to a messagebox and tinker as necessary.

 
No, there really is no line, prompt or string to indicate the end of the message. But I'm thinking if I just had the first 2-3 lines after the "*C" it would be sufficient. Is there a way to do accomplish that?

I'm not sure how do to the following:
"spit the grabbed line to a messagebox and tinker as necessary" --rget gets the info but what command puts it where I want it in the email? This is what I am completely lost on.

"separate string variables" -- You mean rget sLine //rget tLine //rget uLine and so on and forth? Different letters for the “x”Line?

I built it how you informed me and it compiled ok and I did get the usermsg of "Stop" and then the script continued, but it didn't place anything in the email from the rget command at all. I understanding more on how the command works but would really appreciate it if you could give me some examples in my actual script as I am really new to ASPECT.


string sLine

proc main
while 1
waitfor "*C" forever matchcase
rget sLine
rget sLine
usermsg "stop"
call Outlook
endwhile
endproc

proc Outlook
integer iTask, iWindow, iStatus = 0
string sTaskName

if firsttask iTask ;Search list of tasks for outlook.exe
taskname iTask sTaskName
if strnicmp sTaskName "outlook.exe" 11 ;Search for Outlook process
taskwin iTask iWindow
winactivate iWindow ;Bring Outlook to foreground
pause 2
launch_message() ;Run procedure to open new message
iStatus = 1 ;Set flag indicating Outlook was found
endif
while nexttask iTask
taskname iTask sTaskName
if strnicmp sTaskName "outlook.exe" 11
taskwin iTask iWindow
winactivate iWindow
pause 2
launch_message()
iStatus = 1
endif
endwhile
endif
if iStatus == 0 ;Outlook not active
run "c:\program files\microsoft office\office11\outlook.exe" maximized
pause 5
launch_message()
endif
endproc

proc launch_message
pause 3
sendkey CTRL 'N' ;Open new message
pause 1
sendkeystr "Gornek, Kenneth;W, William E"
pause 1
sendkey ALT 'J' ;Move to subject line
pause 1
sendkeystr "Critical PITB 5ESS Alarm - Automated"
sendkey 0x09
sendkeystr "A Critical alarm has been detected. This is an automated email for the Pittsburgh 5ESS."
sendkey ALT 'S'
endproc
 
Right, if you want to capture multiple lines, you would need multiple rget commands and you would need a separate variable for each successful rget command. Otherwise, you run the risk of reading a blank line with your last rget command and your string variable would no longer have the information from the previous rget.

What I would do is write a short script that issues a few rget commands and displays them to the screen using usermsg so you figure out just how tricky it is to get the particular data you need. Once you have that, you can modify your main script:

string sLine1, sLine2, sLine3

proc main
while 1
waitfor "*C" forever matchcase
rget sLine1
rget sLine2
rget sLine3
usermsg "%s" sLine1
usermsg "%s" sLine2
usermsg "%s" sLine3
endwhile
endproc

You would use the sendkeystr command to put the value from the string variables (sLine1 etc.) into the email message.

 
Ok, I'm getting close but only seem to be getting the first line after the "*C". Here is what everything reads like:

Alarm message that the script fires on:

*C TST ALM - CRITICAL ALARM TEST IN PROGRESS
FOR AUDIBLE AND VISUAL ALARM REPORTING

What is placed in the email sent by the script:

"A Critical alarm has been detected. This is an automated email for the Pittsburgh 5ESS. TST ALM – CRITICAL ALARM TEST IN PROGRESS"

On my usermsgs, I see the following boxes in this order:
"TST ALM - CRITICAL ALARM TEST IN PROGRESS"
"FOR AUDIBLE AND VISUAL ALARM REPORTING"
"Here I get a small box in the message - I think it may be a carriage return"
"Here I get the beginning of a new message" (Which I don't need)


The script:

string sLine1, sLine2, sLine3, sLine4

proc Main
while 1
waitfor "*C" forever matchcase
rget sLine1
rget sLine2
rget sLine3
rget sLine4
call Outlook
endwhile
endproc

proc Outlook
integer iTask, iWindow, iStatus = 0
string sTaskName

if firsttask iTask ;Search list of tasks for outlook.exe
taskname iTask sTaskName
if strnicmp sTaskName "outlook.exe" 11 ;Search for Outlook process
taskwin iTask iWindow
winactivate iWindow ;Bring Outlook to foreground
pause 2
launch_message() ;Run procedure to open new message
iStatus = 1 ;Set flag indicating Outlook was found
endif
while nexttask iTask
taskname iTask sTaskName
if strnicmp sTaskName "outlook.exe" 11
taskwin iTask iWindow
winactivate iWindow
pause 2
launch_message()
iStatus = 1
endif
endwhile
endif
if iStatus == 0 ;Outlook not active
run "c:\program files\microsoft office\office11\outlook.exe" maximized
pause 5
launch_message()
endif
endproc

proc launch_message
pause 3
sendkey CTRL 'N' ;Open new message
pause 1
sendkeystr "Gornek, Kenneth;W, William E."
pause 1
sendkey ALT 'J' ;Move to subject line
pause 1
sendkeystr "Critical PITB 5ESS Alarm - Automated"
sendkey 0x09
sendkeystr "A Critical alarm has been detected. This is an automated email for the Pittsburgh 5ESS."
sendkeystr sLine1
pause 1
sendkeystr sLine2
pause 1
sendkeystr sLine3
pause 1
sendkeystr sLine4
sendkey ALT 'S'
endproc


 
Hmm, that's a bit odd. One thing you might try doing is using the strreplace command to strip out any carriage returns and linefeeds in case those are causing issues. You can do that like this:

strreplace sLine1 "`n" ""
strreplace sLine2 "`r" ""

You might also try flipping the order of sLine1 and sLine2 in the launch_message procedure for a quick sanity test.

What version of Outlook or Outlook Express are you using?

 
I am using Microsoft Outlook 2003 SP2.

So with your changes the Script should like so?

(I changed the very first line and the Main Proc section)

string sLine2, sLine1, sLine3, sLine4

proc Main
while 1
waitfor "*C" forever matchcase
rget sLine1
rget sLine2
rget sLine3
rget sLine4
strreplace sLine1 "`n" ""
strreplace sLine2 "`r" ""
call Outlook
endwhile
endproc

proc Outlook
integer iTask, iWindow, iStatus = 0
string sTaskName

if firsttask iTask ;Search list of tasks for outlook.exe
taskname iTask sTaskName
if strnicmp sTaskName "outlook.exe" 11 ;Search for Outlook process
taskwin iTask iWindow
winactivate iWindow ;Bring Outlook to foreground
pause 2
launch_message() ;Run procedure to open new message
iStatus = 1 ;Set flag indicating Outlook was found
endif
while nexttask iTask
taskname iTask sTaskName
if strnicmp sTaskName "outlook.exe" 11
taskwin iTask iWindow
winactivate iWindow
pause 2
launch_message()
iStatus = 1
endif
endwhile
endif
if iStatus == 0 ;Outlook not active
run "c:\program files\microsoft office\office11\outlook.exe" maximized
pause 5
launch_message()
endif
endproc

proc launch_message
pause 3
sendkey CTRL 'N' ;Open new message
pause 1
sendkeystr "Gornek, Kenneth;W, William E."
pause 1
sendkey ALT 'J' ;Move to subject line
pause 1
sendkeystr "Critical PITB 5ESS Alarm - Automated"
sendkey 0x09
sendkeystr "A Critical alarm has been detected. This is an automated email for the Pittsburgh 5ESS."
sendkeystr sLine1
pause 1
sendkeystr sLine2
pause 1
sendkeystr sLine3
pause 1
sendkeystr sLine4
sendkey ALT 'S'
endproc
 
Ah shoot, wasn't as clear as I meant to be. You would want to run the two strreplace commands on all strings that you read with the rget commands:

strreplace sLine1 "`n" ""
strreplace sLine1 "`r" ""

repeat for sLine2 and so on.

Making the change I suggested for the launch_message procedure would test if there is anything "odd" about the contents of sLine2 that could be causing the problem you are seeing.

I'm going to try this on my machine a bit later tonight (just fudge some data into the sLine variables) and see what happens.

 
I understand now. I'd be interested to see what you find with your testing. Was I correct in the placement of my commands?

string sLine2, sLine1, sLine3, sLine4

proc Main
while 1
waitfor "*C" forever matchcase
rget sLine1
rget sLine2
rget sLine3
rget sLine4
strreplace sLine1 "`n" ""
strreplace sLine1 "`r" ""
strreplace sLine2 "`n" ""
strreplace sLine2 "`r" ""
strreplace sLine3 "`n" ""
strreplace sLine3 "`r" ""
strreplace sLine4 "`n" ""
strreplace sLine4 "`r" ""
call Outlook
endwhile
endproc
 
Hmm, tried the script with your values in sLine1 and sLine2 and seemed to go OK. I did notice when I went back to your output from the remote system that it looks like there might be a tab or some other formatting character in the second line based on the offset, but when I manually pressed a tab in the Outlook body nothing "bad" happened and the cursor stayed where it should.

FYI, your strreplace commands look OK but I think we can comment those out for the moment.

The next thing I would try is seeing just what is coming across from the other system and see if there is a control character or something else that Outlook may not like being dumped into a message body. You can use Procomm's Monitor Window to find this information (I've copied some information below on how to do this from my website). Basically what you'll want to do is find the corresponding strings (sLine1, sLine2) in the Monitor Window, then take a screenshot so I can look at the data. One other thing to try would be swapping sLine1 and sLine in the launch_message procedure such that the sendkeystr command sends sLine2 first - this would help us narrow down if there is something in the particular string that is causing the problem.

Procomm's Monitor Window can be used to view the incoming and outgoing data, in both hex and ASCII format. To activate this window, select the Data | Monitor Window menu item. Resize the Monitor Window so that you can view the entire width of the window, then click back in the Procomm Plus window so that the Monitor Window does not have focus. Incoming text is displayed in red, while text you send is colored blue. The Monitor Window can be handy for viewing incoming escape sequences (to determine if Procomm Plus is responding properly to them) or to verify that the program is sending the data you think it should be.

 
An email has been sent. Let me know if you don't receive it.
 
Did you get me email? I got a response but wasn't sure if it was you. It was from a military address.
 
Preliminarily it looks like there are some odd characters coming across in the text. I see a few nulls, which could cause issues with a string being terminated before it should. There is also one or two other hex characters that I need to investigate.

Did you get a chance to try swapping sLine1 and sLine2 in the launch_message procedure?

 
Yes, in the main script I changed it as follows but the email was exactly the same. FYI - I'm not sure if this matters but I am using a vt100 emulation.

string sLine2, sLine1, sLine3

proc Main
while 1
waitfor "*C" forever matchcase
rget sLine1
rget sLine2
rget sLine3
call Outlook
endwhile
endproc
 
I thought this was interesting... Look at what happened after I changed the script:

proc Monitor
while 1
waitfor "*C" forever matchcase
rget sLine1
rget sLine2
rget sLine3
strreplace sLine2 "`n" ""
strreplace sLine2 "`r" ""
call Outlook
endwhile
endproc

proc Outlook
integer iTask, iWindow, iStatus = 0
string sTaskName

if firsttask iTask ;Search list of tasks for outlook.exe
taskname iTask sTaskName
if strnicmp sTaskName "outlook.exe" 11 ;Search for Outlook process
taskwin iTask iWindow
winactivate iWindow ;Bring Outlook to foreground
pause 2
launch_message() ;Run procedure to open new message
iStatus = 1 ;Set flag indicating Outlook was found
endif
while nexttask iTask
taskname iTask sTaskName
if strnicmp sTaskName "outlook.exe" 11
taskwin iTask iWindow
winactivate iWindow
pause 2
launch_message()
iStatus = 1
endif
endwhile
endif
if iStatus == 0 ;Outlook not active
run "c:\program files\microsoft office\office11\outlook.exe" maximized
pause 5
launch_message()
endif
endproc

proc launch_message
pause 3
sendkey CTRL 'N' ;Open new message
pause 1
sendkeystr "Gornek, Kenneth;W., William E."
pause 1
sendkey ALT 'J' ;Move to subject line
pause 1
sendkeystr "Critical PITB 5ESS Alarm - Automated"
sendkey 0x09
sendkeystr "A Critical alarm has been detected. This is an automated email for the Pittsburgh 5ESS - "
sendkeystr sLine1
pause 1
sendkeystr sLine2
pause 1
sendkeystr sLine3
sendkey ALT 'S'
endproc

Here is what printed in the body of the email:

"A Critical alarm has been detected. This is an automated email for the Pittsburgh 5ESS - TST ALM – CRITICAL ALARM TEST IN PROGRESS FOR AUDIBLE AND VISUAL ALARM REPORTINGA Critical alarm has been detected. This is an automated email for the Pittsburgh 5ESS - TST ALM – CRITICAL ALARM TEST IN PROGRESS FOR AUDIBLE AND VISUAL ALARM REPORTING"

Looks like it got the more lines of the information I wanted but printed it in the body of the email twice for some reason.
 
Ok... I am getting closer. This is what I have now... The only issue I see as of now, Outlook doesn't always want to send the email correctly for some reason. (Get hung up)

Script:

string sLine1, sLine2

proc main

while 1
waitfor "*C" forever matchcase
rget sLine1
rget sLine2
strreplace sLine2 "`n" ""
strreplace sLine2 "`r" ""
call Outlook
endwhile
endproc

proc Outlook
integer iTask, iWindow, iStatus = 0
string sTaskName

if firsttask iTask ;Search list of tasks for outlook.exe
taskname iTask sTaskName
if strnicmp sTaskName "outlook.exe" 11 ;Search for Outlook process
taskwin iTask iWindow
winactivate iWindow ;Bring Outlook to foreground
pause 2
launch_message() ;Run procedure to open new message
iStatus = 1 ;Set flag indicating Outlook was found
endif
while nexttask iTask
taskname iTask sTaskName
if strnicmp sTaskName "outlook.exe" 11
taskwin iTask iWindow
winactivate iWindow
pause 2
launch_message()
iStatus = 1
endif
endwhile
endif
if iStatus == 0 ;Outlook not active
run "c:\program files\microsoft office\office11\outlook.exe" maximized
pause 5
launch_message()
endif
endproc

proc launch_message
pause 3
sendkey CTRL 'N' ;Open new message
pause 1
sendkeystr "Gornek, Kenneth;W., William E."
pause 1
sendkey ALT 'J' ;Move to subject line
pause 1
sendkeystr "Critical PITB 5ESS Alarm - Automated"
sendkey 0x09
sendkeystr "A Critical alarm has been detected. This is an automated email for the Pittsburgh 5ESS - "
sendkeystr sLine1
pause 1
sendkeystr sLine2
pause 1
sendkey ALT 'S'
endproc

Email Body:

A Critical alarm has been detected. This is an automated email for the Pittsburgh 5ESS - TST ALM – CRITICAL ALARM TEST IN PROGRESS
FOR AUDIBLE AND VISUAL ALARM REPORTING
 
Also, I was looking at the HEX code from the monitor you asked me to do and it looks as if every message ends in one of the following two codes...

0D 00 0A 19 or 0D 0A 19

HEX Description
0D carriage return
00 null
0A line feed
19 end of medium
 
One thing I do when I have to do email is use an external program called "BLAT". WIth little configuration for outlook server you can do about anything you want. THEN, procomm just has to decide that the email has to be sent.. create a small bat file to send it (and optionall create text to go in it etc).

Procomm is great at what it does.. and blat is great at what it does.. I let them both do their primary tasks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top