Monitoring radmind (updated)
(Updated 5/7/04) Once you have set up some sort of
automation for radmind, so that it runs automatically every night, for example,
it becomes important to be able to monitor the machines you manage to see if
they are running radmind regularly and to be notified if there are any
problems.
The run_radmind script we use emails us if there is
a failure. But what if the failure is that the script never runs at all? Do
you want to assume that because you haven't been notified of a problem, that
everything is fine? So we have the script also perform an action on success.
Since the vast majority of our machines are successful, and a large chunk of
them run radmind every night, we don' t want to be buried in emails telling us
everything is OK.
So on success, our
run_radmind script calls a web CGI like so (in
Perl):
#check in with the radmind
check-in cgi
system "curl
http://radmind/cgi-bin/radmindCheckin";
and
here's the
CGI:
#!/usr/bin/perl
#
Radmind checkin
CGI
#
#
this simple CGI touches a file in
$UPDATE_DIR
# with the hostname of the
the machine reporting in (This
assumes
# your machine's hostnames are
in DNS and reverse lookup works)
#
otherwise it touches a file named the same as the IP address
of
# the machine reporting
in.
#
#
Copyright 2003 Walt Disney Feature
Animation
# Permission granted to use
this code
freely.
#
#
this CGI can be called from a script like
so:
# curl
"http://your.webserver.tld/cgi-bin/radmindCheckin"
#
#
Original Script by Greg Neagle,
WDFA.
#
#
02/11/2004 Modification of the original code to support running on Panther
Server
# - Lance Ogletree ,
Rice
University
#
#
05/06/2004 Modification to deal with Apache sometimes returning the remote IP in
# $ENV{SERVER_ADDR} and
sometimes in $ENV{HTTP_PC_REMOTE_ADDR},
# depending on the server
configuration.
# This
should make the script more portable.
# Thanks to Josh Burker,
Mercer Island School District for helping debug
# this
issue.
# - Greg Neagle,
WDFA
#
#
05/06/2004 Added ability to pass in a custom hostname; this might make this
script
# usable in
environments where useful hostnames are not in
DNS.
# You could then have
the machine grab a name from a file or by
using
# `scutil --get
LocalHostName` or `scutil --get
ComputerName`
# You'd then
call the CGI like so:
#
curl
"http://your.webserver.tld/cgi-bin/radmindCheckIn?mycustomhostname
#
- Greg Neagle,
WDFA
#
print
"Content-type: text/plain\n";
print
"\n";
print "Radmind
check-in\n";
print
"\n";
$UPDATE_DIR =
"/var/radmind/client/updated/";
# be
sure the directory pointed to by $UPDATE_DIR
exists
# and that it's writable by the
web server
$hostname =
$ENV{QUERY_STRING};
if
($hostname eq "")
{
#no custom
hostname passed in, so let's generate
one
$IP =
$ENV{HTTP_PC_REMOTE_ADDR};
if
($IP eq "")
{
#
depending on Apache
config/environment
#
we need to use $ENV{REMOTE_ADDR}
instead
$IP
=
$ENV{REMOTE_ADDR};
}
$hostoutput
= `host $IP`;
unless
($hostoutput =~ /not found/)
{
#
parse out the
hostname
@hostoutput
= split /\s+/,
$hostoutput;
$hostname
= pop
@hostoutput;
$hostname
=~ s/\.$//;
} else
{
#
use the IP as the
hostname
$hostname
=
$IP;
}
}
print
"$hostname successfully checked
in.\n";
$cmd = "/usr/bin/touch
$UPDATE_DIR$hostname";
`$cmd`;
The
CGI is very simple. All it does is take the IP address of the incoming
connection, look up the DNS hostname of that IP address, and then "touches" a
file with the name of the host in a directory we've created to hold these (We
used "/var/radmind/client/updated/").
The
"touch" command creates an empty file if one does not exist, or updates the
modification date on the file if it already
exists.
If there is no hostname associated
with the IP address, it touches a file named after the IP address
("192.168.1.1").
Finally, you can pass the
CGI a hostname - this could be useful if the machine has a file it can use to
come up with a unique name (like a radmind certificate), or you've set the
"Computer Name" or Rendezvous name. In this case, you'd call the CGI like so
(again in Perl):
system "curl
http://radmind/cgi-bin/radmindCheckin?customhostname";
You
can then tell the last time a machine successfully ran radmind by looking at the
modification date of the file with its name. We have another CGI which presents
this info in a nice web page. Details in anther entry on this
site.
Since I originally posted this
script last December, Lance Ogletree contributed a modification that lets it run
properly under Panther, Josh Berker surfaced an issue (and helped me debug it)
with some configurations of Apache, and I added the custom hostname
feature.
Enjoy.
Posted: Fri - May 7, 2004 at 10:46 PM