[Xymon] Netbackup client status script?

Galen Johnson Galen.Johnson at sas.com
Thu Oct 25 22:21:49 CEST 2012


Have you considered adding it to xymonton.org?

=G=

________________________________
From: xymon-bounces at xymon.com [xymon-bounces at xymon.com] on behalf of Nico [nicolas at lienard.name]
Sent: Thursday, October 25, 2012 2:40 PM
To: KING, KEVIN
Cc: xymon at xymon.com
Subject: Re: [Xymon] Netbackup client status script?

Hello

we got this one done recently but it is a bit ugly but it has been working fine.
you ll have to modify some variable like $bbdisp and maybe others.

it has to run on the netbackup server (ours is running on solaris).

let me know if you have questions.

cheers
Nico


#!/usr/bin/perl -w

#
# nlienard (with help of mward)
# 2012-08-01
# Retrieve netbackup status then publish it on hobbit
#

use Switch;
use strict;
use warnings;

# Fields output by the command are:

# 1 jobid               2 jobtype       3 state         4 status
# 5 class               6 schedule      7 client        8 server
# 9 started     10 elapsed      11 ended        12 stunit
# 13 try                14 operation    15 kbytes       16 files
# 17 pathlastwritten    18 percent      19 jobpid       20 owner
# 21 subtype    22 classtype    23 schedule_type        24 priority
# 25 group      26 masterserver 27 retentionunits       28 retentionperiod
# 29 compression        30 kbyteslastwritten    31 fileslastwritten     32 trystatus
# 33 trystatusdescription       34 parentjob    35 kbpersec     36 copy
# 37 robot      38 vault        39 profile      40 session
# 41 ejecttapes 42 srcstunit    43 srcserver    44 srcmedia
# 45 dstmedia   46 stream       47 suspendable  48 resumable
# 49 restartable        50 datamovement 51 snapshot     52 backupid
# 53 killable   54 controllinghost

# Hobbit variables
my $bb = "/opt/xymon/server/bin/xymon";
my $coltmon = "10.64.3.6";
my $test = "netbackup";

my( $jobid, $jobtype, $state, $status, $class, $schedule, $client, $server, $started, $ended, $kbytes);
my (%record, $rec);
my ($tmpfile, $self);

my $today = scalar localtime(time) ;
$today =~ s/\w+\s(\w+)\s+(\d+).*/$1  $2/;
my $yesterday = scalar localtime(time-86400) ;

$yesterday =~ s/\w+\s(\w+)\s+(\d+).*/$1  $2/;
my $yesterday2 = scalar localtime(time-172800) ;
$yesterday2 =~ s/\w+\s(\w+)\s(\d+).*/$1  $2/;

my $todayX = scalar localtime(time) ;
$todayX =~ s/\w+\s(\w+)\s+(\d+).*/$1 $2/;
my $yesterdayX = scalar localtime(time-86400) ;
$yesterdayX =~ s/\w+\s(\w+)\s+(\d+).*/$1 $2/;
my $yesterday2X = scalar localtime(time-172800) ;
$yesterday2X =~ s/\w+\s(\w+)\s(\d+).*/$1 $2/;


open(BPP, "/usr/openv/netbackup/bin/admincmd/bpdbjobs -all_columns 2>/dev/null |") || die "Cannot execute bpdbjobs command: $!";

while (<BPP>) {
        chomp;
        s/'/\'/g; # Escape any un-escaped single quotes.
        (
                $jobid,
                $jobtype,
                $state,
                $status,
                $class,
                $schedule,
                $client,
                $server,
                $started,
                undef,
                $ended,
                undef,
                undef,
                undef,
                $kbytes,
                undef
        ) = split(/,/);

        $record{$jobid}{jobid} = "$jobid";

        $record{$jobid}{jobtype} = "$jobtype";
        $record{$jobid}{state} = "$state";
        $record{$jobid}{status} = "$status";
        $record{$jobid}{class} = "$class";
        $record{$jobid}{schedule} = "$schedule";
        $record{$jobid}{client} = "$client";
        $record{$jobid}{server} = "$server";
        $record{$jobid}{started} = "$started";
        $record{$jobid}{ended} = "$ended";
        $record{$jobid}{kbytes} = "$kbytes";
}

