VI-DB snaps.php v2: Difference between revisions
Jump to navigation
Jump to search
(Initial creation) |
(Incorrect content - corrected) |
||
Line 7: | Line 7: | ||
<html> | <html> | ||
<head> | <head> | ||
<title>vi- | <title>vi-db (snaps)</title> | ||
<link rel='SHORTCUT ICON' href='favicon.ico'> | <link rel='SHORTCUT ICON' href='favicon.ico'> | ||
<link rel='stylesheet' type='text/css' href='alpha.css' /> | <link rel='stylesheet' type='text/css' href='alpha.css' /> | ||
Line 13: | Line 13: | ||
<meta name='Description' content='VI Info'> | <meta name='Description' content='VI Info'> | ||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" > | <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='Pragma' content='no-cache'> | ||
<meta http-equiv='Expires' content='900'> | <meta http-equiv='Expires' content='900'> | ||
</head> | </head> | ||
Line 24: | Line 24: | ||
//Local variables etc | //Local variables etc | ||
require 'config.php'; | require 'config.php'; | ||
$self = $_SERVER['PHP_SELF']; | |||
$debug = 0; | |||
// Import from config.php | |||
global $snap_size, $snap_age; | |||
// open connection and select database | // open connection and select database | ||
Line 29: | Line 34: | ||
mysql_select_db($db) or die ("Unable to select database!"); | mysql_select_db($db) or die ("Unable to select database!"); | ||
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"; | //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 "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>Active Snapshots</h1>\n"; | |||
if (array_key_exists('vcid', $_REQUEST)) { | |||
$vc_link = "&vcid=".$_REQUEST["vcid"]; | |||
$vcid=$_REQUEST["vcid"]; | |||
} else { | |||
$vc_link = ""; | |||
$vcid=0; | |||
} | |||
// Initial query | |||
$query = "SELECT vcid, vc.name AS vc, COUNT(sid) AS count, SUM(size) AS size FROM snap RIGHT JOIN vc USING (vcid) GROUP BY vc ORDER BY vc;"; | |||
print " | $result = mysql_query($query); | ||
//print $query; | |||
if (mysql_num_rows($result) == 0) { | |||
die ("No snapshots found...."); | |||
} | |||
$row = mysql_fetch_assoc($result); | |||
// ----------------- Layout table | // ----------------- Layout table (top) ---------------------------- | ||
print "<table align='center' cellspacing=10><tr>\n"; | print "<table align='center' cellspacing=10><tr><td valign='top'>\n"; | ||
// ------------ | // ------------------- Summary table ------------------------ | ||
$ | print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th>Snapshots<th>Total Usage<br><small>MB</size>\n"; | ||
$snap_tot = 0; | |||
while ($row = mysql_fetch_assoc($result)) { | |||
print "<tr><td><a href='$self?vcid=".$row['vcid']."'>".$row['vc']."<td class='num'>".$row['count']."<td class='num'>".number_format($row['size']); | |||
$snap_tot += $row['size']; | |||
} | |||
if (array_key_exists('vcid', $_REQUEST)) { | |||
print "<tr><td align='center' colspan=2><a href=$self>For All vCentres</a><td class='num'>".number_format($snap_tot)."\n"; | |||
} else { | |||
print "<tr><td align='center' colspan=2><b>↑ ↑</b> Filter On vCentre<td class='num'>".number_format($snap_tot)."\n"; | |||
} | |||
print "</table>\n"; | |||
// ------------------ Layout table cell (bottom)-------------------------- | |||
print "\n<tr><td valign='top'>\n"; | |||
// ----------------- Detail table --------------------------------------- | |||
$query = "SELECT vc.name AS vc, vm.name AS vm, vc_path, vmid, snap.name, descr, UNIX_TIMESTAMP(created) AS created, quiesced, vm_on, size "; | |||
$query .= "FROM snap JOIN vc USING (vcid) JOIN vm USING (vmid) JOIN vm_ext USING (vmid)"; | |||
if ($vcid > 0) { | |||
$query .= "WHERE vc.vcid=$vcid ORDER BY"; | |||
} else { | |||
$query .= "ORDER BY vc,"; | |||
} | } | ||
if (array_key_exists('sort', $_REQUEST)) { | |||
if ($_REQUEST["sort"] == 'folder') { | |||
$query .= " vc_path, vm, created;"; | |||
if ($ | } elseif ($_REQUEST["sort"] == 'vm') { | ||
$query .= " vm, created;"; | |||
$ | } elseif ($_REQUEST["sort"] == 'snap') { | ||
$query .= " snap.name, vm, created;"; | |||
} | } | ||
} else { | |||
$query .= " vm, created;"; | |||
} | |||
if ($debug == 1) {print ($query);} | |||
$result = mysql_query($query); | |||
//$date_old = date_sub(date_create(), date_interval_create_from_date_string('3 days')); | |||
$time_old = time() - ((24*60*60) * $snap_age); | |||
print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th><a href='$self?sort=vm$vc_link'>VM Name</a><th><a href='$self?sort=folder$vc_link'>Folder</a><th><a href='$self?sort=snap$vc_link'>Snapshot Name</a><th>Size<br><small>MB</size><th width=380>Description<th>Created<th>Create<br>Email\n"; | |||
while ($snap = mysql_fetch_assoc($result)) { | |||
if (($snap['size'] > $snap_size) or ($snap['created'] < $time_old)) { | |||
print "<tr class='warn'>"; | |||
if ( | |||
print "<tr | |||
} else { | } else { | ||
print "<tr | print "<tr>"; | ||
} | } | ||
print "</ | print "<td>".$snap['vc']."<td><a href='vm-detail.php?vmid=".$snap['vmid']."'>".$snap['vm']."</a><td>".$snap['vc_path']."<td>".$snap['name']."<td class='num'>".number_format($snap['size'])."<td>".$snap['descr']."<td>".date("d-m-y H:i", $snap['created']); | ||
print "<td><a href='mailto:someone@michaelpage.com?subject=".$snap['vm']." snapshot...&body=Can the following snapshot for the above server be deleted?%0A"; | |||
print "%0AName:%09%09".$snap['name']."%0ADescrip.:%09".$snap['descr']."%0ACreated:%09".date("d-m-Y H:i", $snap['created'])."%0ASize:%09%09".number_format($snap['size'])." MB'>Mail</a>\n"; | |||
} | } | ||
print "</table>\n"; | print "</table>\n"; | ||
// ------------------- Layout table end ------------------------------ | // ------------------- Layout table end ------------------------------ | ||
print "</table>\n"; | print "</table>\n"; | ||
print "<br><a href='index.php'> | print "<br><a href='index.php'>Search page</a>   <a href='status.php'>Status page</a><br>\n"; | ||
$time = round((microtime(true) - $time_start)*1000); | $time = round((microtime(true) - $time_start)*1000); | ||
Line 111: | Line 137: | ||
// ------------------- End of HTML --------------------------------- | // ------------------- End of HTML --------------------------------- | ||
print "</body><html>"; | print "</body><html>"; | ||
Line 121: | Line 145: | ||
return (str_replace(array("*", "?"), array("%", "_"), trim($text))); | return (str_replace(array("*", "?"), array("%", "_"), trim($text))); | ||
} | } | ||
?> | ?> | ||
Latest revision as of 10:15, 19 December 2011
<html xmlns='http://www.w3.org/TR/REC-html40'>
<!--Version 2.0 -->
<html>
<head>
<title>vi-db (snaps)</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'];
$debug = 0;
// Import from config.php
global $snap_size, $snap_age;
// 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>Active Snapshots</h1>\n";
if (array_key_exists('vcid', $_REQUEST)) {
$vc_link = "&vcid=".$_REQUEST["vcid"];
$vcid=$_REQUEST["vcid"];
} else {
$vc_link = "";
$vcid=0;
}
// Initial query
$query = "SELECT vcid, vc.name AS vc, COUNT(sid) AS count, SUM(size) AS size FROM snap RIGHT JOIN vc USING (vcid) GROUP BY vc ORDER BY vc;";
$result = mysql_query($query);
//print $query;
if (mysql_num_rows($result) == 0) {
die ("No snapshots found....");
}
$row = mysql_fetch_assoc($result);
// ----------------- Layout table (top) ----------------------------
print "<table align='center' cellspacing=10><tr><td valign='top'>\n";
// ------------------- Summary table ------------------------
print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th>Snapshots<th>Total Usage<br><small>MB</size>\n";
$snap_tot = 0;
while ($row = mysql_fetch_assoc($result)) {
print "<tr><td><a href='$self?vcid=".$row['vcid']."'>".$row['vc']."<td class='num'>".$row['count']."<td class='num'>".number_format($row['size']);
$snap_tot += $row['size'];
}
if (array_key_exists('vcid', $_REQUEST)) {
print "<tr><td align='center' colspan=2><a href=$self>For All vCentres</a><td class='num'>".number_format($snap_tot)."\n";
} else {
print "<tr><td align='center' colspan=2><b>↑ ↑</b> Filter On vCentre<td class='num'>".number_format($snap_tot)."\n";
}
print "</table>\n";
// ------------------ Layout table cell (bottom)--------------------------
print "\n<tr><td valign='top'>\n";
// ----------------- Detail table ---------------------------------------
$query = "SELECT vc.name AS vc, vm.name AS vm, vc_path, vmid, snap.name, descr, UNIX_TIMESTAMP(created) AS created, quiesced, vm_on, size ";
$query .= "FROM snap JOIN vc USING (vcid) JOIN vm USING (vmid) JOIN vm_ext USING (vmid)";
if ($vcid > 0) {
$query .= "WHERE vc.vcid=$vcid ORDER BY";
} else {
$query .= "ORDER BY vc,";
}
if (array_key_exists('sort', $_REQUEST)) {
if ($_REQUEST["sort"] == 'folder') {
$query .= " vc_path, vm, created;";
} elseif ($_REQUEST["sort"] == 'vm') {
$query .= " vm, created;";
} elseif ($_REQUEST["sort"] == 'snap') {
$query .= " snap.name, vm, created;";
}
} else {
$query .= " vm, created;";
}
if ($debug == 1) {print ($query);}
$result = mysql_query($query);
//$date_old = date_sub(date_create(), date_interval_create_from_date_string('3 days'));
$time_old = time() - ((24*60*60) * $snap_age);
print "<table class='BasicTable' align='center'>\n<tr><th>vCentre<th><a href='$self?sort=vm$vc_link'>VM Name</a><th><a href='$self?sort=folder$vc_link'>Folder</a><th><a href='$self?sort=snap$vc_link'>Snapshot Name</a><th>Size<br><small>MB</size><th width=380>Description<th>Created<th>Create<br>Email\n";
while ($snap = mysql_fetch_assoc($result)) {
if (($snap['size'] > $snap_size) or ($snap['created'] < $time_old)) {
print "<tr class='warn'>";
} else {
print "<tr>";
}
print "<td>".$snap['vc']."<td><a href='vm-detail.php?vmid=".$snap['vmid']."'>".$snap['vm']."</a><td>".$snap['vc_path']."<td>".$snap['name']."<td class='num'>".number_format($snap['size'])."<td>".$snap['descr']."<td>".date("d-m-y H:i", $snap['created']);
print "<td><a href='mailto:someone@michaelpage.com?subject=".$snap['vm']." snapshot...&body=Can the following snapshot for the above server be deleted?%0A";
print "%0AName:%09%09".$snap['name']."%0ADescrip.:%09".$snap['descr']."%0ACreated:%09".date("d-m-Y H:i", $snap['created'])."%0ASize:%09%09".number_format($snap['size'])." MB'>Mail</a>\n";
}
print "</table>\n";
// ------------------- Layout table end ------------------------------
print "</table>\n";
print "<br><a href='index.php'>Search page</a>   <a href='status.php'>Status 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 ============================
function search_char ($text) {
return (str_replace(array("*", "?"), array("%", "_"), trim($text)));
}
?>