Category: WIN32
Author/Contact Info Discipulus ** HATE THE WAR **
Description: This rude script aims to examine usage of remote disks. There is a %macchine (to modify) that contains machine_name =>qw/@characteristics/.
If logfiles are on a different disk or partition the script examine the two disks separately.
#!perl -w

use Win32::AdminMisc 981228||die;
use CGI qw /:standard -nph/;
use DBI;
use DBD::Chart;
my $dbh = DBI->connect('dbi:Chart:');
 $|++;
 $POST_MAX=100;
 $DISABLE_UPLOAD=1;

 
print header();
print start_html(-title=>'*du',-bgcolor=>"#000099",-text=>"#FF9933",-l
+ink=>"#FF3300",-alink=>"#FF3300",-vlink=>"#FF3300");

print small('data updated  '.localtime(time)).br;
#######################CONFIG HASH######################
my %macchine=(
            'host01'=>qw[name1 10.0.0.1 c undef c:/ao/log],
            'host02'=>qw[name2 10.0.0.2 e undef c:/ao/log],
            'host03'=>qw[name3 10.0.0.3 h undef c:/ao/log],
);
#######################################################
foreach my $mak(sort keys %macchine)
{
  my $drv= $macchine{$mak}[2];
  my $ip= $macchine{$mak}[1];
  my $host= $macchine{$mak}[0];
  my $ret = &du_pie_dsk($ip, $drv, $mak);
print b("$mak $drv".':');

if (-e "$mak$drv\.png")
  {
   print img {src=>"$mak$drv\.png"}
  }
  else {print i("Warning:  $mak image not found! $ret")}

my $base_log;
if ($macchine{$mak}[4]=~/^(\w):/i){$base_log = $1;}

if ($base_log ne $drv)
{ print  b("Log $base_log".':');
  my $ret = &du_pie_dsk($ip, $base_log, $mak);
  if (-e "$mak$base_log\.png")
  {
   print img {src=>"$mak$base_log\.png"}
  }
  else {print i("Warning:  $mak image not found! $ret")}
}
print br.hr;


}
sub du_pie_dsk{
 my $ip=shift;
 my $dsk=shift;
 my $host=shift;

 my $str='\\\\'.$ip.'\\'.$dsk.'$';
  my ($totale, $liberi);
  unless (($totale, $liberi)=Win32::AdminMisc::GetDriveSpace($str)){re
+turn "Errore Win32::AdminMisc::GetDriveSpace : $^E"}
  my $occupati=($totale-$liberi);
  
  my $tot=Arrotonda_Mega($totale);
  my $lib=Arrotonda_Mega($liberi);
  my $occ=Arrotonda_Mega($occupati);

$dbh->do("CREATE TABLE $host$dsk (region CHAR(20), sales INT)");
$sth = $dbh->prepare("INSERT INTO $host$dsk VALUES( ?, ?)");
$sth->execute("$lib free", $liberi);
$sth->execute("$occ used", $occupati);
    my $now = localtime (time);
$rsth = $dbh->prepare(
"SELECT PIECHART FROM $host$dsk
        WHERE WIDTH=400 AND HEIGHT=130 AND
        TITLE = \'$host\' AND
        COLOR=(lpurple, blue) AND
        SIGNATURE=\'$now auto perl\'
        AND     BACKGROUND=lgray");
$rsth->execute;
$rsth->bind_col(1, \$buf);
$rsth->fetch;
open(OUTF, ">$host$dsk\.png");
binmode OUTF;
print OUTF $buf;
close(OUTF);
}
sub Arrotonda_Mega{
my( $size, $n ) =( shift, 0 );
   ++$n and $size /= 1024 until $size < 1024;
    return sprintf "%.2f %s",
          $size, ( qw[ bytes Kb Mb Gb ] )[ $n ];
}
#
#       simple piechart
#