VI-DB run-errors.php v2.1

From vwiki
Revision as of 08:53, 12 October 2011 by Sstrutt (talk | contribs) (Initial creation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
<html xmlns='http://www.w3.org/TR/REC-html40'>

<!--Version 2.1 -->

<html>
<head>
<title>vi-db (run-errors)</title>
<link rel='SHORTCUT ICON' href='favicon.ico'>
<link rel='stylesheet' type='text/css' href='alpha.css' />
<meta name='Author' content='Simon Strutt'>
<meta name='Description' content='VI Info'>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<meta http-equiv="Content-Type" content="image/jpeg" >
<meta http-equiv='Pragma' content='no-cache'>
<meta http-equiv='Expires' content='900'>
</head>
<body>

<?php
$time_start = microtime(true);

//Local variables etc
require 'config.php';

// open connection and select database
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect to database!");
mysql_select_db($db) or die ("Unable to select database!");

//Set debug on if required
if (array_key_exists('debug', $_REQUEST) and ($_REQUEST["debug"] == 1)) {
	$debug = 1;
}

// show parameters and errors
if ($debug) {
	error_reporting(-1);
	print_r($_REQUEST);
	print "<br>";
}

print "DISCLAIMER: Please use all information gained from here with caution - I haven't performed exhaustive validation and testing of any of the information that may be presented.<br>\n";
print "If you're making changes or decisions, please double check with the reality of what is displayed by the vCentre servers.  You retain full responsibility for your actions...!\n ";

if (!array_key_exists('runid', $_REQUEST)) {
	die ("Error - required parameter does not exist!");
}

// Initial query (need VM name for page title)

$query = "SELECT vc.site, vc.name, sev, text, script_run_error.stamp FROM script_run_error JOIN vc USING (vcid) WHERE runid=". $_REQUEST["runid"];
$query .= " ORDER BY site, vc.name, script_run_error.stamp;";
if ($debug) {print ($query);}
$result = mysql_query($query);
//print $query;
if (mysql_num_rows($result) == 0) {
	die ("No errors found for script run!");
}
print "<h1>Script run errors</h1>";

// ----------------- Layout table (top left) ----------------------------
print "<table align='center' cellspacing=10><tr><td valign='top'>\n";


// ----------------- Error logs  ---------------------------------------
print "<table class='BasicTable' align='center'>\n<tr><th>Site<th>vCentre<th>Severity<th>Error Text<th>Timestamp\n";
while ($error = mysql_fetch_assoc($result)) {
	print "<tr><td>".$error['site']."<td>".$error['name'];
	if ($error['sev'] == 3) {
		print "<td>warn";
	} elseif ($error['sev'] == 2) {
		print "<td class='warn'>error";
	} elseif ($error['sev'] == 1) {
		print "<td class='alert'>Critical";
	} elseif ($error['sev'] == 0) {
		print  "<td class='good'>note";
	} else {
		print "<td class='alert'>Unexpected";
	}
	print "<td>".$error['text']."<td>".$error['stamp']."\n";
}
print "</table>\n";

// ------------------- Layout table end ------------------------------
print "</table>\n";

print "<br><a href='index.php'>Back to search page</a><br>\n";
	
$time = round((microtime(true) - $time_start)*1000);
print "Page took $time msecs to execute on server";

// ------------------- End of HTML ---------------------------------
print "</body><html>";

// ================ FUNCTIONS ============================

	
?>