Networker

Re: [Networker] Things to do with Perl scripts in NW

2010-04-23 08:47:23
Subject: Re: [Networker] Things to do with Perl scripts in NW
From: Yaron Zabary <yaron AT ARISTO.TAU.AC DOT IL>
To: NETWORKER AT LISTSERV.TEMPLE DOT EDU
Date: Fri, 23 Apr 2010 15:44:07 +0300
Francis Swasey wrote:
On 4/23/10 1:58 AM, Yaron Zabary wrote:
  I have plenty of perl scripts that do things like billing, scripted
staging and cloning, fixing schedules, enable/disable of staging
policies as well as small reporting utilities that requires parsing of
mminfo's output.


  I have sent in the past some of them, but feel free to ask for them.

Yaron,
  I'd be interested in seeing some examples of billing scripts.

That is our billing script. It simply sums all savesets for each client. This data is then loaded into an Informix database which is used to charge our users.

#!/usr/bin/perl

open(MMINFO,"mminfo -a -xc, -q !ssrecycle -r 'client,nsavetime,fragsize(50),volume' |");

my $header = <MMINFO>;
while(<MMINFO>)
{
  chop;
  ($client,$stime,$size,$volume) = split(/,/);
  next if $volume =~ /.RO$/; # Ignore duplicate ssid on RO device
  $total{$client} += $size;
  $lastb{$client} = $stime if $lastb{$client} < $stime;
}

close(MMINFO);

chdir "/usr/home/backups/Thecat/Dailylogs/";

$f = outf();
open(OUT,">$f");
$now = t2str(time());

foreach $client (sort keys %total)
{
  print OUT $now,"|";
  ($c,$domain)=split(/\./,$client,2);
  $domain="tau.ac.il" unless $domain;
  print OUT $c,"|",$domain,"|";
  printf OUT ("%.2f|",$total{$client}/1024/1024);
  print OUT t2str($lastb{$client});
  print OUT "\n";
}

close(OUT);
sleep 3;

sub t2str

{
  my($t) = @_;
(my $sec,my $min,my $hour,my $mday,my $monx,my $year,my $wday,my $yday,my $isdst) = localtime($t);
  my $m = $monx + 1;
  my $y = $year + 1900;
  return $y."-".$m."-".$mday;
}

sub outf

{
(my $sec,my $min,my $hour,my $mday,my $monx,my $year,my $wday,my $yday,my $isdst) = localtime(time());
  my $m = $monx + 1;
  my $y = $year + 1900;
  return sprintf("Payday.%d-%02d-%02d.%02d-%02d",$y,$m,$mday,$hour,$min);
}



The following is not billing, but is used to report which savesets do not have a full in the last 35 days (which probably means that they missed their monthly full).

#!/usr/bin/perl


open(EXCLUDE,"</usr/local/TAUSRC/Local/dailyreport/excludelist");

while(<EXCLUDE>)
{
  chomp;
  push(@exclude,$_);
}

open(MMINFO,"mminfo -a -xc, -r client,name,nsavetime,level |");

$header = <MMINFO>;

while ($line = <MMINFO>)
{
  chop($line);
  ($client,$ssname,$time,$level) = split(/,/,$line);
  $ssname =~ s/\\//;
  $ss = $client.':'.$ssname;
  $count{$ss}++;
  $sstimeo{$ss} = max($sstimeo{$ss},$time);
  next unless $level eq 'full';
  $countf{$ss}++;
  $sstime{$ss} = max($sstime{$ss},$time);
}

$monthago = time() - 35*24*60*60;
foreach $ssx (sort keys %sstime)
{
  if ($sstime{$ssx} <= $monthago)
  {
#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($sstime{$ssx});
    @l = grep { $ssx =~ /$_/ } @exclude;
print "$ssx $countf{$ssx}/$count{$ss} ".datex($sstime{$ssx})." ".datex($sstimeo{$ssx})."\n" unless $#l >= 0;
  }
}

sub max

{
  my($a) = @_; shift;
  my($b) = @_;
  return $b if ($a == undef);
  return $a if ($b == undef);
  return ($a > $b)?$a:$b;
}

sub datex
{
  my($t) = @_;
  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t);
  my $y = 1900 + $year;
  my $m = $mon + 1;
  return $mday."/".$m."/".$y;
}


Thanks,


--

-- Yaron.

To sign off this list, send email to listserv AT listserv.temple DOT edu and type 
"signoff networker" in the body of the email. Please write to networker-request 
AT listserv.temple DOT edu if you have any problems with this list. You can access the 
archives at http://listserv.temple.edu/archives/networker.html or
via RSS at http://listserv.temple.edu/cgi-bin/wa?RSS&L=NETWORKER

<Prev in Thread] Current Thread [Next in Thread>