Commit bc2b571d authored by Leigh B. Stoller's avatar Leigh B. Stoller

Just for Mike ... add a console log icon and add option to show last N

lines of console log.
parent 1174c5e7
...@@ -12,12 +12,14 @@ use Getopt::Std; ...@@ -12,12 +12,14 @@ use Getopt::Std;
# #
sub usage() sub usage()
{ {
print(STDOUT "Usage: spewconlog node\n"); print(STDOUT "Usage: spewconlog [-l linecount] node\n");
exit(-1); exit(-1);
} }
my $optlist = ""; my $optlist = "l:";
my $logdir = "/var/log/tiplogs"; my $linecount = 0;
my $logdir = "/var/log/tiplogs";
my $logname; my $logname;
my $cmd;
# #
# Configure variables # Configure variables
...@@ -74,6 +76,18 @@ my $logfile; ...@@ -74,6 +76,18 @@ my $logfile;
if (! getopts($optlist, \%options)) { if (! getopts($optlist, \%options)) {
usage(); usage();
} }
if (defined($options{"l"})) {
$linecount = $options{"l"};
# Untaint of course.
if ($linecount =~ /^([\d]+)$/) {
$linecount = $1;
}
else {
die("*** $0:\n".
" Bad data in linecount: $linecount\n");
}
}
usage() usage()
if (@ARGV != 1); if (@ARGV != 1);
my $node = $ARGV[0]; my $node = $ARGV[0];
...@@ -117,6 +131,13 @@ else { ...@@ -117,6 +131,13 @@ else {
$logname = "$logdir/${node}.log" $logname = "$logdir/${node}.log"
} }
if ($linecount) {
$cmd = "tail -". $linecount
}
else {
$cmd = "cat";
}
# #
# Run an ssh command in a child process, protected by an alarm to # Run an ssh command in a child process, protected by an alarm to
# ensure that the ssh is not hung up forever if the machine is in # ensure that the ssh is not hung up forever if the machine is in
...@@ -144,6 +165,6 @@ if ($syspid) { ...@@ -144,6 +165,6 @@ if ($syspid) {
# Now we want to ssh over and cat the file. # Now we want to ssh over and cat the file.
# #
$UID = 0; $UID = 0;
system("sshtb -host $tipserver cat $logname"); system("sshtb -host $tipserver $cmd $logname");
$UID = $SAVEUID; $UID = $SAVEUID;
exit(($? == 0 ? 0 : 1)); exit(($? == 0 ? 0 : 1));
...@@ -40,6 +40,19 @@ else { ...@@ -40,6 +40,19 @@ else {
PAGEARGERROR("Must specify a node ID!"); PAGEARGERROR("Must specify a node ID!");
} }
#
# Look for linecount argument
#
if (isset($linecount) && $linecount != "") {
if (! TBvalid_integer($linecount)) {
PAGEARGERROR("Illegal characters in linecount!");
}
$optarg = "-l $linecount";
}
else {
$optarg = "";
}
# #
# A cleanup function to keep the child from becoming a zombie. # A cleanup function to keep the child from becoming a zombie.
# #
...@@ -56,7 +69,7 @@ function SPEWCLEANUP() ...@@ -56,7 +69,7 @@ function SPEWCLEANUP()
} }
register_shutdown_function("SPEWCLEANUP"); register_shutdown_function("SPEWCLEANUP");
$fp = popen("$TBSUEXEC_PATH $uid nobody webspewconlog $node_id", "r"); $fp = popen("$TBSUEXEC_PATH $uid nobody webspewconlog $optarg $node_id", "r");
if (! $fp) { if (! $fp) {
USERERROR("Spew console log failed!", 1); USERERROR("Spew console log failed!", 1);
} }
......
...@@ -1203,7 +1203,8 @@ function SHOWNODES($pid, $eid, $sortby) { ...@@ -1203,7 +1203,8 @@ function SHOWNODES($pid, $eid, $sortby) {
<th>Last Log Message</th>\n"; <th>Last Log Message</th>\n";
} }
echo " <th><a href=\"docwrapper.php3?docname=ssh-mime.html\">SSH</a></th> echo " <th><a href=\"docwrapper.php3?docname=ssh-mime.html\">SSH</a></th>
<th><a href=\"faq.php3#tiptunnel\">Console</a></th>"; <th><a href=\"faq.php3#tiptunnel\">Console</a></th> .
<th>Log</th>";
# Only put out a RDP column header if there are any Windows nodes. # Only put out a RDP column header if there are any Windows nodes.
$windows_query_result = DBQueryFatal("SELECT r.pid,r.eid,n.node_id,oi.OS ". $windows_query_result = DBQueryFatal("SELECT r.pid,r.eid,n.node_id,oi.OS ".
...@@ -1294,6 +1295,12 @@ function SHOWNODES($pid, $eid, $sortby) { ...@@ -1294,6 +1295,12 @@ function SHOWNODES($pid, $eid, $sortby) {
<A href='nodetipacl.php3?node_id=$node_id'> <A href='nodetipacl.php3?node_id=$node_id'>
<img src=\"console.gif\" alt=c></A> <img src=\"console.gif\" alt=c></A>
</td>\n"; </td>\n";
echo " <td align=center>
<A href='showconlog.php3?node_id=$node_id".
"&linecount=200'>
<img src=\"/icons/f.gif\" alt='console log'></A>
</td>\n";
} }
if ($iswindowsnode) { if ($iswindowsnode) {
......
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