Veritas-bu

[Veritas-bu] Using Windows SMTP to send email notifications

2007-02-12 16:03:07
Subject: [Veritas-bu] Using Windows SMTP to send email notifications
From: pkoster at ci.grand-rapids.mi.us (Koster, Phil)
Date: Mon, 12 Feb 2007 16:03:07 -0500
Yep.  You can also use NOM.  All depends on what you want.  We have tons
of custom scripts and batch files for different things.  We had a perl
"guru" in here for a while.  He put together the below morning status
check (for a Win2K NBU 5.1 environment although still works with 6 MP4;
slightly altered to protect the innocent):
 
[code]

#!c:\perl\bin\perl.exe
#This is a comment
########################################################################
####
#  Author: Joseph Harnish
#  Date:
#  Description: Create reports of the backup solution to send the
administrator
########################################################################
####
#  ToDo
#    - Add sub report of 71s (data stored in @list_of_policy_changes)
#    - Store more information on number of hosts per policy to report
differences
#    - HTML based email reports
#    - Remove duplicates of reported systems.
########################################################################
#####
 
use strict;
use Getopt::Long;
use Net::SMTP;
use Time::localtime;
use Date::Calc qw(:all); 
 
#set this number to the line you want to see.
my $debug_line = 0;
 

my @emailaddress = ();
my $server_to_lookfor = '';
my $msglevel = '';
my $cellphone = '';
my $email_diff_only = '';
my $diff_file = "NB_job.dif";
my $diffclean = 0;
GetOptions ('server=s' =>\$server_to_lookfor, 'debug=i' => \$debug_line,
'help' => \&HelpMessage,
 'email=s' => \@emailaddress, 'level=i' => \$msglevel, 'cellphone' =>
\$cellphone,
 'diff' => \$email_diff_only, 'diffclean' => \$diffclean);
 
my $val = `d:\\progra~1\\veritas\\netbackup\\bin\\admincmd\\bpdbjobs
-all_columns`;
my @list_of_jobs = split(/\n/,$val);
 
open(OUTFILE, ">One_Job.txt") if($debug_line >0);
my $i = 0;
my $output = "";
my $out_of_window = "";
my $jobs_that_completed_successfully = 0;
my $successfull_backup_k = 0;
my $successfull_backup_files = 0;
my ($curr_year,$curr_mon,$mday, $curr_hour,$curr_min,$curr_sec) =
Today_and_Now();
#my ($curr_sec,$curr_min,$curr_hour,$mday,$curr_mon,$curr_year, @trash)
= ();
my @list_of_policy_changes = ();
my %already_reported_errors = ();
 
my @start_filter_date = ();
if($curr_hour >= 17){
 #filter tonights jobs
 @start_filter_date =($curr_year, $curr_mon, $mday, 15,00,00);
 print "I am in tonights backup window\n" if($debug_line > 0);
} else {
 #filter yesterdays jobs
 ($curr_year, $curr_mon, $mday) =
Add_Delta_YMD($curr_year,$curr_mon,$mday,0,0,'-1'); 
 @start_filter_date =($curr_year, $curr_mon, $mday, 15,00,00);
 print "I am looking at last nights backup window\n" if($debug_line >
0);
}
 
