Commit d401faad authored by bnachtw's avatar bnachtw
Browse files

file added

parent fb402d60
#! /usr/bin/perl
##############################################################################
#
# tsm-status-storagepool.pl
#
# script for getting status of storagepools for Monitoring-Website
#
#
# (C) 2014 - 2018 GWD Göttingen, Bjørn Nachtwey
# mailto:bjoern.nachtwey@gwdg.de
#
##############################################################################
#
# changelog
# date version remark
# 2014-08-12 0.9 initial coding
# 2014-09-12 0.9.1 script renamed, some fixes
# 2018-01-10 0.9.2 switched to common style, moved credentials arguments
#
##############################################################################
use warnings;
use strict;
use Time::Piece;
##############################################################################
##############################################################################
# F I L L I N Y O U R S E T T I N G S H E R E
##############################################################################
##############################################################################
##############################################################################
# C R E D E N T I A L S
##############################################################################
my $admuser = $ARGV[0]; # or replace by expicit ID
my $admpwd = $ARGV[1]; # or replace by expicit PW
##############################################################################
# O U T P U T S E T T I N G S
##############################################################################
my $outputpath = "/TSM/Monitoring/www/Serverstatus/storagepoolstatus.html";
##############################################################################
# F U R T H E R S E T T I N G S
##############################################################################
my @serverlist = qw /tsm110 tsm112 tsm113 tsm130 tsm131 tsm180 tsm182 tsm184 tsm230 tsm231 tsm232 tsm233 tsm234 lm101 lm201 lm202/; # list of new servers
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set some variables
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# some settings for tabbed output
my $widewidth = 20;
my $midwidth = 15;
my $smallwidth = 10;
# some threshold values
# my $stgp_empty_warn = 0.10;
# my $stgp_empty_crit = 0.05;
# some loop iterators
my $server; # actual server name
my $server_name; # second variable for actual server name
#my $oserver_name;
# some lists to be processed
my @stgpoolstatus; # list of information on stgpools
my @volumestatus; # list of information on volumes
# items from seletc statement
my $stgp_name; # actual stgpool name
my $stgp_size; # size of actual storagepool in TB
my $stgp_util; # actual stgpool's "usage"
my $stgp_mig; # actual stgpool's "migrateable"
my $stgp_totvol; # total number of volumes at actual storage pool
my $stgp_emptvol; # number of empty volumes at actual storage pool
my $stgp_pendvol; # number of pending volumes at actual storage pool
my $stgp_unavvol; # number of unavailabe volumes at actual storage pool
my $stgp_rovol; # number of read-only volumes at actual storage pool
my $stgp_maxscr; # max number of scratch volumes
my $stgp_scrused; # number of scratch volumes used
my $dsmadmc = "/usr/bin/dsmadmc "; # linux servers
my $dsmargs = " -tab -dataonly=yes -id=$admuser -pa=$admpwd -outfile";
my $date = localtime->strftime ('%a %b %d %H:%M:%S %Y %Z');
# new variables
my $command;
my $selectstatement;
open STATFILE, ">" . $outputpath or die "$0: cannot open output file: " . $outputpath;
printf STATFILE "<HTML>\n<HEAD>\n<TITLE>TSM Server State -- Storagepools: %s</TITLE>\n</HEAD>\n", $date;
printf STATFILE "<BODY BGCOLOR=\"#eeeee0\">\n";
printf STATFILE "<P><FONT COLOR=\"#000000\" FACE=\"monospace\" SIZE=\"5\"><CENTER>\n";
printf STATFILE "TSM Server State -- Storagepools: %s</CENTER></FONT></P>\n", $date;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# S T O R A G E P O O L S / V O L U M E S
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
printf STATFILE "<p style=\"font-family:monospace\">\n";
printf STATFILE "<HR NOSHADE>\n";
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# main loop over all servers
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
foreach $server (@serverlist)
{
printf STATFILE "<FONT COLOR=\"#000000\" FACE=\"monospace\" SIZE=\"4\">\n";
printf STATFILE "&nbsp" x (2 * $midwidth + 3 * $smallwidth + 8);
printf STATFILE " + - ". "- " x $smallwidth . "- - - - Volumes - - - -" . " -" x $smallwidth . " +";
printf STATFILE "<br>" . "\n";
printf STATFILE "Servername" . "&nbsp;" x ($midwidth - length("Serverame") + 0);
printf STATFILE "&nbsp;" x ($midwidth - length("Storagepool") + 0) . "Storagepool";
printf STATFILE "&nbsp;" x ($smallwidth - length("Size [TB]") + 1) . "Size [TB]";
printf STATFILE "&nbsp;" x ($smallwidth - length("util [%%]") + 2) . "util [%%]";
printf STATFILE "&nbsp;" x ($smallwidth - length("mig [%%]") + 2) . "mig [%%]";
printf STATFILE "&nbsp;" x ($smallwidth - length("total") + 1) . "total";
printf STATFILE "&nbsp;" x ($smallwidth - length("empty") + 0) . "empty";
printf STATFILE "&nbsp;" x ($smallwidth - length("pending") + 0) . "pending";
printf STATFILE "&nbsp;" x ($smallwidth - length("unav.") + 1) . "unav.";
printf STATFILE "&nbsp;" x ($smallwidth - length("readonly") + 1) . "readonly ";
printf STATFILE "&nbsp;" x ($smallwidth - length("maxscr") + 0) . "maxscr";
printf STATFILE "&nbsp;" x ($smallwidth - length("scr_used") + 1) . "scr_used";
printf STATFILE "\n";
printf STATFILE "<br>" . "\n";
printf STATFILE "</FONT></P>\n";
printf STATFILE "<HR NOSHADE>\n";
$server_name = $server;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# get list of stgpools
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
undef @stgpoolstatus;
$selectstatement = "select EST_CAPACITY_MB, stgpool_name, PCT_UTILIZED, PCT_MIGR, MAXSCRATCH, NUMSCRATCHUSED from stgpools order by stgpool_name";
$command = "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";
@stgpoolstatus = split '\n' , `$command`;
$server_name = $server;
foreach my $stgp_item (@stgpoolstatus)
{
if ( ( $stgp_item =~ m/^ANR/ ) or ($stgp_item =~ m/^ANS/) )
{
last
}
undef $stgp_name;
undef $stgp_util;
undef $stgp_mig;
undef $stgp_maxscr;
undef $stgp_scrused;
($stgp_size, $stgp_name, $stgp_util, $stgp_mig, $stgp_maxscr, $stgp_scrused) = split '\t' , $stgp_item;
$stgp_name =~ s/ //g;
if ( ( $stgp_name =~ m/^ANR/ ) or ($stgp_name =~ m/^ANS/) )
{
last
}
$stgp_util =~ s/ //g;
$stgp_mig =~ s/ //g;
$stgp_maxscr =~ s/ //g;
$stgp_scrused =~ s/ //g;
# get information about volumes
undef @volumestatus;
$selectstatement = "select access, count (volume_name) from volumes where ( STGPOOL_NAME = '$stgp_name') group by access";
$command = "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";
# reset values to zero
$stgp_totvol = 0;
$stgp_emptvol = 0;
$stgp_pendvol = 0;
$stgp_unavvol = 0;
$stgp_rovol = 0;
@volumestatus = split '\n' , `$command`;
foreach my $volstat (@volumestatus)
{
if ( ( $stgp_name =~ m/^ANR/ ) or ($stgp_name =~ m/^ANS/) )
{
last;
}
if ( $volstat =~ m/READONLY/ )
{
$stgp_rovol = $volstat;
$stgp_rovol =~ s/READONLY//;
$stgp_rovol =~ s/ //g;
}
if ( $volstat =~ m/UNAVAILABLE/ )
{
$stgp_unavvol = $volstat;
$stgp_unavvol =~ s/UNAVAILABLE//;
$stgp_unavvol =~ s/ //g;
}
if ( $volstat =~ m/READWRITE/ )
{
$stgp_totvol = $volstat;
$stgp_totvol =~ s/READWRITE//;
$stgp_totvol =~ s/ //g;
}
}
$stgp_totvol = $stgp_totvol + $stgp_rovol + $stgp_unavvol;
undef @volumestatus;
$selectstatement = "select count (volume_name) from volumes where ( STGPOOL_NAME = '$stgp_name' and STATUS = 'EMPTY')";
$command = "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";
$stgp_emptvol = `$command`;
$stgp_emptvol =~ s/ //g;
$selectstatement = "select count (volume_name) from volumes where ( STGPOOL_NAME = '$stgp_name' and STATUS = 'PENDING')";
$command = "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";
$stgp_pendvol = `$command`;
$stgp_pendvol =~ s/ //g;
# set font color according to legend
# "#228b22"; # green
# "#FFBF00"; # orange
# "#ff0000"; # red
# my $fc_e = "#FF0000";
my $fc_e = "#110000";
my $fc_u = "#228b22";
my $fc_r = "#228b22";
if ( $stgp_totvol > 0 )
{
if ( $stgp_unavvol > 0 )
{
$fc_u = "#FF0000";
}
if ( $stgp_rovol > 0 )
{
$fc_r = "#FF0000";
}
}
else
{
$fc_e = "#000000";
$fc_u = "#000000";
$fc_r = "#000000";
}
$stgp_size= sprintf "%.2f", ( $stgp_size / 1024. / 1024.);
$stgp_size= $stgp_size;
printf STATFILE "<FONT COLOR=\"#000000\" FACE=\"monospace\" SIZE=\"4\">\n";
if ( ( $stgp_name =~ m/^D/ ) or ($stgp_name =~ m/^F/) )
{
printf STATFILE "<strong>";
}
printf STATFILE $server_name . "&nbsp;" x ($midwidth - length ($server_name) ) . "\n";
printf STATFILE "&nbsp;" x ($midwidth - length ($stgp_name) ) . $stgp_name . "\n";
printf STATFILE "&nbsp;" x ($smallwidth - length ($stgp_size) ) . $stgp_size . "\n";
printf STATFILE "&nbsp;" x ($smallwidth - length ($stgp_util)) . $stgp_util . "\n";
printf STATFILE "&nbsp;" x ($smallwidth - length ($stgp_mig)) . $stgp_mig . "\n";
printf STATFILE "&nbsp;" x ($smallwidth - length ($stgp_totvol)) . $stgp_totvol . "\n";
printf STATFILE "&nbsp;" x ($smallwidth - length ($stgp_emptvol)) . $stgp_emptvol . "\n";
printf STATFILE "&nbsp;" x ($smallwidth - length ($stgp_pendvol)) . $stgp_pendvol . "\n";
printf STATFILE "</FONT>\n";
printf STATFILE "<FONT COLOR=\"" . $fc_u . "\" FACE=\"monospace\" SIZE=\"4\">";
printf STATFILE "&nbsp;" x ($smallwidth - length ($stgp_unavvol)) . $stgp_unavvol . "\n";
printf STATFILE "</FONT>\n";
printf STATFILE "<FONT COLOR=\"" . $fc_r . "\" FACE=\"monospace\" SIZE=\"4\">";
printf STATFILE "&nbsp;" x ($smallwidth - length ($stgp_rovol)) . $stgp_rovol . "\n";
printf STATFILE "</FONT>\n";
printf STATFILE "<FONT COLOR=\"#000000\" FACE=\"monospace\" SIZE=\"4\">\n";
printf STATFILE "&nbsp;" x ($smallwidth - length ($stgp_maxscr)) . $stgp_maxscr . "\n";
printf STATFILE "&nbsp;" x ($smallwidth - length ($stgp_scrused)) . $stgp_scrused . "\n";
if ( ( $stgp_name =~ m/^D/ ) or ($stgp_name =~ m/^F/) )
{
printf STATFILE "</strong>";
}
printf STATFILE "</FONT>\n";
printf STATFILE "<br>\n";
# substitute server_name by "." if not first fs
if ( $server eq $server_name )
{
$server_name = ".";
}
} # EO while (@stgpoolstatus)
printf STATFILE "<br>\n";
}
printf STATFILE "</P>\n</BODY>\n</HTML>\n";
close STATFILE;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment