Commit 9c25160c authored by Leigh Stoller's avatar Leigh Stoller

Add nodelog command as per Mike's request, plus web page updates for

viewing the log.
parent e8653ab5
......@@ -1025,7 +1025,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
db/webcontrol db/node_status db/genelists db/genelists.proxy \
discvr/GNUmakefile \
db/libdb.pm db/inuse db/avail db/nodeip db/showgraph \
db/dhcpd_makeconf \
db/dhcpd_makeconf db/nodelog \
ipod/GNUmakefile \
lib/GNUmakefile \
os/GNUmakefile os/split-image.sh os/imagezip/GNUmakefile \
......
......@@ -147,7 +147,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
db/webcontrol db/node_status db/genelists db/genelists.proxy \
discvr/GNUmakefile \
db/libdb.pm db/inuse db/avail db/nodeip db/showgraph \
db/dhcpd_makeconf \
db/dhcpd_makeconf db/nodelog \
ipod/GNUmakefile \
lib/GNUmakefile \
os/GNUmakefile os/split-image.sh os/imagezip/GNUmakefile \
......
......@@ -10,7 +10,7 @@ include $(OBJDIR)/Makeconf
BIN_SCRIPTS = nalloc nfree nodeip
SBIN_SCRIPTS = avail inuse showgraph if2port backup webcontrol node_status \
genelists genelists.proxy dhcpd_makeconf
genelists genelists.proxy dhcpd_makeconf nodelog
LIBEXEC_SCRIPTS =
LIB_SCRIPTS = libdb.pm
......
......@@ -55,12 +55,15 @@ use Exporter;
BATCHSTATE_ACTIVATING
TBBatchState TBSetBatchState
TB_NODELOGTYPES
TBAdmin TBProjAccessCheck TBNodeAccessCheck TBOSIDAccessCheck
TBImageIDAccessCheck TBExptAccessCheck ExpLeader MarkNodeDown
SetNodeBootStatus OSFeatureSupported IsShelved NodeidToExp
UserDBInfo DBQuery DBQueryFatal DBQueryWarn DBWarn DBFatal
DBQuoteSpecial UNIX2DBUID ExpState SetExpState ProjLeader
ExpNodes DBDateTime DefaultImageID GroupLeader TBGroupUnixInfo
TBValidNodeLogType TBValidNodeName TBSetNodeLogEntry
);
# Must come after package declaration!
......@@ -184,6 +187,9 @@ sub TB_IMAGEID_ACCESS() { 5; }
sub TB_IMAGEID_MIN() { TB_IMAGEID_READINFO; }
sub TB_IMAGEID_MAX() { TB_IMAGEID_ACCESS; }
# Node Log Types
sub TB_NODELOGTYPES() { ("misc") ; }
#
# We should list all of the DB limits.
#
......@@ -1009,6 +1015,65 @@ sub UNIX2DBUID ($$) {
return 1;
}
#
# Validate a node log type.
#
# usage: TBValidNodeLogType(char *type)
# Returns 1 if the type string is valid.
# Returns 0 if not.
#
sub TBValidNodeLogType($)
{
my($type) = @_;
foreach my $actype ( TB_NODELOGTYPES ) {
if ($actype eq $type) {
return 1;
}
}
return 0;
}
#
# Insert a Log entry for a node.
#
# usage: TBSetNodeLogEntry(char *node, char *type, char *message)
# Returns 1 if okay.
# Returns 0 if failed.
#
sub TBSetNodeLogEntry($$$$)
{
my($node, $dbuid, $type, $message) = @_;
if (! TBValidNodeName($node) || !TBValidNodeLogType($type)) {
return 0;
}
return DBQueryWarn("insert into nodelog ".
"values ".
"('$node', NULL, '$type', '$dbuid', $message, now())");
}
#
# Validate a node name.
#
# usage: TBValidNodeName(char *name)
# Returns 1 if the node is valid.
# Returns 0 if not.
#
sub TBValidNodeName($)
{
my($node) = @_;
my $query_result =
DBQueryWarn("select node_id from nodes where node_id='$node'");
if ($query_result->numrows == 0) {
return 0;
}
return 1;
}
#
# Issue a DB query. Argument is a string. Returns the actual query object, so
# it is up to the caller to test it. I would not for one moment view this
......
#!/usr/bin/perl -wT
use English;
use Getopt::Std;
sub usage() {
print STDOUT "Usage: nodelog [-t type] -m <message> node [node ...]\n";
exit(-1);
}
my $optlist = "t:m:";
# Configure variables
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/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 libdb;
use libtestbed;
if (!$UID) {
die("*** $0:\n".
" Please do not run this script as root!\n");
}
if (!TBAdmin($UID)) {
die("*** $0:\n".
" You must be a TB administrator to enter a log entry\n");
}
my $errors = 0;
my $message;
my @nodes;
my $type = "misc";
my $dbuid;
#
# Verify user and get his DB uid.
#
if (! UNIX2DBUID($UID, \$dbuid)) {
die("*** $0:\n".
" Go Away! You do not exist in the Emulab Database.\n");
}
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (@ARGV < 1) {
usage();
}
@nodes = @ARGV;
if (defined($options{"m"})) {
$message = $options{"m"};
$message = DBQuoteSpecial($message);
}
else {
usage();
}
if (defined($options{"t"})) {
$type = $options{"t"};
}
#
# Validate type tag.
#
if (!TBValidNodeLogType($type)) {
die("*** $0:\n".
" Invalid log type $type!\n");
}
#
# Validate the nodes names.
#
foreach my $node ( @nodes ) {
if (! TBValidNodeName($node)) {
die("*** $0:\n".
" Invalid node name $node!\n");
}
}
#
# And then insert the log entry.
#
foreach my $node ( @nodes ) {
if (! TBSetNodeLogEntry($node, $dbuid, $type, $message)) {
print STDERR "Failed to insert entry for node $node\n";
$errors++;
}
}
exit($errors);
......@@ -54,6 +54,13 @@ echo "<p><center>
<A href='nodecontrol_form.php3?node_id=$node_id'>Yes</a>
</center>\n";
if ($isadmin) {
echo "<br><p>
<center>
<A href='shownodelog.php3?node_id=$node_id'>Node Log</a>
</center>\n";
}
#
# Standard Testbed Footer
#
......
<?php
include("defs.php3");
include("showstuff.php3");
#
# Standard Testbed Header
#
PAGEHEADER("Node Log");
#
# Only known and logged in users can do this.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);
#
# Verify form arguments.
#
if (!isset($node_id) ||
strcmp($node_id, "") == 0) {
USERERROR("You must provide a node ID.", 1);
}
#
# Check to make sure that this is a valid nodeid
#
$query_result =
DBQueryFatal("SELECT node_id FROM nodes WHERE node_id='$node_id'");
if (mysql_num_rows($query_result) == 0) {
USERERROR("The node $node_id is not a valid nodeid!", 1);
}
#
# Admin users can look at any node, but normal users can only control
# nodes in their own experiments.
#
if (! $isadmin) {
USERERROR("You do not have permission to view log for node $node_id!", 1);
}
$query_result =
DBQueryFatal("select * from nodelog where node_id='$node_id'".
"order by reported");
if (! mysql_num_rows($query_result)) {
echo "<br>
<center>
There are no entries in the log for node $node_id.
</center>\n";
}
else {
echo "<br>
<center>
Log for node $node_id.
</center><br>\n";
echo "<table border=1 cellpadding=2 cellspacing=2 align='center'>\n";
echo "<tr>
<td align=center>Date</td>
<td align=center>ID</td>
<td align=center>Type</td>
<td align=center>Reporter</td>
<td align=center>Entry</td>
</tr>\n";
while ($row = mysql_fetch_array($query_result)) {
$type = $row[type];
$log_id = $row[log_id];
$reporter = $row[reporting_uid];
$date = $row[reported];
$entry = $row[entry];
echo "<tr>
<td>$date</td>
<td>$log_id</td>
<td>$type</td>
<td>$reporter</td>
<td>$entry</td>
</tr>\n";
}
echo "</table>\n";
}
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
......@@ -680,9 +680,6 @@ function SHOWIMAGEID($imageid, $edit) {
$part1_osid = $row[part1_osid];
$part2_osid = $row[part2_osid];
$part3_osid = $row[part3_osid];
$part4_osid = $row[part4_osid];
$default_osid= $row[default_osid];
$path = $row[path];
......@@ -796,7 +793,7 @@ function SHOWIMAGEID($imageid, $edit) {
}
echo "<tr>
<td>Path: </td>
<td>Filename: </td>
<td class=left>\n";
if ($edit) {
......
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