my $filter_time = Date_to_Time(@start_filter_date);
my $total_number_of_jobs;
foreach my $jobs (@list_of_jobs){
 my @job = split(/\,/, $jobs); 
 if($debug_line >0){
  $i++;
  next if($i < $debug_line);
  last if($i > $debug_line);
  my $j = 0;
  foreach my $joba (@job){
   print OUTFILE "$j => $joba\n" ;
   $j++;
  }
 }
 my $server_name = $job[6];
 next if ! ($server_name =~ m/$server_to_lookfor/);
 my $policy_type = $job[5];
 my $policy_name = $job[4];
 my $offset = $job[43];
 my $k_backuped = $job[43 + $offset + 1];
 my $number_of_files_backedup = $job[43 + $offset + 2];
 my $average_speed = $job[43 + $offset + 4];
 my $status = $job[3];
 my $job_id = $job[0];
 my $drive = $job[32];
 my $job_start_time = $job[8];
 #print "$filter_time > $job_start_time\n";
 #next;
 next if($filter_time > $job_start_time);
 my $job_end_time = $job[10];
 if($status > 1){
  if($status == 196){
   $out_of_window .= "$server_name 's $drive drive\n";
  } elsif ($status == 190) {
   # No more images for duplication
   #don't count against us it means it has moved everything to tape
   $total_number_of_jobs--;
  } elsif ($status == 150) {
   # Administratively cancelled 
   #don't count against us usually testing or restarted automatically
   $total_number_of_jobs--;
  } elsif ($status == 71) {
   # No files found
   #don't count against us usually means the directory is gone
   push(@list_of_policy_changes, "Policy: $policy_name, Server:
$server_name, Drive: $drive needs to be looked at and possibly
removed.\n");
   $total_number_of_jobs--;
  } else {
   # I need to track this and eliminate all duplicates caused by
requeuing.
   if(! defined($already_reported_errors{"$server_name - $drive"}) ||
($already_reported_errors{"$server_name - $drive"} == 0)){
    $output .= "$server_name - $drive - $status\n";
    $already_reported_errors{"$server_name - $drive"} = 1;
   } else {
    $total_number_of_jobs--;
   }
  }
 } else {
  $jobs_that_completed_successfully++;
  $successfull_backup_k += $k_backuped;
  $successfull_backup_files += $number_of_files_backedup;
 }
 #print "$job_id 's status is $status\n";
 $total_number_of_jobs++;
}
close OUTFILE if($debug_line >0);
 
#summary info
$val = `d:\\progra~1\\veritas\\netbackup\\bin\\admincmd\\bpdbjobs
-summary`;
my @summary_breakout = split(/\n/, $val);
my $ii = 0;
my $summary_output_sm = "";
my $summary_output_full = "";
foreach (@summary_breakout){
 $ii++;
 next if($ii < 2);
 my @summary_line = split(/\s+/, $_);
 my $master_server = $summary_line[0];
 my $queued = $summary_line[1];
 my $requeued = $summary_line[2];
 my $active = $summary_line[3];
 $summary_output_sm .= "MS:$master_server - Q:$queued - RQ:$requeued -
A:$active\n";
 $summary_output_full .= "Master Server: $master_server\nQueued:
$queued\nRequeued: $requeued\nActive: $active\n";
}
 
my $email_output = '';
$email_output .= "**Nightly Backup Status Report**\n";
$email_output .= $output;
if($msglevel > 0){
 $email_output .= "\n ****Out Of Window****\n";
 $email_output .= $out_of_window;
}
if($msglevel > 1){
 $email_output .= "\n ****All Jobs****\n";
 $email_output .= "Total jobs: $total_number_of_jobs\n";
 my ($success_rate, $junk) = split(/\./,
(($jobs_that_completed_successfully/$total_number_of_jobs) * 100));
 $email_output .= "Success Rate: $success_rate \%\n";
}
if($msglevel > 2){
 $email_output .= "\n ****Successful Backups****\n";
 $email_output .= "$jobs_that_completed_successfully jobs completed
successfully\n";
 $email_output .= "$successfull_backup_k k was backed up\n";
 $email_output .= "$successfull_backup_files files were backed up\n";
}
if($msglevel > 1){
 $email_output .= $summary_output_full;
} else {
 $email_output .= $summary_output_sm;
}
 
WriteDiffFile($diff_file, $email_output) if($diffclean);
 
if($email_diff_only){
 my $temp = DiffFile($diff_file, $email_output);
 WriteDiffFile($diff_file, $email_output);
 $email_output = $temp;
}
if($emailaddress[0] ne '' && $email_output ne ''){
 #email report
 #check for cellphone flag.  If so limit to 110 chars.
 if($cellphone){
  my @message = split(/\n/, $email_output); 
  my $temp_message = '';
  my $running_total = 0;
  foreach (@message){
   chomp;
   my @tmp_arr = split(//, $_);
   if($running_total + $#tmp_arr > 110){
    foreach my $emailaddr (@emailaddress){
     send_email($emailaddr, $temp_message);
    }
    $running_total = $#tmp_arr;
    $temp_message = "$_\n";
   } else {
    $running_total += $#tmp_arr;
    $temp_message .= "$_\n";
   }
  }
 } else {
  foreach my $emailaddr (@emailaddress){
   send_email($emailaddr, $email_output);
  }
 }
} else {
 print $email_output;
}
 
sub HelpMessage {
 print "Usage checkjobs.pl [--server=servername] [--help] \n[--debug=#]
[--email=user\@domain.com]\n";
 print "                   [--level=# (1 for Out Of Window, 3 for
Successful stats)]\n [--cellphone]";
 print "                   [--diff] [--diffclean]\n";
 exit;
}
 
