AFS-Monitor
view release on metacpan or search on metacpan
examples/xstat_cm_test view on Meta::CPAN
#!/usr/bin/perl -w
#
# Copyright © 2004 Alf Wachsmann <alfw@slac.stanford.edu> and
# Elizabeth Cassell <e_a_c@mailsnare.net>
#
# $Revision: 1.8 $ $Date: 2006/05/31 16:22:51 $ $Author: alfw $
#
use blib;
use strict;
use AFS::Monitor qw(xstat_cm_test constant);
use Data::Dumper;
my @cmname = ("virtue.openafs.org", "andrew.e.kth.se");
my @collID = (0, 1, 2);
my @tests; # choose which tests to run
$tests[1] = 1; # test of cmname @cmname and collIDs @collID
$tests[2] = 0; # test of cmname but no collID
$tests[3] = 0; # test of single cmname with collID
$tests[4] = 0; # test of single cmname but no single collID
my $all = 1;
my $showdump = 0; # print entire contents of hash for each test
my $formatted = 1; # print formatted like original xstat_cm_test program
print "# Starting now... #\n";
my $result;
if ($all || $tests[1]) {
print "\n******** TEST 1: ********\n";
print "\nxstat_cm_test -cmname ", join(" ", @cmname),
" -collID ", join(" ", @collID), "\n\n";
$result = xstat_cm_test(cmname => \@cmname,
collID => \@collID);
parse_result($result);
}
if ($all || $tests[2]) {
print "\n******** TEST 2: ********\n";
print "\nxstat_cm_test -cmname ", join(" ", @cmname), "\n\n";
$result = xstat_cm_test(cmname => \@cmname);
parse_result($result);
}
if ($all || $tests[3]) {
print "\n******** TEST 3: ********\n";
print "\nxstat_cm_test -cmname ", $cmname[0],
" -collID 2\n\n";
$result = xstat_cm_test(cmname => $cmname[0],
collID => 2);
parse_result($result);
}
if ($all || $tests[4]) {
print "\n******** TEST 4: ********\n";
print "\nxstat_cm_test -cmname ", $cmname[0], "\n\n";
$result = xstat_cm_test(cmname => $cmname[0]);
parse_result($result);
}
sub parse_result {
my $info = shift;
if ($AFS::CODE) {
print "Error case: ", ref($info), "\n" if (defined($info));
# die("Error: AFS::CODE = $AFS::CODE (", ($AFS::CODE+0), ")\n");
print "Error: AFS::CODE = $AFS::CODE (", ($AFS::CODE+0), ")\n";
return;
}
if ($showdump) {
local $Data::Dumper::Quotekeys = 0;
local $Data::Dumper::Sortkeys = 1;
local $Data::Dumper::Indent = 1;
local $Data::Dumper::Maxdepth = 2;
local $Data::Dumper::Varname = "xstat_cm_test";
print Dumper($info);
}
if ($formatted) {
foreach my $host (@$info) {
if ($host->{probeOK} == 0) {
printf("CM_Handler: Probe 1, collection %d to CM on '%s' failed\n",
$host->{collectionNumber},
$host->{hostName});
return;
}
if ($host->{collectionNumber} == constant("AFSCB_XSTATSCOLL_CALL_INFO")) {
PrintCallInfo($host);
} elsif ($host->{collectionNumber} == constant("AFSCB_XSTATSCOLL_PERF_INFO")) {
PrintPerfInfo($host);
} elsif ($host->{collectionNumber} == constant("AFSCB_XSTATSCOLL_FULL_PERF_INFO")) {
PrintFullPerfInfo($host);
} else {
printf "** Unknown collection: %d\n", $host->{collectionNumber};
}
}
}
}
sub PrintPerfInfo {
my $host = shift;
printf("AFSCB_XSTATSCOLL_PERF_INFO (coll %d) for CM %s\n[Probe 1, %s]\n\n",
$host->{collectionNumber},
$host->{hostName},
scalar localtime $host->{probeTime});
PrintOverallPerfInfo($host->{data});
}
sub PrintFullPerfInfo {
my $host = shift;
printf("AFSCB_XSTATSCOLL_FULL_PERF_INFO (coll %d) for CM %s\n[Probe 1, %s]\n\n",
$host->{collectionNumber},
$host->{hostName},
scalar localtime $host->{probeTime});
( run in 0.673 second using v1.01-cache-2.11-cpan-437f7b0c052 )