close(BPP);

#
# %record now has all the data in it.
#


my @ignore = qw(ignore_host1 ignore_host2);

# Loop through the hash extracting entries
foreach $rec ( keys %record ) {
        # Set the hostname
        my $hostname = $record{$rec}{client};
        $hostname =~ s/(.*)\.oss.*/$1/;

        if (!($hostname)) {
                next;
        }

        if (grep { $_ eq $hostname } @ignore) {
        #if ( $hostname ~~ @ignore ) {
                next;
        }


        #print "checking " . scalar(localtime($record{$rec}{started})) . " with $yesterday and $today\n";
        #if ( (scalar(localtime($record{$rec}{started})) =~ /$yesterday/) || (scalar(localtime($record{$rec}{started})) =~ /$today/) ) {
        if ( (scalar(localtime($record{$rec}{started})) =~ /$yesterday/) || (scalar(localtime($record{$rec}{started})) =~ /$today/) || (scalar(localtime($record{$
rec}{started})) =~ /$yesterdayX/) || (scalar(localtime($record{$rec}{started})) =~ /$todayX/) ) {
                #if ($record{$rec}{class} =~ /Production/) {

                        # Set the color
                        my $color = "yellow";
                        my $state_color = "yellow";
                        my $msg = "&${color}This device is not correctly backuped";

                        my $state;
                        switch ( $record{$rec}{state} ) {
                                case 0 {  $state = "Queued";}
                                case 1 {  $state = "Active";}
                                case 2 {  $state = "Queued";}
                                case 3 {  $state = "Done";}
                                case 4 {  $state = "Suspended";}
                                case 5 {  $state = "Incomplete";}
                        }


                        # there are state and status.
                        # state is the general status
                        # status is the detail status

                        # state = 3 = Done = Green
                        if ( $record{$rec}{state} eq 3 ) {
                                $color = "green";
                                $state_color = "green";
                                $msg = "&${color}This device is correctly backuped";
                        }

                        # if state = 3 but status  != 0, then error => yellow
                        if ( $record{$rec}{status} ne 0 ) {
                                $color = "yellow";
                                $msg = "&${color}This device is backuped but with errors";
                        }



                        my $kbytes = "&yellow No data backuped";
                        if ($record{$rec}{kbytes}) {

                                $kbytes = "&green $record{$rec}{kbytes}";
                        }

                        my $ttl = "2d";
                        if ($record{$rec}{schedule} =~ /Weekly/ ) {
                                $ttl = "8d";
                        }


                        # build msg for hobbit
                        #my $line = "status+2d $hostname.$test $color";
                        my $line = "status+$ttl $hostname.$test $color";

                        $line .= "\n\t<H2>$msg</H2>\n";
                        $line .= "<table border=1>";
                        $line .= "<tr><th>State</th><td>&${state_color}" . $state . "</td></tr>";
                        $line .= "<tr><th>Status</th><td>&${color}" . $record{$rec}{status} . "</tr>";
                        $line .= "<tr><th>Jobid</th><td>" . $record{$rec}{jobid} . "</td></tr>";
                        $line .= "<tr><th>Class</th><td>" . $record{$rec}{class} . "</td></tr>";
                        $line .= "<tr><th>Schedule</th><td>" . $record{$rec}{schedule} . "</td></tr>";
                        $line .= "<tr><th>Client</th><td>" . $record{$rec}{client} . "</td></tr>";
                        $line .= "<tr><th>Server</th><td>" . $record{$rec}{server} . "</td></tr>";
                        $line .= "<tr><th>Started</th><td>" . scalar(localtime($record{$rec}{started})) . "</td></tr>";
                        $line .= "<tr><th>Ended</th><td>" . scalar(localtime($record{$rec}{started})) . "</td></tr>";
                        $line .= "<tr><th>kbytes</th><td>" . $kbytes . "</td></tr>";
                        $line .= "</table>";
                        $line .= "\nIf this check is purple, that means there is NO BACKUP anymore. Raise a ticket to BACKUP Team";

                        # debug
                        #print "\nPublishing status for $hostname to hobbit $bbdisp\n\n";



                        # publish status to hobbit central
                        #system "$bb $bbdisp \"$line\"";

                        # publish status to hobbit local
                        my $bbdisp  = `grep -i "$hostname " ~xymon/server/etc/hosts.d/LOCALDCS/* |cut -d/ -f9 |cut -d: -f1 | head -1`;
                        #print "debug1 bbdisp:[$bbdisp]\n";

                        chomp($bbdisp);
                        #print "debug2 bbdisp:[$bbdisp]\n";

                        if ($bbdisp) {
                                print "\nPublishing status for $hostname to hobbit $bbdisp";
                                #print "\n$bb $bbdisp \"$line\"";
                                #publish status to hobbit central
                                system "$bb $coltmon \"$line\"";
                                # publish status to hobbit local
                                system "$bb $bbdisp \"$line\"";
                        #} else {
                                #print "\nNOT Publishing status for $hostname to hobbit $bbdisp\n\n";
                        }

                        # debug
                        #print "jobid: ", $record{$rec}{jobid}, "\n";
                        #print "\tjobtype: ", $record{$rec}{jobtype}, "\n";
                        #print "\tstate: ", $record{$rec}{state}, "\n";
                        #print "\tstatus: ", $record{$rec}{status}, "\n";
                        #print "\tclass: ", $record{$rec}{class}, "\n";
                        #print "\tschedule: ", $record{$rec}{schedule}, "\n";
                        #print "\tclient: ", $record{$rec}{client}, "\n";
                        #print "\tstarted: ", scalar(localtime($record{$rec}{started})), "\n";
                        #print "\tended: ", scalar(localtime($record{$rec}{ended})), "\n";
                        #print "\tkbytes: ", $record{$rec}{kbytes}, "\n";
                }
        #}
}


