$a $b Order $col >". $heading[$col-1] ."< " .$hwinfo[$a][$col-1]." <=> $col ".$hwinfo[$b][$col-1]."\n";
if( $col == 'name' ) {
if( $a != $b ) {
return(strcasecmp($a,$b));
}
} elseif ( $col == 'domain' ) {
#echo sprintf("
%s <=> %s\n",strstr($a,'.'),strstr($b,'.'));
$dom_a = implode(".",array_reverse(split("\.",$a)));
$dom_b = implode(".",array_reverse(split("\.",$b)));
#echo sprintf("
%s <=> %s\n",$dom_a,$dom_b);
return(strcasecmp($dom_a,$dom_b));
} elseif ( $col != "" && ( $heading[$col-1] == 'IP' || $heading[$col-1] == 'Kernel' || preg_match("/DRAC/", $heading[$col-1]) == 1 ) ) {
$col--;
#echo sprintf("
%s <=> %s\n",$hwinfo[$a][$col],$hwinfo[$b][$col]);
$ip_a = split("\.|-",$hwinfo[$a][$col]);
$ip_b = split("\.|-",$hwinfo[$b][$col]);
$ip_a[0] = preg_replace("/.*=/","",$ip_a[0]);
$ip_b[0] = preg_replace("/.*=/","",$ip_b[0]);
for( $i=0; $i<=3; $i++) {
#echo sprintf("
%d %s <=> %s = ",$i,$ip_a[$i] , $ip_b[$i]);
if( $ip_a[$i] < $ip_b[$i] ) {
#echo "-1\n";
return(-1);
} elseif( $ip_a[$i] > $ip_b[$i] ) {
#echo "1\n";
return(1);
}
#echo "0\n";
}
#echo sprintf("
%s <=> %s\n",$ip_a,$ip_b);
if( $hwinfo[$a][$col] != $hwinfo[$b][$col] ) {
return(strcasecmp($hwinfo[$a][$col],$hwinfo[$b][$col]));
}
} else {
if ( $col != "" ) {
$col--;
if( $hwinfo[$a][$col] != $hwinfo[$b][$col] ) {
if ( preg_match("/^[0-9]+[^0-9]*$/",$hwinfo[$a][$col]) && preg_match("/^[0-9]+[^0-9]*$/",$hwinfo[$b][$col] ) ) {
// Do numeric comparison if feasible
return( $hwinfo[$a][$col] - $hwinfo[$b][$col] );
} else {
return(strcasecmp($hwinfo[$a][$col],$hwinfo[$b][$col]));
}
}
}
}
}
# all other things being 'equal', sort by name
return(strcasecmp($a,$b));
}
usort($all_hosts,'sort_cmp');
#echo implode("\n
",$all_hosts) . "\n";
#sort($all_hosts);
#echo "sort $sort_order[0] $sort_order[1]\n";
#$http_query_string = HttpQueryString.new($global=true);
#$query()=$http_query_string.toArray();
#if( $_SERVER[QUERY_STRING] == "csv" ) {
#echo "csv = $_GET[csv]\n";
if ( array_key_exists('csv', $_GET) ) {
output_as_csv($all_hosts);
} elseif ( array_key_exists('dell', $_GET) ) {
output_as_dell_csv($all_hosts);
} else {
output_as_html($all_hosts);
}
function output_as_html($all_hosts)
{
global $wiki_page;
#global $hwinfo_dir;
global $hwinfo_str;
global $hwinfo_mtime;
global $heading;
global $hwinfo_split;
global $stale_if_older_seconds;
$format = array(
"n CPUs" => " ALIGN=CENTER",
"Vendor" => " NOWRAP",
"Model" => " NOWRAP",
"Service Tag" => " ALIGN=CENTER",
"Speed" => " NOWRAP ALIGN=RIGHT",
"L2 Cache" => " NOWRAP ALIGN=RIGHT",
"FSB" => " NOWRAP ALIGN=RIGHT",
"Total RAM" => " NOWRAP ALIGN=RIGHT",
"Installed Modules" => " NOWRAP",
"Memory Slots free" => " NOWRAP ALIGN=CENTER",
"Disk Sizes" => " NOWRAP",
"RAID Info" => " NOWRAP",
"arch" => " NOWRAP",
"Kernel" => " NOWRAP",
"Packages" => " NOWRAP",
"OS" => " NOWRAP",
"" => " NOWRAP",
);
?>
Host | Motherboard Info | CPU Info | Memory Info | Disk Info | Software | Remote Management | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Name . domain | $th\n"; $n++; } ?>|||||||||||||||||||
$host | \n"; for ( $i=0 ; $i < count($hwinfo); $i++ ) { if ( $hwinfo[$i] == "" ) { $hwinfo[$i] = " "; } if ( ! isset($format[$heading[$i]]) ) { $format[$heading[$i]] = ""; } if ( $heading[$i] == "DRAC/ILO" && preg_match("/not available/", $hwinfo[$i]) ) { $hwinfo[$i] = " "; } elseif ( $heading[$i] == "OS" ) { $hwinfo[$i] = preg_replace("/ *\([a-z0-9 ]*\) *$/i","",$hwinfo[$i],1); $hwinfo[$i] = preg_replace("/ release/i","",$hwinfo[$i],1); $hwinfo[$i] = preg_replace("/Red Hat Enterprise Linux( Server| ES)? */i","RHEL ",$hwinfo[$i],1); } elseif ( $heading[$i] == "Vendor" ) { $hwinfo[$i] = preg_replace("/ *Corporation/i","",$hwinfo[$i],1); } elseif ( $heading[$i] == "Installed Modules" || $heading[$i] == "Memory Slots free" ) { $n_slots = preg_match_all("@/@",$hwinfo[$i],$dummy) +1 ; $n_free = preg_match_all("@/0@",$hwinfo[$i],$dummy); $hwinfo[$i] = "$n_free of $n_slots"; } elseif ( $heading[$i] == "Disk Sizes" ) { // $hwinfo[$i] = preg_replace("/^(.{30}([^ /]{0,6})?).*/","\${1}...",$hwinfo[$i],1);; $hwinfo[$i] = preg_replace("/^(.{36})...*/","\${1}...",$hwinfo[$i],1);; } echo "" . $hwinfo[$i] ." | \n"; } if ( 0 == 1 ) { echo "||||||||||||||||||
$host | \n"; $hwinfo_str = exec("check_nrpe -H $host -t 120 -c check_hwinfo"); $hwinfo_str = preg_replace("@http:(//|\\\\\\\\)@i","",$hwinfo_str); // echo $hwinfo_str; $hw_types = preg_split ( "/[][]+/", $hwinfo_str); $mb_info = explode( ":", $hw_types[1]) ; for($i=0; $i<3; $i++ ) { if ( $mb_info[$i] == "" ) { $mb_info[$i] = " "; } echo "$mb_info[$i] | \n"; } $cpu_info = explode( ":", $hw_types[2]) ; for($i=0; $i<5; $i++ ) { if ( $cpu_info[$i] == "" ) { $cpu_info[$i] = " "; } if ( $i==0 ) { // ncpus $align="ALIGN=CENTER"; } elseif ( $i == 2 || $i == 3 || $i == 4) { // MHz, L2 Cache, FSB $align="ALIGN=RIGHT"; } else { $align=""; } echo "$cpu_info[$i] | \n"; } $mem_info = explode( ":", $hw_types[3]) ; for($i=0; $i<3; $i++ ) { if ( $mem_info[$i] == "" ) { $mem_info[$i] = " "; } if ( $i==0 || $i == 1 ) { // Total RAM, ECC $align="ALIGN=RIGHT"; } elseif ( $i == 2 ) { // installed modules $align=""; $mem_info[$i] = preg_replace("@/@"," - ",$mem_info[$i]); } else { $align=""; } echo "$mem_info[$i] | \n"; } $disk_info = explode( ":", $hw_types[4]) ; for($i=0; $i$hw_types[4] | \n"; $os_info = explode( ":", $hw_types[5]) ; for($i=0; $i
Last Updated: