VI-DB vmtools.php v2

From vwiki
Jump to navigation Jump to search
<html xmlns='http://www.w3.org/TR/REC-html40'>

<!--Version 2.0 -->

<html>
<head>
<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'>
</head>
<body>

<?php
$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) {
	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 ";

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

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

//Initial summary query
$query = "SELECT vc.name AS vc, cluster.clid, cluster.name 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, cluster.name;";

$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 vc.name AS vc, cluster.name AS cl, vm.vmid, vm.name AS vm, vm_ext.vc_path, vm_ext.tools 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, vm.name;";
} else {
	$query .= "ORDER BY cl, vc_path, vm.name;";
}
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><td>";
	if ($vm['tools'] == 'toolsOld') {
		$vm['tools'] = 'Out of Date';
	} elseif ($vm['tools'] == 'toolsNotRunning') {
		$vm['tools'] = 'Not Running';
	} elseif ($vm['tools'] == 'toolsNotInstalled') {
		$vm['tools'] = 'Not Installed';
	}
	print $vm['tools']."\n";
}
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;
}
	
?>