sub send_email {
    print "Sending email\n";
    my $email_to = shift;
    my $output_mail = shift;
    
    my $smtp = Net::SMTP->new("your.e-mail.server.name.or.IP");
    $smtp->mail (backup_admins at yourdomain.com);
    $smtp->to ($email_to);
    $smtp->data();
    $smtp->datasend("To:  $email_to\n");
    $smtp->datasend("From:  backup_admins at yourdomain.com\n");
    $smtp->datasend("Subject: Nightly Backup Status report\n");
    $smtp->datasend("\n");
    $smtp->datasend($output_mail);
    $smtp->dataend();
    $smtp->quit;
}
 
sub WriteDiffFile{
 my $file_name = shift;
 my $data = shift;
 open(OUTFILE, ">$file_name");
 print OUTFILE $data;
 close OUTFILE;
}
 
sub DiffFile {
 my $file_name = shift;
 my $data = shift;
 open(INFILE, "<$file_name");
 my $file_data = "";
 while(<INFILE>){
  $file_data .= $_;
 }
 close INFILE;
 my @arr_old = split(/\n/, $file_data);
 my @arr_new = split(/\n/, $data);
 my $return_list = '';
 foreach (@arr_new){
  chomp;
  $return_list .= "$_\n" if(! IsInList($_, @arr_old));
 }
 return $return_list;
}
 

sub IsInList {
 my $element = shift;
 my @arr = @_;
 foreach (@arr){
  chomp;
  return 1 if($_ eq $element);
 }
 return 0;
}
 
[/code]
 
Phil Koster
Network Administrator
City of Grand Rapids, MI
Direct: 456-3136
Helpdesk: 456-3999

________________________________

From: Dave Brown [mailto:dbrown at worknetinc.com] 
Sent: Monday, February 12, 2007 3:52 PM
To: Koster, Phil; NB List Mail
Subject: RE: [Veritas-bu] Using Windows SMTP to send email notifications


Yes,  but that only states that the nbmail.cmd in bin directory may need
to be configured.  When looking at that script,  it only refers to using
BLAT.  No info on SMTP

________________________________

From: Koster, Phil [mailto:pkoster at ci.grand-rapids.mi.us] 
Sent: Monday, February 12, 2007 2:50 PM
To: Dave Brown; NB List Mail
Subject: RE: [Veritas-bu] Using Windows SMTP to send email notifications


Veritas/Syamtenc uses the technical term "e-mail" instead of SMTP.
Check your admin guide vol 1 pg 434.
 
Phil Koster
Network Administrator
City of Grand Rapids, MI
Direct: 456-3136
Helpdesk: 456-3999

________________________________

From: veritas-bu-bounces at mailman.eng.auburn.edu
[mailto:veritas-bu-bounces at mailman.eng.auburn.edu] On Behalf Of Dave
Brown
Sent: Monday, February 12, 2007 3:38 PM
To: NB List Mail
Subject: [Veritas-bu] Using Windows SMTP to send email notifications


NetBackup 6.0 MP4 on Windows 2003
 
Anyone have documentation or point me to the docs on how to set this up
?  Everything I see talks about using BLAT or some other 3rd party app,
but why install 3rd party when SMTP is there ?
 
Thanks
 
Dave Brown
Worknetinc
 
 
This message (including any attachments) is intended for the sole use of
the individual to whom it is addressed and may contain confidential
information. You are hereby notified that any dissemination,
distribution, or duplication of this message by someone other than the
intended addressee or their designated agent is strictly prohibited.
Information included in this message that does not relate to the
specified business of Worknet shall be understood as neither given by
nor endorsed by Worknet or its employees.  Any cost estimates or
estimated quotes included in this message are considered non-binding
estimates only and must not be considered final costs unless contained
within an official proposal document. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://mailman.eng.auburn.edu/pipermail/veritas-bu/attachments/20070212/4f7fe2ba/attachment.html