purple server side test?

michael nemeth michael.nemeth at lmco.com
Mon May 5 17:55:20 CEST 2008


Below is a server script I adapted for showing a back-up (save prosses)  
is running.
I have a trigger set up for the proc (yellow if the save string  is in 
the ps)column that works, but I wanted separate column.
Sometimes I get purples with below script when backups are running and
confirmed by the proc column  but mostly it works,

How can I be getting purples?

 
#!/usr/bin/perl

#*----------------------------------------------------------------------------*/
#* Hobbit client message 
processor.                                           */
#*                                                                            
*/
#* This perl program shows how to create a server-side module using 
the       */
#* data sent by the Hobbit clients. This program is fed data from 
the         */
#* Hobbit "client" channel via the hobbitd_channel program; each 
client       */
#* message is processed by looking at the [who] section and 
generates         */
#* a "login" status that goes red when an active "root" login is 
found.       */
#*                                                                            
*/
#* Written 2007-Jan-28 by Henrik Storner 
<henrik at hswn.dk>                     */
#*                                                                            
*/
#* This program is in the public domain, and may be used freely 
for           */
#* creating your own Hobbit server-side 
modules.                              */
#*                                                                            
*/
#*----------------------------------------------------------------------------*/

# $Id: rootlogin.pl,v 1.1 2007/01/28 12:42:34 henrik Exp $


my $bb;
my $bbdisp;
my $hobbitcolumn = "bkup";

my $hostname = "";
my $msgtxt = "";
my %sections = ();
my $cursection = "";

sub processmessage;


# Get the BB and BBDISP environment settings.
$bb = $ENV{"BB"} || die "BB not defined";
$bbdisp = $ENV{"BBDISP"} || die "BBDISP not defined";


# Main routine.
#
# This reads client messages from <STDIN>, looking for the
# delimiters that separate each message, and also looking for the
# section markers that delimit each part of the client message.
# When a message is complete, the processmessage() subroutine
# is invoked. $msgtxt contains the complete message, and the
# %sections hash contains the individual sections of the client
# message.

while ($line = <STDIN>) {
        if ($line =~ /^\@\@client\#/) {
                # It's the start of a new client message - the header 
looks like this:
                # 
@@client#830759/HOSTNAME|1169985951.340108|10.60.65.152|HOSTNAME|sunos|sunos

                # Grab the hostname field from the header
                @hdrfields = split(/\|/, $line);
                $hostname = $hdrfields[3];

                # Clear the variables we use to store the message in
                $msgtxt = "";
                %sections = ();
        }
        elsif ($line =~ /^\@\@/) {
                # End of a message. Do something with it.
                processmessage();
        }
        elsif ($line =~ /^\[(.+)\]/) {
                # Start of new message section.

                $cursection = $1;
                $sections{ $cursection } = "\n";
        }
        else {
                # Add another line to the entire message text variable,
                # and the the current section.
                $msgtxt = $msgtxt . $line;
                $sections{ $cursection } = $sections{ $cursection } . $line;
        }
}

# we watch the [who] section of the client message and alert
# if there is a root login active.

sub processmessage {
        my $color;
        my $summary;
        my $statusmsg;
        my $cmd;
        my $cmdl;

        # Dont do anything unless we have the "ps" section
        return unless ( $sections{"ps"} );

        # Is there a "root" login somewhere in the "who" section?
        # Note that we must match with /m because there are multiple
        # lines in the [who] section.
        if (  ($cmdl) = $sections{"ps"} =~ /(save -s.*)/  ) {
                $color = "yellow";
                $summary = "There MAYBE active backups" ;
                $statusmsg = "&yellow " .  $cmdl  . $sections{"ps"};
        }
        else {
                $color = "green";
                $summary = "Ok";
                $statusmsg = "&green No backup active\n\n";
        }
        # Build the command we use to send a status to the Hobbit daemon
        $cmd = $bb . " " . $bbdisp . " \"status " . $hostname . "." . 
$hobbitcolumn . " " . $color . "
" . $summary . "\n\n" . $statusmsg . "\"";

        # And send the message
        system $cmd;
}






More information about the Xymon mailing list