Commit f35301f9 authored by bnachtw's avatar bnachtw
Browse files

added

parent 0be09a45
#! /usr/bin/perl
##############################################################################
#
# tsm-status-drives-paths.pl
#
# script for gathering some Libman's drives and paths
#
#
# (C) 2017 GWD Göttingen, Bjørn Nachtwey
# mailto:bjoern.nachtwey@gwdg.de
#
##############################################################################
#
# changelog
# date version remark
# 2017-05-15 0.9 initial coding
#
##############################################################################
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/www/Monitoring/drives_paths.html"; # output path
##############################################################################
# F U R T H E R S E T T I N G S
##############################################################################
my @serverlist = qw /lm101 lm201/; # list of servers
# some settings for tabbed output
my $widewidth = 25;
my $midwidth = 20;
my $smallwidth = 15;
my $fontcolor = "000000"; # default is black
# some threshold values [%]
my $drives_warn = 70;
my $drives_crit = 50;
my $paths_warn = 70;
my $paths_crit = 50;
##############################################################################
##############################################################################
# E N D O F S E T T I N G S
##############################################################################
##############################################################################
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set some variables
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# # some loop iterators
my $server; # actual server name
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set some variables
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
my $drives_onl; # number of drives beeing online
my $drives_off; # number of drives beeing offline
my $drives_nn; # number of drives beeing neither on- nor offline
my $drives_on_perc; # share of drives beein online in %
my $drivestatus; # return value of select command
my $paths_onl; # number of paths beeing online
my $paths_off; # number of paths beeing offline
my $paths_on_perc; # share of paths beein online in %
my $pathstatus; # return value of select command
my $dsmadmc = "/usr/bin/dsmadmc "; # linux servers
my $dsmargs = " -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>ISP Library Manager D R I V E S and P A T H S State: %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 "ISP Library Manager D R I V E S and P A T H S State: %s</CENTER></FONT></P>\n", $date;
printf STATFILE "<HR NOSHADE>\n";
printf STATFILE "<style>\n";
printf STATFILE "\t table, th,td {\n";
printf STATFILE "\t border: 1px solid black;\n";
printf STATFILE "\t border-collapse: collapse;\n";
printf STATFILE "\t padding: 0.2em 0.5em;\n";
printf STATFILE "\t }\n";
printf STATFILE "\t th,td{ text-align: center;\n";
printf STATFILE "\t font-size: 20px;\n";
printf STATFILE "\t font-family:monospace}\n";
printf STATFILE "</style>\n";
printf STATFILE "\n";
printf STATFILE "<table>\n";
printf STATFILE "<tr>\n";
printf STATFILE "\t<th>Server</th>\n";
printf STATFILE "\t<th># Drives online</th>\n";
printf STATFILE "\t<th># Drives offline</th>\n";
printf STATFILE "\t<th> <p style=\"color:#FF0000\"># Drives n/n</p></th>\n";
printf STATFILE "\t<th># Drives online \[%%\]</th>\n";
printf STATFILE "\t<th> </th>\n";
printf STATFILE "\t<th># Paths online</th>\n";
printf STATFILE "\t<th># Paths offline</th>\n";
printf STATFILE "\t<th># Paths online \[%%\]</th>\n";
printf STATFILE "</tr>\n";
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# main loop over all servers
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
foreach $server (@serverlist)
{
printf STATFILE "<tr>\n";
printf STATFILE "\t<td> <p style=\"color:#00000\"> $server </p> </td>\n";
# get drives online
$selectstatement="select count(*) from drives where online='YES'";
$command = "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";
$drives_onl = `$command`;
if ( ( $drives_onl =~ m/ANR/ ) or ($drives_onl =~ m/ANS/) )
{
next;
}
$drives_onl =~ s/ //g;
# get drives offline
$selectstatement="select count(*) from drives where online='NO'";
$command = "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";
$drives_off = `$command`;
if ( ( $drives_off =~ m/ANR/ ) or ($drives_off =~ m/ANS/) )
{
next;
}
$drives_off =~ s/ //g;
# get drives neither nor
$selectstatement="select count(*) from drives where not ( online='NO' or online='YES')";
$command = "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";
$drives_nn = `$command`;
if ( ( $drives_nn =~ m/ANR/ ) or ($drives_nn =~ m/ANS/) )
{
next;
}
$drives_nn =~ s/ //g;
# get path online
$selectstatement="select count(*) from paths where online='YES'";
$command = "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";
$paths_onl = `$command`;
if ( ( $paths_onl =~ m/ANR/ ) or ($paths_onl =~ m/ANS/) )
{
next;
}
$paths_onl =~ s/ //g;
# get drives offline
$selectstatement="select count(*) from paths where online='NO'";
$command = "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";
$paths_off = `$command`;
if ( ( $paths_off =~ m/ANR/ ) or ($paths_off =~ m/ANS/) )
{
next;
}
$paths_off =~ s/ //g;
$drives_on_perc = $drives_onl / ($drives_onl + $drives_off + $drives_nn) * 100.;
if ( $drives_on_perc < $drives_crit )
{
$fontcolor = "#FF0000";
}
elsif( $drives_on_perc < $drives_warn )
{
$fontcolor = "#FFBF00";
}
else
{
$fontcolor = "#00000";
}
printf STATFILE "\t<td> <p style=\"color:$fontcolor\"> $drives_onl </p> </td>\n";
printf STATFILE "\t<td> <p style=\"color:$fontcolor\"> $drives_off </p> </td>\n";
printf STATFILE "\t<td> <p style=\"color:$fontcolor\"> $drives_nn </p> </td>\n";
printf STATFILE "\t<td> <p style=\"color:$fontcolor\"> %5.2f </p> </td>\n", $drives_on_perc;
printf STATFILE "\t<td> <p style=\"color:$fontcolor\"> </p> </td>\n";
# get paths
$paths_on_perc = $paths_onl / ($paths_onl + $paths_off) * 100.;
if ( $paths_on_perc < $paths_crit )
{
$fontcolor = "#FF0000"; # red
}
elsif( $paths_on_perc < $paths_warn )
{
$fontcolor = "#FFBF00"; # orange
}
else
{
$fontcolor = "#00000"; # black
}
printf STATFILE "\t<td> <p style=\"color:$fontcolor\"> $paths_onl </p> </td>\n";
printf STATFILE "\t<td> <p style=\"color:$fontcolor\"> $paths_off </p> </td>\n";
printf STATFILE "\t<td> <p style=\"color:$fontcolor\"> %5.2f </p> </td>\n", $paths_on_perc;
printf STATFILE "</tr>\n";
}
printf STATFILE "</table>\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