nodelog.in 2.42 KB
Newer Older
1
#!/usr/bin/perl -wT
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
24
use strict;
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
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;
51 52
use User;
use Node;
53 54 55 56 57 58 59 60 61 62 63

if (!$UID) {
    die("*** $0:\n".
	"    Please do not run this script as root!\n");
}

my $errors = 0;
my $message;
my $type = "misc";

#
64
# Verify user.
65
#
66 67 68
my $this_user = User->ThisUser();
if (! defined($this_user)) {
    die("You ($UID) do not exist!\n");
69
}
70 71 72 73
if (! ($this_user->IsAdmin() || $this_user->IsOpsGuy())) {
    die("*** $0:\n".
	"    You must be a TB administrator to enter a log entry\n");
}
74 75 76 77 78

#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
79
my %options = ();
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
if (! getopts($optlist, \%options)) {
    usage();
}
if (@ARGV < 1) {
    usage();
}
if (defined($options{"m"})) {
    $message = $options{"m"};
}
else {
    usage();
}
if (defined($options{"t"})) {
    $type = $options{"t"};
}

#
97
# Grab nodes and insert.
98
#
99 100 101
foreach my $node_id ( @ARGV ) {
    my $node = Node->Lookup($node_id);
    if (!defined($node)) {
102
	die("*** $0:\n".
103
	    "    No such node: $node_id!\n");
104
    }
105 106
    if ($node->InsertNodeLogEntry($this_user, $type, $message) != 0) {
	print STDERR "*** Failed to insert entry for node $node\n";
107 108 109 110
	$errors++;
    }
}
exit($errors);