nodelog.in 1.92 KB
Newer Older
1
#!/usr/bin/perl -wT
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3 4 5 6 7

#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
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);