Skip to content

Instantly share code, notes, and snippets.

@sanmadjack
Created September 23, 2013 21:17
Show Gist options
  • Save sanmadjack/6677113 to your computer and use it in GitHub Desktop.
Save sanmadjack/6677113 to your computer and use it in GitHub Desktop.
PHP ZFS Info Display
<html>
<head>
<script type="text/javascript">
var filesystems=<?php
$filesystems = array();
$header_regex = "|^([A-Za-z0-9/]+)\s+([a-z]+)\s+([^\s]+)\s+([a-z-]+)$|";
$output = array();
//exec("sudo zpool status 2>&1",$output);
//exec("sudo zfs get 2>&1",$output);
exec("sudo zfs get all 2>&1",$output);
foreach($output as $line) {
$matches = array();
if(preg_match($header_regex,$line,$matches)) {
if(!array_key_exists($matches[1],$filesystems)){
$filesystems[$matches[1]] = array();
}
$filesystems[$matches[1]][$matches[2]] = $matches[3];
}
}
echo json_encode($filesystems);
?>;
var properties=<?php
$properties = array();
foreach($filesystems as $fs_kay=>$fs_value){
foreach($fs_value as $key=>$value) {
if(!in_array($key,$properties)) {
array_push($properties,$key);
}
}
}
echo json_encode($properties);
?>;
properties.sort();
var default_columns = new Array();
default_columns[0] = "mountpoint";
default_columns[1] = "recordsize";
default_columns[2] = "usedbydataset";
default_columns[3] = "compression";
default_columns[4] = "compressratio";
var table;
function display() {
var prop_list = document.getElementById("prop_list");
document.getElementById('content').innerHTML = "";
table = document.createElement("table");
var row = document.createElement("tr");
table.appendChild(row);
var td = document.createElement("td");
td.innerHTML = "name";
row.appendChild(td);
for(var prop in default_columns) {
td = document.createElement("th");
td.innerHTML = default_columns[prop];
row.appendChild(td);
}
for(var fs in filesystems) {
var row = document.createElement("tr");
table.appendChild(row);
var td = document.createElement("th");
td.innerHTML=fs;
row.appendChild(td);
for(var prop in default_columns) {
td = document.createElement("td");
var property = filesystems[fs];
switch(default_columns[prop]) {
default:
property = property[default_columns[prop]];
if(property!=null) {
td.innerHTML = property;
} else {
td.innerHTML = "-";
}
}
row.appendChild(td);
}
}
document.getElementById('content').appendChild(table);
}
function addprop() {
}
</script>
<style>
td, th {
border:solid black 1px;
}
</style>
</head>
<body onload="display()">
<select id="prop_list">
</select>
<input type="button" onclick="addprop()" />
<input type="button" onclick="display()" />
<div id="content">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment