Sunday 23 February 2014

COD script

 How to use this script?

server1:/tmp # ./codnew.pl
usage: ./codnew.pl MODEL XX XXXXX e.g ./codnew.pl 9119 83 9f6bf

(Eg)
server1:/tmp # ./codnew.pl 9119 02 1CBB4
04 processors activated on 12/06/2011
064 GB memory activated on 12/06/2011
080 GB memory activated on 10/24/2011
020 GB memory activated on 09/09/2011
999 GB memory activated on 08/16/2011
06 processors activated on 03/07/2011
128 GB memory activated on 11/30/2010
02 processors activated on 01/05/2010
016 GB memory activated on 11/18/2009
28 processors activated on 02/05/2009
400 GB memory activated on 02/05/2009

 =============================================

#!/usr/bin/perl
#
# PoC Script to go out on the net to the IBM POD site and tally up activations for a given i or p Series machine


#
# todo - add logic for processor deactivation - who uses that? IBM dont even publish the code on the pod site ;)
#
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("mozilla 8.0");
# $ua->proxy(['http'], 'http://proxy:8080/');
$ua->timeout(10);
use HTTP::Request::Common qw(POST);
if ($#ARGV != 2) {
print "usage: $0 MODEL XX XXXXX e.g $0 9119 83 9f6bf\n";
exit;
}
($model, $serial1, $serial2) = @ARGV;

##### main #####
get('http://www-912.ibm.com/pod/pod',"$serial2.htm");
html2txt("$serial2.htm","$serial2.txt");
total("$serial2.txt");
exit;

# fakes a mozilla browser, fills in the CGI form and snags the returned page to a local html file
sub get {
   my $req = (POST $_[0],
      ["system_type" => $model,
      "system_serial_number1" => $serial1,
      "system_serial_number2" => $serial2 ]);

   $request = $ua->request($req);
   $activations = $request->content;
   open(POD,">$_[1]");
   print POD $activations;
   close(POD);
}

# strips out the crap and converts the table to a local txt file to parse
sub html2txt {
   open(HTML,"<$_[0]");
   open(TXT,">$_[1]");
   while (<HTML>) {
      if (/<\/table>/) {$f = 0;};
      if (/<th>Posted Date \(MM/) {$f = 1;};
      if ($f == 1) {
      # poor mans HTML::TableExtract - excuse my sed like perl....
         s/<tr align="center">/:/g;
         s/<[^>][^>]*>//g;
         s/ //g;
         s/\n//g;
         s/:/\n/g;
         s/\&nbsp\;/ /g; #Added DW
         print TXT $_;
      };
   };
   close(TXT);
   close(HTML);
}
# totals up the de/activations to get totals
sub total {
   open(TXT,"<$_[0]");
   $[ = 1; $\ = "\n";# set array base & output record separator
   while (<TXT>) {
      ($code,$hex,$date) = split(' ', $_, -1);
      if (/POD/) {
         $p = substr($hex, 27, 2);
         print $p . ' processors activated on ' . $date;
         $pt = $pt + $p;
      };

      if (/MOD/) {
         $r = substr($hex, 26, 3);
         print $r . ' GB memory activated on ' . $date;
         $rt = $rt + $r;
      };

      if (/RMEM/) {
         $r = substr($hex, 27, 2);
         print $r . ' GB memory activated on ' . $date;
         $rt = $rt - $r;
      };
   };

   print '================';
   print 'TOTAL CPU=' . $pt . ' RAM=' . $rt*1024 . 'MB (' . $rt . 'GB)';
   close(TXT);
}





======================================================


3 comments:

  1. Hi! this does not work on perl 5 - can you fix it?

    ReplyDelete
    Replies
    1. http://gibsonnet.net/blog/cgaix/html/How%20much%20memory%20or%20CPU%20will%20that%20CoD%20code%20activate%20anyway.html

      Delete
  2. This comment has been removed by the author.

    ReplyDelete