Commit 0be09a45 authored by bnachtw's avatar bnachtw
Browse files

Upload new file

parent 5cebacb8
#! /usr/bin/perl
##############################################################################
#
# tsm-dbstatus.pl
#
# script for getting status of TSM-DB for Monitoring-Website
# DB2 based TSM / ISP only
#
# (C) 2014 GWD Göttingen, Bjørn Nachtwey
# mailto:bjoern.nachtwey@gwdg.de
#
##############################################################################
#
# changelog
# date version remark
# 2014-08-12 0.9 initial coding
# 2017-03-09 0.9.5 removed parts for TSM5, moved constants to top of file
#
##############################################################################
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/databasestatus.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 tsm230 tsm231 tsm232 tsm233 tsm234 lm101 lm201/; # list of new servers
# # some settings for tabbed output
my $widewidth = 20;
my $midwidth = 15;
# # some threshold values
my $db_util_warn = 70;
my $db_util_crit = 95;
my $db_ext_warn = 10;
my $db_ext_crit = 5;
##############################################################################
##############################################################################
# E N D O F S E T T I N G S
##############################################################################
##############################################################################
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set some variables
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# # some loop iterators
my $server; # actual server name
# # some lists to be processed
my $dbstatus; # list of information on db
# # items from seletc statement
my $db_size; # db size in MB
my $db_util; # actual db_utilization in %
my $db_used;
my $db_free; # free space in db filesystem(s) in MB
my $db_free_p; # free space in db filesystem(s) in %
my $db_ext; # free max. extention in MB
my $db_ext_p; # free max. extention in %
my $date_last; # date of last backup completed
my $date_reorg; # date of last backup reorg completed
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 HTML file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
open STATFILE, ">" . $outputpath
or die "$0: cannot open output file: " . $outputpath;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# write body
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
printf STATFILE "<HTML>\n<HEAD>\n<TITLE>TSM Server State -- Database: %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 -- Database: %s</CENTER></FONT></P>\n", $date;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# write head of tabular
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
printf STATFILE "<p style=\"font-family:monospace\">\n";
printf STATFILE "<HR NOSHADE>\n";
printf STATFILE "<FONT COLOR=\"#000000\" FACE=\"monospace\" SIZE=\"4\">\n";
printf STATFILE "Servername" . "&nbsp;" x ($widewidth - length("Serverame") + 1);
printf STATFILE "current size (GB)" . "&nbsp;" x ($widewidth - length("current size (GB)") + 1);
printf STATFILE "utilized (GB)" . "&nbsp;" x ($midwidth - length("utilized (GB)") + 1);
printf STATFILE "free (%%)" . "&nbsp;" x ($widewidth - length("free (%%)") + 0);
printf STATFILE "Date of last ReOrg" . "&nbsp;" x ($widewidth - length("Date of last ReOrg") + 1);
printf STATFILE "Date of last Backup" . "&nbsp;" x ($widewidth - length("Date of last Backup") + 1);
printf STATFILE "<br>" . "\n";
printf STATFILE "</FONT></P>\n";
printf STATFILE "<HR NOSHADE>\n";
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# loop over all servers
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
foreach $server (@serverlist)
{
$selectstatement = "select TOT_FILE_SYSTEM_MB, USED_DB_SPACE_MB, date (LAST_BACKUP_DATE) as date, date (LAST_REORG) as reorg from db";
undef $dbstatus;
$command = "$dsmadmc $dsmargs -se=$server \"$selectstatement\" 2>/dev/null";
$dbstatus = `$command`;
if ( ( $dbstatus =~ m/ANR/ ) or ($dbstatus =~ m/ANS/) )
{
next;
}
($db_size, $db_used, $date_last, $date_reorg) = split ' ' , $dbstatus;
# skip spaces from output
$db_size =~ s/ //g;
$db_used =~ s/ //g;
# calculate db-extention in percent
$db_free_p = sprintf "%.1f", ( (1. - $db_used / $db_size ) * 100.0 );
# convert MB to GB
$db_size = sprintf "%.2f", ($db_size / 1024.);
$db_used = sprintf "%.2f", ($db_used / 1024.);
# set font color according to legend
# "#228b22"; # green
# "#FFBF00"; # orange
# "#ff0000"; # red
my $fontcolor = "#228b22";
if ( (100 - $db_free_p) < $db_util_warn)
{
$fontcolor="#228b22";
}
elsif ( (100 - $db_free_p) < $db_util_crit)
{
$fontcolor="#FFBF00";
}
# write stats for server to HTML file
printf STATFILE "<FONT COLOR=\"#000000\" FACE=\"monospace\" SIZE=\"4\">\n";
printf STATFILE $server . "&nbsp;" x ($widewidth - length ($server) ) . "\n";
printf STATFILE "</FONT>\n";
printf STATFILE "<FONT COLOR=\"". $fontcolor. "\" FACE=\"monospace\" SIZE=\"4\">\n";
printf STATFILE $db_size . "&nbsp;" x ($widewidth - length ($db_size) ) . "\n";
printf STATFILE $db_used . "&nbsp;" x ($midwidth - length ($db_used)) . "\n";
printf STATFILE $db_free_p . "&nbsp;" x ($widewidth - length ($db_free_p)) . "\n";
printf STATFILE "</FONT>\n";
printf STATFILE "<FONT COLOR=\"#000000\" FACE=\"monospace\" SIZE=\"4\">\n";
printf STATFILE $date_reorg . "&nbsp;" x ($widewidth - length ($date_reorg)) . "\n";
printf STATFILE $date_last . "&nbsp;" x ($widewidth - length ($date_last)) . "\n";
printf STATFILE "</FONT>\n";
printf STATFILE "<br>\n";
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# close HTML file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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