Home
About
Agents
CGIs
Mac
Macros
Misc
Stories
Suites
Websites
Outline
Frontier
Scripting

Babysitting a Server

We needed this script at UserLand, as do many sysops managing remote servers.

It's an agent script that runs once every five minutes. It sends a message to a server over HTTP. It looks at the response. If there's an error, it adds a message to a log outline and beeps the speaker.

agents.botherBetty is set up to watch betty.userland.com, but please set it up to bother another machine instead. Thanks!

It sends a helloWorld message, assuming that the server has been configured to send back a simple response. If your server is running the Betty software, you can depend on it responding to a helloWorld request in this way. If it's running another kind of software you may want to ask for something else, and check the response accordingly.

Listing

Since it's a relatively short script, here's a listing of its source code. Have fun!

local (minutesBetweenRuns = 5)
local (ipServer = "betty.userland.com")
local (portServer = 80)
local (adroutline = @scratchpad.bettyErrorLog)
local (adrcounter = @scratchpad.bettyCounter)
on logError (errorstring, extrainfo)
if not defined (adroutline^)
new (outlineType, adroutline)
target.set (adroutline)
op.firstSummit ()
op.insert (clock.now () + ": " + errorstring, up)
op.insert (extrainfo, right)
op.firstSummit ()
target.clear ()
edit (adroutline)
speaker.beep ()
try
local (s = tcp.httpClient (method:"GET", server:ipServer, port:portServer, path:"helloworld", debug:false))
local (ix = string.patternMatch ("\r\n\r\n", s))
local (response = string.delete (s, 1, ix + 3))
if response != "<html><body>Hello World!</body></html>"
logError ("Bad response from server.", response)
else
logError ("TCP error.", tryError)
if not defined (adrcounter^)
adrcounter^ = 1
else
adrcounter^++
msg ("We've bothered " + ipServer + " " + adrcounter^ + " times.")
clock.sleepFor (minutesBetweenRuns * 60)


This is a fat web page containing system.agents.botherBetty. More info on fat pages here.

© copyright 1997-98 UserLand Software. This page was originally posted on 3/18/98; 6:31:38 PM and it was last built on 9/11/98; 9:22:44 AM. Webmaster: dave@userland.com.