Monday, May 31, 2010

Script to Monitor ClearCase license

Here are the scripts mentioned in my previous post regarding monitoring ClearCase license usage.

re: Apperently I am not good at following up my previous posts -- Sorry for the delay.

The collection script is as simple as this.

date >> /home/ccadmin/logs/license.log
/opt/rational/clearcase/bin/clearlicensegrep "Current active users" >> /home/ccadmin/logs/license.log

The script is scheduled in cron jobs for every 10 mintues. This script can be easily converted to a Windows batch file and added to scheduler.

Then a perl script is used to load the data and generate the report in excel format. The script can be added as part of the Windows scheduler, or run at the time when you want to view the report. The nice chart in the previous post is also part of the excel report.

#Auther: Li Qin
#Date: 2008.02.05
#Function: generate ClearCase license usage report in excel format

use Spreadsheet::WriteExcel;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';

$Win32::OLE::Warn = 3; # die on errors...

$file = "C:\\Li\\SCM\\ClearCase\\report-licns.xls";
$workbook = Spreadsheet::WriteExcel->new("$file");
$sheet = $workbook->addworksheet("data");

my $format1 = $workbook->add_format();

my $format2 = $workbook->add_format();

my $format3 = $workbook->add_format();

$sheet->merge_range('C2:G2', "ClearCase Usage Report", $format1);

$sheet->set_column(3, 2, 40);
$sheet->set_column(3, 3, 20);
$sheet->set_column(3, 4, 20);
$sheet->write(3, 2, "Date", $format2 );
$sheet->write(3, 3, "Usage", $format2 );
$sheet->write(3, 4, "Max", $format2 );

