I recently added some more functionality to the NSAPI scripting plugin:
1. -f, -s, and -d options to the test command.
2. a cachefilename command, which generates the
corresponding cache file's full path, provided a URL.
3. A runsaf command.
4. An isalive command.
In the first case, as is obvious, -f checks if a file exists, -s outputs the
size, and -d checks the directory exists - pretty much similar to the unix shell.
In the case of cachefilename, it's a lil more complicated - a bit of
"outside" help is needed. cachefilename expects two variables to be
predefined: one is cache-root, and it's value should be the full path
to the cache partition of the proxy instance. The other is cache-ndirs
which obviously is the number of section dirs under the partition.
runsaf does what it's name suggests:
runsaf "set-proxy-server" "server=proxy1.domain.com:8080"
And finally, isalive takes two arguments, a hostname and port, and checks if
there is anyone listening on the host at that port.
for example, here is a simple script which logs the availability status of
the cache file name of each incoming request:
cache-root = "/opt/sun/proxyserver40/proxy-server1/cache"
cache-ndirs = 16
cfname = cachefilename $rq.reqpb.uri
if test -f $cfname
then
message = "does exist!"
else
message = "does not exist!'
fi
log inform "$rq.reqpb.uri: cache file $cfname $message"
req noaction
Here is another example script which uses some of the above mentioned commands:
servers = "p1.domain1.com p2.domain2.com p3.domain3.com p4.domain4.com"
for host in $servers
do
if isalive $host 8080
then
log inform "using proxy $host:8080"
runsaf "set-proxy-server" "server=$host:8080"
req proceed
else
log warn "proxy $host:8080 is down"
fi
done
rq.srvhdrs.status = "500 All Proxies Down"
req aborted
When a request arrives, the script basically searches for an "alive" proxy to
route it to. If a particular proxy happens to be down, a warning message is
printed into the logs.
The latest plugin binary (for sparc) can be found here.