Le 25 oct. 2012 à 20:01, KING, KEVIN a écrit :

Ages ago I wrote a package for netbackup on the Big Brother system. It tacked a bunch of stuff and told you when the backup tapes could recycled and such. But all our stuff was on Sun equipment. I think your Idea of loading the binaries on a nix box may be a good way. Let me see if I can find my work. It used to be on deadcat long time ago.

From: xymon-bounces at xymon.com<mailto:xymon-bounces at xymon.com> [mailto:xymon-bounces at xymon.com] On Behalf Of Ricardo Stella
Sent: Thursday, October 25, 2012 11:14 AM
To: xymon at xymon.com<mailto:xymon at xymon.com>
Subject: [Xymon] Netbackup client status script?


We are finally migrating out of Tivoli to Symantec's Netbackup.  We currently have a backup tab for each client which would report some stats - number of files, number of bytes, and status.

Looking at doing something similar, however, it seems that most of the status commands are only available to be run on the netbackup master or media servers.

I've found the following nagios script:  http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=2566&cf_id=24

But in order not to reinvent the wheel, does anyone have something similar?  Further, our master and media servers are running windows, which makes scripting a little more challenging.

If not, if I install the media server bits on a linux box (without registering it on the netbackup domain) would this be enough to query the DB and produce reports?  If so, perl or bash would do it.

Thanks in advance...
--
°((( = (( ===°°° ((( ================================================

_______________________________________________
Xymon mailing list
Xymon at xymon.com<mailto:Xymon at xymon.com>
http://lists.xymon.com/mailman/listinfo/xymon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20121025/082c0927/attachment.html>


More information about the Xymon mailing list