open(FILE,"license.log")  || die "couldn't open file a.out";
$row = 4;
my @user1, @user2;
$max = 35;
while ($date= ) {
chomp $date;

$line1 = ;
chomp $line1;
while ( !($line1 =~ m/Current/) ) {
$user1[$row-4] = 0;

$sheet->write($row+1, 2, $date, $format3);
$sheet->write($row+1, 3, $user1[$row-4], $format3);
if ( $date =~ m/Fri Feb 1 17/ ) {
$max = 40;
$sheet->write($row+1, 4, $max, $format3);
$row = $row +1;
$date = $line1;
$line1 = ;
chomp $line1;
$pos = rindex $line1, ":";
$user1[$row-4] = substr($line1,$pos+1);

$sheet->write($row+1, 2, $date, $format3);
if ( $date =~ m/Fri Feb 1 17/ ) {
$max = 40;
$sheet->write($row+1, 3, $user1[$row-4], $format3);
$sheet->write($row+1, 4, $max, $format3);
$row = $row +1;

# #create chart
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');

# open Excel file
my $Book = $Excel->Workbooks->Open("$file");
# select worksheet of data

$count = 6;
my $sheet = $Book->Worksheets("data");
my $value = $sheet->Cells($count,4)->{'Value'};
my $len = length($value);

while ( $len >0 ) {
$count = $count +1;
my $value = $sheet->Cells($count,4)->{'Value'};
$len = length($value);
#printf "At ($count, 4) the value is %s. length is %d\n", $value, $len;
print "last row is $count.";

$lastRow = $count-1;
my $Range = $sheet->Range("C6:E$lastRow");

my $Chart2 = $Excel->Charts->Add($sheet);
$Chart2->{ChartType} = xlLine;
$Chart2->SetSourceData({Source => $Range, PlotBy => xlColumns});

$Chart2->{HasTitle} = 1;
$Chart2->ChartTitle->{Text} = "ClearCase License Usage\n";
$Chart2->Axes(xlValue)->{HasTitle} = 1;
$Chart2->Axes(xlValue)->AxisTitle->{Text} = "License Usage";
$Chart2->Axes(xlCategory)->{HasTitle} = 1;
$Chart2->Axes(xlCategory)->AxisTitle->{Text} = "Date/Time";

$Chart2->{HasLegend} = 'False';
$Chart2->{Name} = "Chart";
$Chart2->{HasLegend} = 1;
$Chart2->Legend->{Position} = xlBottom;
$Chart2->SeriesCollection(1)->{Name} = "Usage";
$Chart2->SeriesCollection(2)->{Name} = "Max";

# save and clean up
# End of create charts

We have upgraded our monitoring using SQL Server Reporting Service, a nice-to-have.


Anonymous said...

I advise to you.

Anonymous said...

whoah this blog is fantastic i love reading your articles.
Stay up the good work! You already know, a lot of individuals are hunting around for this info, you could aid them greatly.

Take a look at my web blog ... legal amphetamines

Anonymous said...

Apρreсiating the perѕistence yοu put into
youг blοg anԁ detailеd іnformatiоn уou providе.
It's good to come across a blog every once in a while that isn't the same unwantеd гehаshed informatіоn.
Excellеnt read! I've saved your site and I'm including уоur RSЅ feеds to my Google

Мy blοg: 50 state legal incense reviews

Anonymous said...

I loved as much as you'll receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get got an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case you shield this hike.

My page: cheap legal highs

Anonymous said...

I'm not sure exactly why but this website is loading extremely slow for me. Is anyone else having this problem or is it a issue on my end? I'll check back later and see if the problem still exists.

Here is my blog ... cheap legal highs

ninest123 said...

burberry, tory burch outlet, jordan shoes, sac longchamp, uggs on sale, ugg boots, louis vuitton, oakley sunglasses, michael kors, tiffany jewelry, cheap oakley sunglasses, ray ban sunglasses, christian louboutin outlet, ralph lauren pas cher, louboutin pas cher, ray ban sunglasses, air max, nike free, longchamp outlet, longchamp pas cher, ray ban sunglasses, tiffany and co, oakley sunglasses, polo ralph lauren outlet, louis vuitton, prada outlet, kate spade outlet, longchamp outlet, nike free, ugg boots, nike air max, gucci outlet, oakley sunglasses, louis vuitton outlet, longchamp, nike outlet, replica watches, louis vuitton, replica watches, prada handbags, chanel handbags, louboutin outlet, oakley sunglasses, nike roshe run, louis vuitton outlet, nike air max, louboutin shoes, louboutin, polo ralph lauren outlet, air jordan pas cher

ninest123 said...

true religion jeans, hollister pas cher, vans pas cher, tn pas cher, michael kors, true religion outlet, sac guess, nike free run uk, michael kors outlet, oakley pas cher, true religion jeans, replica handbags, ugg boots, burberry outlet online, mulberry, converse pas cher, michael kors outlet, ugg boots, true religion jeans, michael kors outlet, michael kors, nike air max, air force, hogan, new balance pas cher, vanessa bruno, ray ban uk, hollister, kate spade handbags, north face, nike air max, lululemon, coach outlet, burberry, michael kors, timberland, ray ban pas cher, michael kors outlet, coach purses, lacoste pas cher, hermes, nike air max, nike blazer, north face, ralph lauren uk, abercrombie and fitch, michael kors outlet, michael kors, nike roshe, coach outlet

ninest123 said...

converse outlet, giuseppe zanotti, hollister, insanity workout, herve leger, north face outlet, asics running shoes, nike air max, louboutin, converse, instyler, vans shoes, reebok shoes, iphone cases, abercrombie and fitch, mac cosmetics, wedding dresses, nike huarache, baseball bats, p90x workout, valentino shoes, chi flat iron, nike trainers, ghd, babyliss, oakley, soccer shoes, vans, timberland boots, gucci, celine handbags, nike air max, north face outlet, new balance, ralph lauren, hollister, jimmy choo shoes, mcm handbags, birkin bag, soccer jerseys, longchamp, beats by dre, bottega veneta, ferragamo shoes, nfl jerseys, lululemon, nike roshe, hollister, mont blanc, ray ban

ninest123 said...

moncler, lancel, canada goose, moncler outlet, canada goose, louis vuitton, juicy couture outlet, swarovski crystal, sac louis vuitton pas cher, louis vuitton, canada goose outlet, moncler, moncler, moncler, pandora charms, montre pas cher, canada goose uk, ugg,ugg australia,ugg italia, hollister, canada goose, ugg,uggs,uggs canada, bottes ugg, marc jacobs, doudoune canada goose, ugg boots uk, moncler, louis vuitton, moncler, pandora jewelry, thomas sabo, pandora charms, toms shoes, barbour, coach outlet, supra shoes, replica watches, links of london, barbour jackets, canada goose, juicy couture outlet, swarovski, pandora jewelry, canada goose outlet, louis vuitton, moncler, karen millen, wedding dresses, ugg pas cher