VI-DB vmtools.php v2.1

From vwiki
Revision as of 08:55, 12 October 2011 by Sstrutt (talk | contribs) (Initial creation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
<html xmlns=''>

<!--Version 2.1 -->

<title>vi-db (vmtools)</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'>

$time_start = microtime(true);

//Local variables etc
require 'config.php';
$self = $_SERVER['PHP_SELF'];

// 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) {
	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 ";

print "<h1>VM's with Problematic VMTools</h1>\n";

if (array_key_exists('clid', $_REQUEST)) {
	$cl_link = "&clid=".$_REQUEST["clid"];
} else {
	$cl_link = "";

//Initial summary query
$query = "SELECT AS vc, cluster.clid, AS cluster, COUNT(vmid) AS VMs, SUM(IF(tools='toolsOld',1,0)) AS old, SUM(IF(tools='toolsNotRunning',1,0)) AS stop, ";
$query .= "SUM(IF(tools='toolsNotInstalled',1,0)) AS noinstall FROM vm JOIN vc USING (vcid) JOIN cluster USING (clid) JOIN vm_ext USING (vmid) WHERE vm.exist=1 AND vm.is_on=1 ";
$query .= "AND tools!='ToolsOK' GROUP BY clid ORDER BY vc,;";

$result = mysql_query($query);
//print $query;
if (mysql_num_rows($result) == 0) {
	die ("No machines found...!");

print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th>Cluster<th>Out of<br>Date<th>Not<br>Running<th>Not<br>Installed<th>Total\n";
while ($row = mysql_fetch_assoc($result)) {
	print "<tr><td>".$row['vc']."<td><a href='$self?clid=".$row['clid']."'>".$row['cluster']."<td class='num'>".$row['old']."<td class='num'>".$row['stop']."<td class='num'>".$row['noinstall']."<td class='num'>".$row['VMs'];
if (array_key_exists('clid', $_REQUEST)) {
	print "<tr><td align='center' colspan=6><a href=$self>For All Clusters</a>\n";
} else {
	print "<tr><td align='center' colspan=6><b>&uarr; &uarr;</b> Filter On Cluster\n";
print "</table><br>\n";

// Detail query
$query = "SELECT AS vc, AS cl, vm.vmid, AS vm, vm_ext.vc_path, FROM vm JOIN vc USING (vcid) JOIN cluster USING (clid) JOIN vm_ext USING (vmid) ";
$query .= "WHERE vm.exist=1 AND vm.is_on=1 AND tools!='ToolsOK' ";
if ($clid > 0) {
	$query .= "AND cluster.clid=$clid ORDER BY cl, vc_path,;";
} else {
	$query .= "ORDER BY cl, vc_path,;";
if ($debug == 1) {print ($query);}
$result = mysql_query($query);

if (mysql_num_rows($result) == 0) {
	die ("None...!");
print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th>Cluster<th>Folder<th>VM Name<th>Tools State\n";

$vms = mysql_fetch_all($result, MYSQL_ASSOC);
$odd_row = false;
foreach ($vms as $vm) {
	$odd_row = !$odd_row;
	if ($odd_row) {
		print "<tr class='odd'>";
	} else {
		print "<tr>";
	print "<td>".$vm['vc']."<td>".$vm['cl']."<td>".$vm['vc_path']."<td><a href=vm-detail.php?vmid=".$vm['vmid'].">".$vm['vm']."</a>";
	switch ($vm['tools']) {
		case 'toolsOk':
			print "<td>Tools OK";
		case 'toolsOld':
			print "<td>Out of Date";
		case 'toolsNotRunning':
			print "<td>Not Running";
		case 'toolsNotInstalled':
			print "<td>Not Installed";
			print "<td>".$vm['tools'];
print "</table><br>";

print "<br><table class='NavTable' align='center' valign='top'><th>Main Pages:<td><a href='index.php'>Search page</a><td><a href='status.php'>Status page</a></table><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 ============================

function search_char ($text) {
	return (str_replace(array("*", "?"), array("%", "_"), trim($text)));

function mysql_fetch_all($result) {
   while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
       $return[] = $row;
   return $return;