Commit fff1d16b authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Set up aging of the log table. However, this script also does some

special stuff at Utah (MAINSITE=1).

* Before aging out, copy the entries to another DB on boss so that we
  have it forever!

* As an extra special hack of the century, copy those entries over to
  ops and store in a DB over there for Kevin to look at. This code
  will go away at some point.
parent 2f8899e2
......@@ -16,12 +16,13 @@ SBIN_SCRIPTS = avail inuse showgraph if2port backup webcontrol node_status \
genelists genelists.proxy dhcpd_makeconf nodelog unixgroups \
dbcheck interswitch dbboot grabron stategraph newwanode \
idletimes idlemail setsitevar audit changeuid \
elabinelab_bossinit update_permissions mysqld_watchdog
elabinelab_bossinit update_permissions mysqld_watchdog \
dumperrorlog
LIBEXEC_SCRIPTS = webnodelog webnfree webnewwanode webidlemail xmlconvert
LIB_SCRIPTS = libdb.pm Node.pm libdb.py libadminctrl.pm
# Stuff installed on plastic.
USERSBINS = genelists.proxy
USERSBINS = genelists.proxy dumperrorlog.proxy
USERLIBS = libtbdb.pm
#
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
#
# Check DB consistency.
#
sub usage() {
print STDOUT "Usage: dumperrorlog [-d]\n";
exit(-1);
}
my $optlist = "d";
my $debug = 1;
my $tempfile = "/var/tmp/testbed_dumperrorlog_tempfile";
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $ISMAINSITE = @TBMAINSITE@;
my $USERNODE = "@USERNODE@";
my $PROXY = "$TB/sbin/dumperrorlog.proxy";
my $SCP = "/usr/bin/scp";
my $SSHTB = "$TB/bin/sshtb";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use libdb;
use libtestbed;
# Protos
sub fatal($);
#
# Only real root can call this.
#
if ($UID != 0) {
print STDERR "You must be root to run this script!\n";
exit(-1);
}
#
# Form a temp name.
#
my $logname = TBMakeLogname("dumperrorlog");
#
# Parse command arguments. Once we return from getopts, all that should
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (@ARGV) {
usage();
}
if (defined($options{"d"})) {
$debug++;
}
#
# Reopen both stdout and stderr so that we can record all the output for
# later mailing.
#
if (! $debug) {
open(STDERR, ">> $logname") or die("opening $logname for STDERR: $!");
open(STDOUT, ">> $logname") or die("opening $logname for STDOUT: $!");
}
#
# Get the last index we archived out.
#
my $query_result =
DBQueryFatal("select idx from emulab_indicies ".
"where name='lastlog_seqnum'");
my ($lastseq) = $query_result->fetchrow_array();
if (!defined($lastseq)) {
DBQueryFatal("insert into emulab_indicies (name, idx) ".
"values ('lastlog_seqnum', 0)");
$lastseq = 0;
}
#
# Grab the index number for the NOTICE priority.
#
$query_result =
DBQueryFatal("select priority from priorities where name='NOTICE'");
my ($NOTICE) = $query_result->fetchrow_array();
if (!defined($NOTICE)) {
fatal("No priority named 'NOTICE' in the priorities table!");
}
#
# Only the main site does this archiving stuff.
#
if ($ISMAINSITE) {
#
# Must lock the table of course
#
DBQueryFatal("lock tables log write");
my $maxseq = $lastseq + 10;
#
# Grab all of the new entries and store to the file
#
DBQueryFatal("select * from log ".
"where seq > $lastseq " .
"into outfile '${tempfile}.log' ");
#
# Now we need to find out what the last index really was.
#
$query_result =
DBQueryFatal("select seq from log ".
"where seq > $lastseq " .
"order by seq desc limit 1");
# Save for later.
$lastseq = $query_result->fetchrow_array();
DBQueryFatal("unlock tables");
#
# Might not be any new entries ...
#
if (defined($lastseq)) {
system("echo \"load data infile '${tempfile}.log' into table log\" ".
" | mysql errorlog");
fatal("Could not load into archive DB!")
if ($?);
# Okay, now that we have really archived them away, update the
# seq number.
DBQueryFatal("update emulab_indicies set idx='$lastseq' ".
"where name='lastlog_seqnum'");
#
# XXX This awful hack will go away when Kevin is happy with
# the error logging code.
#
#
# Copy the file over to ops and load it into the DB over there.
#
system("$SCP -p ${tempfile}.log ".
" ${USERNODE}:/var/db/mysql/errorlog") == 0
or fatal("Could not copy $tempfile to $USERNODE!");
system("$SSHTB -host $USERNODE $PROXY log") == 0
or fatal("Could not load log entries into ops DB!");
}
unlink("${tempfile}.log");
#
# Now the other tables Kevin needs
#
foreach my $tablename ("scripts", "priorities") {
DBQueryFatal("select * from $tablename ".
"into outfile '${tempfile}.${tablename}' ");
system("echo \"load data infile '${tempfile}.${tablename}' ".
" into table $tablename\" | mysql errorlog");
fatal("Could not load $tablename into archive DB!")
if ($?);
#
# Copy the file over to ops and load it into the DB over there.
#
system("$SCP -p ${tempfile}.${tablename} ".
" ${USERNODE}:/var/db/mysql/errorlog") == 0
or fatal("Could not copy ${tempfile}.${tablename} to $USERNODE!");
system("$SSHTB -host $USERNODE $PROXY $tablename") == 0
or fatal("Could not load $tablename entries into ops DB!");
unlink("${tempfile}.${tablename}");
}
}
#
# And then age out entries older then 14 days.
#
DBQueryFatal("delete from log ".
"where stamp < (UNIX_TIMESTAMP(now()) - (14 * 24 * 60 * 60))");
#
# And age out non critical data older then 7 days.
#
DBQueryFatal("delete from log ".
"where priority > $NOTICE and ".
" stamp < (UNIX_TIMESTAMP(now()) - (7 * 24 * 60 * 60))");
exit(0);
sub fatal($)
{
my ($msg) = @_;
SENDMAIL($TBOPS, "DumpErrorLog Failed", $msg, undef, undef, ($logname));
unlink("$logname")
if (-e $logname);
die("*** $0:\n".
" $msg\n");
}
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Mysql;
#
# usage: dumperrorlog.proxy
#
sub usage() {
print STDOUT "Usage: dumperrorlog.proxy tablename\n";
exit(-1);
}
my $tablename;
#
# Configure variables
#
my $PWDFILE = "/usr/testbed/etc/errorlog.pwd";
my $tempfile = "testbed_dumperrorlog_tempfile";
my $DBNAME = "errorlog";
my $DBUSER = "errorlog";
#
# We don't want to run this script unless its the real version.
#
if ($UID != 0) {
die("*** $0:\n".
" Must be root!\n");
}
# un-taint path
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use libtestbed;
sub fatal($) {
my ($msg) = @_;
die("*** $0:\n".
" $msg\n");
}
if (@ARGV != 1) {
usage();
}
$tablename = $ARGV[0];
#
# Untaint the arguments.
#
if ($tablename =~ /^([-\w]+)$/) {
$tablename = $1;
}
else {
die("Tainted argument $tablename!\n");
}
#
# Grab the password we need.
#
my $pwd = `cat $PWDFILE`;
if ($pwd =~ /^([\w]*)$/) {
$pwd = $1;
}
else {
fatal("Bad characters in password!");
}
my $DB = Mysql->connect('localhost', $DBNAME, $DBUSER, $pwd);
fatal("Could not connect to errorlog DB!")
if (!defined($DB));
my $query_result =
$DB->query("load data infile '${tempfile}.${tablename}' ".
"replace into table $tablename");
if (! defined($query_result)) {
fatal("DB Error: " . $DB->errstr . "\n");
}
exit(0);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment