PROGRAM 1
Here is a program to monitor craigslist for software internship postings. First a configuration block is defined to contain the data necessary for notification of the results of this monitoring task. Variables are defined in this block for the data, which will be used by the notify(configBlock) plugin. Another block is defined for the url data, which might in another task contain a user ID and password. For this task only a url is necessary.
Finally a task is defined and begun using a get plugin. The getHTML(configBlock) plugin retrieves text from a web address using the data in its argument block, which is passed to the next plugin called. removeHTMLtags() strips away HTML tags, leaving text for processing by the next plugin. keepAfter(strArg) passes on the text which comes after the first occurrence of its argument string (optionally using regular expressions), and removeFrom(strArg) strips from the text its argument string and everything after it.
The above plugin calls completely define what is to be done in the task, and their result is passed to the monitor(timeValue) plugin, which defines how often this task is to be performed. The notify(configBlock) plugin comes last and performs the needed notification of results.
[Config:StdEmail]
to = myname@gmail.com
server = smtp.gmail.com
port = 465
UserID = myname@gmail.com
Password = rumplestiltskin
[Config:CraigURL]
url = "http://sfbay.craigslist.org/search/egr?query=internship&catAbbreviation=sof"
[Task:CraigslistInternship]
getHTML(CraigURL)
removeHTMLtags()
keepAfter("Found: [0-9]* Displaying: [0-9]*")
removeFrom("Found: [0-9]* Displaying: [0-9]*)
monitor(5 minutes)
notify(StdEmail)
Whenever the text result of this task is different from the previous result of the task, the user will be notified.
PROGRAM 2
This program similarly uses a configuration Block for notification, but gets a locally stored file. It retains as a result every line in the file containing "error", and notifies the user of new errors every tenth of a second.
[Config:SecurityEmail]
to = security@mydomain.com
server = smtp.mydomain.com
port = 950
UserID = monitor@mydomain.com
Password = unbreakable
[Task:FirewallLog]
getFile("\logs\firewall.log")
keepEachLineWith(“error”)
monitor(0.1 second)
notify(SecurityEmail)
PROGRAM 3
This last program combines two tasks: the one from the first program and a unix command. The unix command does its own parsing and extracting, so only the montor(timeValue) and notify(configBlock) are required.
[Config:StdEmail]
to = myname@gmail.com
server = smtp.gmail.com
port = 465
UserID = myname@gmail.com
Password = rumplestiltskin
[Config:CraigURL]
url = "http://sfbay.craigslist.org/search/egr?query=internship&catAbbreviation=sof"
[Config:CS164Email]
to = cs164-ai@berkeley.edu
server = smtp.gmail.com
port = 465
UserID = myname@gmail.com
Password = rumplestiltskin
[Task:CraigslistInternship]
getHTML(CraigURL)
removeHTMLtags()
keepAfter("Found: [0-9]* Displaying: [0-9]*")
removeFrom("Found: [0-9]* Displaying: [0-9]*)
monitor(5 minutes)
notify(StdEmail)
[Task:Glookup]
execCmd(`glookup|grep final`)
monitor(15 minutes)
notify(CS164Email)
Friday, December 11, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment