Alert if Text Found in a TXT File

Discuss RoboTask here
Post Reply
kerrycwh
Posts: 5
Joined: Wed Apr 04, 2018 10:50 pm

Alert if Text Found in a TXT File

Post by kerrycwh »

Hello,
I would like to have a file monitored in our logs and if a certain string of text appears (which will inhibit other processes) then have an alert sent.

Specially check a file called AdventImportLog.txt and if it ever reads... 'Error: 1 Duplicate holdings found' to then send an email to my team alerting them that. We have sent other alerts via email and it works great. But was not sure about the reading thru text.

Thanks!
Kerry
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Alert if Text Found in a TXT File

Post by Oleg »

The simplest way is below.
You can attach some trigger the the task or run this task when you command line finished.
This is optimal way if the file is not very large

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1075658632
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task509"
Hide=INTEGER|0
ID=INTEGER|1194659953
LogOnAsUser=INTEGER|1
Name=STRING|"alert if some text found"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""FILENAME"" with value ""c:\temp\AdventImportLog.txt"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"FILENAME"
varvalue=STRING|"c:\temp\AdventImportLog.txt"

[Actions\Action2]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action2\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"6"
type=STRING|"0"
value1=STRING|"Error: 1 Duplicate holdings found"
value2=STRING|"{TextFile({Filename})}"

[Actions\Action3]
ActionID=STRING|"A_INET_SENDMAIL"
Enabled=INTEGER|-1
Name=STRING|"Send Email"
Params=FOLDER

[Actions\Action3\Params]
attachcount=STRING|"0"
auth=STRING|"0"
charset=STRING|"iso-8859-1"
from=STRING|"user@myhost.com"
host=STRING|"server.com"
html=STRING|"0"
msg0=STRING|"Found error in the log"
msgcount=STRING|"1"
passwordmode=STRING|"0"
port=STRING|"25"
priority=STRING|"1"
receipt=STRING|"0"
SSL=STRING|"0"
subject=STRING|"Error alert "
to=STRING|"admin@myhost.com"
xmailer=STRING|"RoboTask"

[Actions\Action4]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Pay attention that this is example only. You have to change parameters to yours.
Oleg Yershov
kerrycwh
Posts: 5
Joined: Wed Apr 04, 2018 10:50 pm

Re: Alert if Text Found in a TXT File

Post by kerrycwh »

hello,
i will try this, thank you. i copy and pasted into a txt file and then imported into Robotask, but should the extension be different?

can you also be more specific to what to change? i see 4 actions in there. i would like to do a file monitor to basically first see when the file changes, and then run the text scan. could i just do a trigger of file monitor and then action 2, and action 3?
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Alert if Text Found in a TXT File

Post by Oleg »

... but should the extension be different?
The extension doesn't matter. The task is text only
...can you also be more specific to what to change?
I think that you have to change file path in step #1 and email parameters in step #3
Oleg Yershov
Post Reply