https://vwiki.co.uk/index.php?title=VI-DB_esxs.php_v2&feed=atom&action=history
VI-DB esxs.php v2 - Revision history
2024-03-29T06:48:14Z
Revision history for this page on the wiki
MediaWiki 1.37.2
https://vwiki.co.uk/index.php?title=VI-DB_esxs.php_v2&diff=1409&oldid=prev
Sstrutt: Initial creation
2011-08-31T14:05:54Z
<p>Initial creation</p>
<p><b>New page</b></p><div><source lang="php"><br />
<br />
<html xmlns='http://www.w3.org/TR/REC-html40'><br />
<br />
<!-- Version 1.0 --><br />
<br />
<html><br />
<head><br />
<title>vi-db (esx-hware)</title><br />
<link rel='SHORTCUT ICON' href='favicon.ico'><br />
<link rel='stylesheet' type='text/css' href='alpha.css' /><br />
<meta name='Author' content='Simon Strutt'><br />
<meta name='Description' content='VI Info'><br />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" ><br />
<meta http-equiv="Content-Type" content="image/jpeg" ><br />
<meta http-equiv='Pragma' content='no-cache'><br />
<meta http-equiv='Expires' content='900'><br />
</head><br />
<body><br />
<br />
<?php<br />
$time_start = microtime(true);<br />
<br />
//Local variables etc<br />
require 'config.php';<br />
$self = $_SERVER['PHP_SELF'];<br />
<br />
// open connection and select database<br />
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect to database!");<br />
mysql_select_db($db) or die ("Unable to select database!");<br />
<br />
//Set debug on if required<br />
if (array_key_exists('debug', $_REQUEST) and ($_REQUEST["debug"] == 1)) {<br />
$debug = 1;<br />
}<br />
<br />
// show parameters and errors<br />
if ($debug) {<br />
error_reporting(-1);<br />
print_r($_REQUEST);<br />
print "<br>";<br />
}<br />
<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";<br />
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 ";<br />
<br />
print "<h1>ESX Hardware</h1>\n";<br />
<br />
if (array_key_exists('clid', $_REQUEST)) {<br />
$cl_link = "&clid=".$_REQUEST["clid"];<br />
$clid=$_REQUEST["clid"];<br />
} else {<br />
$cl_link = "";<br />
$clid=0;<br />
}<br />
<br />
if (array_key_exists('hw', $_REQUEST)) {<br />
$hw_link = "&hw=".$_REQUEST["hw"];<br />
$hw=$_REQUEST["hw"];<br />
} else {<br />
$hw_link = "";<br />
$hw=0;<br />
}<br />
<br />
if (!array_key_exists('view', $_REQUEST)) {<br />
$view = "mobo";<br />
} else {<br />
if ($_REQUEST["view"] == "nic") {<br />
$view = "nic";<br />
} elseif ($_REQUEST["view"] == "hba") {<br />
$view = "hba";<br />
} elseif ($_REQUEST["view"] == "mobo") {<br />
$view = "mobo";<br />
} else {<br />
die ("Error - view parameter error!");<br />
}<br />
}<br />
<br />
//Initial summary query<br />
$query = "SELECT vc.name AS vc, cluster.clid, cluster.name AS cluster, COUNT(esxid) AS esxs, SUM(cpu_sock) AS cpu_sock, SUM(cpu_core) AS cpu_core, SUM(mem) AS mem FROM esx ";<br />
$query .= "JOIN vc USING (vcid) JOIN cluster USING (clid) WHERE esx.exist=1 GROUP BY clid ORDER BY vc, cluster.name;";<br />
<br />
$result = mysql_query($query);<br />
//print $query;<br />
if (mysql_num_rows($result) == 0) {<br />
die ("No vCentre's found...!");<br />
}<br />
<br />
// ----------------- Layout table (left) ----------------------------<br />
print "<table align='center' cellspacing=10><tr><td valign='top'>\n";<br />
<br />
<br />
print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th width=200>Cluster<th>ESXs<th>CPU<br>Socks<th>CPU<br>Cores<th>Memory<br><small>GB</small>\n";<br />
$esxs = 0;<br />
$cpu_sock_tot = 0;<br />
$cpu_core_tot = 0;<br />
$mem_tot = 0;<br />
while ($row = mysql_fetch_assoc($result)) {<br />
print "<tr><td>".$row['vc'];<br />
if ($clid == $row['clid']) {<br />
print "<td><b>".$row['cluster']."</b>";<br />
} else {<br />
print "<td><a href='$self?clid=".$row['clid']."&view=$view$hw_link'>".$row['cluster']."</a>";<br />
}<br />
print "<td class='num'>".$row['esxs']."<td class='num'>".$row['cpu_sock']."<td class='num'>".$row['cpu_core']."<td class='num'>".number_format(round($row['mem']/1024));<br />
$esxs += $row['esxs'];<br />
$cpu_sock_tot += $row['cpu_sock'];<br />
$cpu_core_tot += $row['cpu_core'];<br />
$mem_tot += $row['mem'];<br />
}<br />
print "<tr><td colspan=2><td class='num'>".$esxs."<td class='num'>".$cpu_sock_tot."<td class='num'>".$cpu_core_tot."<td class='num'>".number_format(round($mem_tot/1024))."\n";<br />
print "</table><br>\n";<br />
<br />
// ------------------ Layout table cell (middle)--------------------------<br />
print "\n<td valign='top'>\n";<br />
<br />
// ----------------- View Selector -----------------------------------------<br />
print "<table class='BasicTable' align='left' valign='middle'>\n<tr><th width=200 colspan=2>View Selector\n";<br />
if ($clid) {<br />
print "<tr><td align='center' colspan=2><a href='$self?view=$view$hw_link'>For All Clusters</a>\n";<br />
} else {<br />
print "<tr><td align='center' colspan=2><b>&lt &lt</b> Filter On Cluster <b>&lt &lt</b>\n";<br />
}<br />
if ($view == "mobo") {<br />
print "<tr><th rowspan=3 width=40>Show:<td align='center'><b>Motherboard</b>\n";<br />
print "<tr><td align='center'><a href='$self?$cl_link$hw_link&view=nic'>Network Cards</a>\n";<br />
print "<tr><td align='center'><a href='$self?$cl_link$hw_link&view=hba'>Host Bus Adapters</a>\n";<br />
} elseif ($view == "nic") {<br />
print "<tr><th rowspan=3 width=40>Show:<td align='center'><a href='$self?$cl_link&view=mobo'>Motherboard\n";<br />
print "<tr><td align='center'><b>Network Cards</b>\n";<br />
print "<tr><td align='center'><a href='$self?$cl_link$hw_link&view=hba'>Host Bus Adapters</a>\n";<br />
} elseif ($view == "hba") {<br />
print "<tr><th rowspan=3 width=40>Show:<td align='center'><a href=$self?$cl_link&view=mobo>Motherboard\n";<br />
print "<tr><td align='center'><a href='$self?$cl_link$hw_link&view=nic'>Network Cards</a>\n";<br />
print "<tr><td align='center'><b>Host Bus Adapters</b>\n";<br />
} else {<br />
print "<tr>ERROR...!!!\n";<br />
}<br />
if ($hw) {<br />
print "<tr><td align='center' colspan=2><a href='$self?view=$view$cl_link'>For All Hardware</a>\n";<br />
} else {<br />
print "<tr><td align='center' colspan=2><b>&gt &gt</b> Filter On Hardware <b>&gt &gt</b>\n";<br />
}<br />
print "</table>";<br />
<br />
// ------------------ Layout table cell (right)--------------------------<br />
print "\n<td valign='top'>\n";<br />
<br />
//Server hardware summary query<br />
$query = "SELECT COUNT(esxid) AS esxs, model FROM esx JOIN vc USING (vcid) WHERE esx.exist=1 GROUP BY model ORDER BY model;";<br />
<br />
$result = mysql_query($query);<br />
//print $query;<br />
if (mysql_num_rows($result) == 0) {<br />
die ("No Servers found...!");<br />
}<br />
<br />
print "<table class='BasicTable' align='center'>\n<tr><th width=130>Server Model<th>ESXs\n";<br />
$esxs = 0;<br />
while ($row = mysql_fetch_assoc($result)) {<br />
print "<tr>";<br />
if ($hw === $row['model']) {<br />
print "<td><b>".$row['model']."</b>";<br />
} else {<br />
print "<td><a href='$self?clid=$clid&view=$view&hw=".$row['model']."'>".$row['model']."</a>";<br />
}<br />
print "<td class='num'>".$row['esxs'];<br />
$esxs += $row['esxs'];<br />
}<br />
print "<tr><td><td class='num'>".$esxs."\n";<br />
<br />
print "</table><br>\n";<br />
<br />
// ------------------ End Layout table cell --------------------------<br />
print "\n</table>\n";<br />
<br />
// Detail query<br />
<br />
if ($view == "mobo") {<br />
<br />
$query = "SELECT vc.name AS vc, cluster.name AS cluster, esx.name AS esx, esx.ver, esx.build, model, cpu_sock, cpu_core, mem, bios_ver FROM esx ";<br />
$query .= "JOIN vc USING (vcid) JOIN esx_ext USING (esxid) JOIN cluster USING (clid) WHERE esx.exist=1 ";<br />
if ($clid > 0) {<br />
$query .= "AND cluster.clid=$clid ";<br />
}<br />
if ($hw) {<br />
$query .= "AND esx.model='$hw' ";<br />
}<br />
$query .= "ORDER BY vc.vcid, cluster.name, esx.name;";<br />
<br />
if ($debug == 1) {print ($query);}<br />
$result = mysql_query($query);<br />
<br />
if (mysql_num_rows($result) == 0) {<br />
die ("None...!");<br />
}<br />
print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th>Cluster<th>ESX<th>Ver<th>Build<th>Model<th>CPU<br>Socks<th>CPU<br>Cores<th>Memory<br><small>GB</small><th>BIOS\n";<br />
<br />
$esxs = mysql_fetch_all($result, MYSQL_ASSOC);<br />
$odd_row = false;<br />
foreach ($esxs as $esx) {<br />
$odd_row = !$odd_row;<br />
if ($odd_row) {<br />
print "<tr class='odd'>";<br />
} else {<br />
print "<tr>";<br />
}<br />
print "<td>".$esx['vc']."<td>".$esx['cluster']."<td>".$esx['esx']."<td>".$esx['ver']."<td class='num'>".$esx['build']."<td class='num'>".$esx['model']."<td class='num'>".$esx['cpu_sock']."<td class='num'>".$esx['cpu_core']."<td class='num'>".round($esx['mem']/1024)."<td>".$esx['bios_ver']."\n";<br />
}<br />
print "</table><br>";<br />
<br />
} elseif ($view == "hba") {<br />
<br />
$query = "SELECT vc.name AS vc, cluster.name AS cluster, esx.name AS esx, esx.ver, esx.build, esx.model AS svr_model, esx_hba.model AS hba_model, driver, drv_ver FROM esx_hba ";<br />
$query .= "LEFT JOIN esx USING (esxid) JOIN vc USING (vcid) JOIN esx_ext USING (esxid) JOIN cluster USING (clid) WHERE esx.exist=1 ";<br />
if ($clid > 0) {<br />
$query .= "AND cluster.clid=$clid ";<br />
}<br />
if ($hw) {<br />
$query .= "AND esx.model='$hw' ";<br />
}<br />
<br />
$query .= "GROUP BY esx.esxid, drv_ver ORDER BY vc.vcid, cluster.name, esx.name, esx_hba.model;";<br />
<br />
if ($debug == 1) {print ($query);}<br />
$result = mysql_query($query);<br />
<br />
if (mysql_num_rows($result) == 0) {<br />
die ("None...!");<br />
}<br />
print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th>Cluster<th>ESX<th>Ver<th>Build<th>Model<th>HBA Model<th>HBA Type<th>HBA Driver\n";<br />
<br />
$esxs = mysql_fetch_all($result, MYSQL_ASSOC);<br />
$odd_row = false;<br />
$last_esx = false;<br />
foreach ($esxs as $esx) {<br />
if ($last_esx <> $esx['esx']) {<br />
$odd_row = !$odd_row;<br />
$last_esx = $esx['esx'];<br />
}<br />
if ($odd_row) {<br />
print "<tr class='odd'>";<br />
} else {<br />
print "<tr>";<br />
}<br />
print "<td>".$esx['vc']."<td>".$esx['cluster']."<td>".$esx['esx']."<td>".$esx['ver']."<td class='num'>".$esx['build']."<td>".$esx['svr_model']."<td>".$esx['hba_model']."<td>".$esx['driver']."<td>".$esx['drv_ver']."\n";<br />
}<br />
print "</table><br>";<br />
<br />
} elseif ($view == "nic") {<br />
<br />
$query = "SELECT vc.name AS vc, cluster.name AS cluster, esx.name AS esx, esx.ver, esx.build, esx.model AS svr_model, esx_nic.model AS nic_model, driver, drv_ver, fware FROM esx_nic ";<br />
$query .= "LEFT JOIN esx USING (esxid) JOIN vc USING (vcid) JOIN esx_ext USING (esxid) JOIN cluster USING (clid) WHERE esx.exist=1 ";<br />
if ($clid > 0) {<br />
$query .= "AND cluster.clid=$clid ";<br />
}<br />
if ($hw) {<br />
$query .= "AND esx.model='$hw' ";<br />
}<br />
$query .= "GROUP BY esx.esxid, drv_ver ORDER BY vc.vcid, cluster.name, esx.name, esx_nic.model;";<br />
<br />
if ($debug == 1) {print ($query);}<br />
$result = mysql_query($query);<br />
<br />
if (mysql_num_rows($result) == 0) {<br />
die ("None...!");<br />
}<br />
print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th>Cluster<th>ESX<th>Ver<th>Build<th>Model<th>NIC Model<th>NIC Type<th>NIC Driver<th>NIC Firmware\n";<br />
<br />
$esxs = mysql_fetch_all($result, MYSQL_ASSOC);<br />
$odd_row = false;<br />
$last_esx = false;<br />
foreach ($esxs as $esx) {<br />
if ($last_esx <> $esx['esx']) {<br />
$odd_row = !$odd_row;<br />
$last_esx = $esx['esx'];<br />
}<br />
if ($odd_row) {<br />
print "<tr class='odd'>";<br />
} else {<br />
print "<tr>";<br />
}<br />
print "<td>".$esx['vc']."<td>".$esx['cluster']."<td>".$esx['esx']."<td>".$esx['ver']."<td class='num'>".$esx['build']."<td>".$esx['svr_model']."<td>".$esx['nic_model']."<td>".$esx['driver']."<td>".$esx['drv_ver']."<td>".$esx['fware']."\n";<br />
}<br />
print "</table><br>";<br />
<br />
}<br />
<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";<br />
<br />
$time = round((microtime(true) - $time_start)*1000);<br />
print "Page took $time msecs to execute on server";<br />
<br />
// ------------------- End of HTML ---------------------------------<br />
print "</body><html>";<br />
<br />
// ================ FUNCTIONS ============================<br />
<br />
function search_char ($text) {<br />
<br />
return (str_replace(array("*", "?"), array("%", "_"), trim($text)));<br />
}<br />
<br />
function bar_graph ($data_percent, $warn_threshold, $alert_threshold) {<br />
print "<td class='bar' title='$data_percent'><div style='width: $data_percent%' ";<br />
if ($data_percent >= $alert_threshold) {<br />
print "class='bar_alert'";<br />
} elseif ($data_percent >= $warn_threshold) {<br />
print "class='bar_warn'";<br />
} else {<br />
print "class='bar_good'";<br />
}<br />
print ">".$data_percent."</div>\n";<br />
}<br />
<br />
<br />
function mysql_fetch_all($result) {<br />
while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {<br />
$return[] = $row;<br />
}<br />
return $return;<br />
}<br />
<br />
?><br />
<br />
<br />
<br />
<br />
</source></div>
Sstrutt