|
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 (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 () |
| 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) |
| logError ("TCP error.", tryError) |
if not defined (adrcounter^) |
| adrcounter^ = 1 |
| adrcounter^++ |
msg ("We've bothered " + ipServer + " " + adrcounter^ + " times.") |
clock.sleepFor (minutesBetweenRuns * 60) |
|