Method isSuccess not working right perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Method isSuccess not working right perl
# 1  
Old 10-08-2009
Method isSuccess not working right perl

Good morning all....
I have been learning Perl for about 2 months now and I guess I am getting there as much as I can however I am really stuck. I have a Perl script called postEvent.pl which uses a package called event.pm. PostEvent.pl depends on a meithod inside event.pm called isSuccess to tell the user if the message sent was a success.
For some reason I keep getting....
Code:
Problems sending message to Tivoli

Which comes from postEvent.pl code logic here...
Code:
if ($event->isSuccess()) {
        &info("Message sent to Tivoli, $flags{'m'}");
} else {
        &error("Problems sending message to Tivoli, ", $event->getStatusMsg);
}

The problem is that the message is in fact a success, for some reason its just not getting the message that it was a success from the event.pm package and I am not sure why. I am listed both sets of source code here in hopes that somebody can tell me what I am doing wrong and show me. I have been stuck on this for 2 days now ;-(
Thank you.
Here is the source for postEvent.pl
Code:
#!/lcl/bin/perl -d
use Env;
use strict;
use Sys::Hostname;
use Getopt::Std;
my ($rtn, $help);
my %flags = ('t' => '', # Event class
             's' => '', # Severity
             'h' => hostname(), # hostname
             'p' => '', # Program
             'b' => '', # Business System
             'm' => '', # Message
             'g' => '', # on-call group
             'i' => '', # instructions
             'n' => 'Shell_API',
             'c' => '', # confirm an event with an email to the on-call team.
             'd' => '', # debug mode
             'u' => '', # specify a specific URL to post events
             '?' => ''  # help
             );
getopts('t:s:h:p:b:m:g:i:n:c:d:u', \%flags);

## Make sure GFS::Event is setup on this system
##
my $rtn = eval { require GFS::Event };
my $event = eval { return GFS::Event->new() };
if ($flags{'u'}) { $event->setURL($flags{'u'}); }
if ($help) { help();exit; }
&debug("Command line parameters: ", join (",", @ARGV)) if $flags{'d'};
&debug("Beginning $0, ", join (",", @ARGV)) if $flags{'d'};
my $event = GFS::Event->new();
if (! defined $event) {
        &error("Could not create event object, $@");
}
if ($flags{'c'}) { $event->setConfirmEventOn(); }
$event->postEvent(
        errorType => $flags{'t'},
        errorSeverity => $flags{'s'},
        errorGroup => $flags{'g'},
        errorProgram => $flags{'p'},
        errorSystem => $flags{'b'},
        errorMessage => "$flags{'m'}",
        errorHost => $flags{'h'},
        errorInstructions => $flags{'i'},
        errorNumber => "$flags{'n'}",
        errorSubsource => "$0",
        errorSource => "$0"
        );
if ($event->isSuccess()) {
        &info("Message sent to Tivoli, $flags{'m'}");
} else {
        &error("Problems sending message to Tivoli, ", $event->getStatusMsg);
}
sub help {
        my $usage = "Mandatory, these command line options must be specified.\n";
        $usage .= "\t-t  <Error Type>\n";
        $usage .= "\t-s <Severity Code>\n";
        $usage .= "\t-g <On-Call Group>\n";
        $usage .= "\t-m <Message>\n\n";
        $usage .= "\t-i <Operator's Instruction>\n";
        $usage .= "\t-n <errorNumber>\n";
        $usage .= "\t-c, no parameter.  If specified, an email notification will be generated in addition to the Tivoli post.\n";
        $usage .= "\t-p <Program>\n";
        $usage .= "\t-b <Business_System>\n";
        $usage .= "\t-d, no parameter.  If specified, set log level to debug.\n";
        &info($usage);
        return;
}
sub debug {
        if (! $flags{'d'}) { return }
        my $field;
        print STDOUT "[" . localtime() . "] [DEBUG] ";
        foreach $field (@_) { print STDOUT $field }
        print "\n";
}
sub info {
        my $field;
        print STDOUT "[" . localtime() . "] [INFO] ";
        foreach $field (@_) { print STDOUT $field }
        print "\n";
}
sub warn {
        my $field;
        print STDOUT "[" . localtime() . "] [WARN] ";
        foreach $field (@_) { print STDOUT $field }
        print "\n";
}
sub error {
        my $field;
        print STDOUT "[" . localtime() . "] [ERROR] ";
        foreach $field (@_) { print STDOUT $field }
        print "\n";
        exit 5;
}

Here is the source for event.pm
Code:
package GFS::Event;
our $VERSION = '1.1.0';
## Core
use strict;
use Sys::Hostname;
use Date::Format;
## Location of postzmsg
use constant POSTZ_HOME => "/lcl/apps/esm/bin";
## Config file for postzmsg
use constant POSTZ_CONFIG => "/lcl/apps/esm/bin/eif.conf";
sub new {
        my $this = {};
    my $proto = shift;
    my $class = ref($proto) || $proto;
    bless $this, $class;
        my %args = @_;
        $this->{'STATUS'} = "";
    $this->{'POSTZ_HOME'} = $args{'postz'} || POSTZ_HOME;
    $this->{'POSTZ_CONFIG'} = $args{'postz_config'} || POSTZ_CONFIG;
        return $this;
}
sub postEvent {
        my $this = shift;
        my %parms = @_;
    my $severity = $parms{'errorSeverity'} || $parms{'err_severity'} || '';
    my $message = $parms{'errorMessage'} || $parms{'err_msg'} || '';
    # Removes all front white space
    $message =~ s/^\s+//;
    # Replaces sequence of white space with a single space
    $message =~ s/\s+/ /g;
    # Removes all end white space
    $message =~ s/\s+$//;
    # Remove carriage returns anywhere in the string
    $message =~ s/^M$//;
    # Remove Line Feeds
    $message =~ s/\n//g;
    my $type = $parms{'errorType'} || $parms{'err_type'} || '';
    my $source = $parms{'errorSource'} || $parms{'err_source'} || '';
    my $group = $parms{'errorGroup'} || $parms{'err_group'} || '';
    my $instructions = $parms{'errorInstructions'} || $parms{'err_inst'};
        if (! $instructions) { $instructions= "Please call ${group} as appropriate for severity (${severity})."; }
    # Removes all front white space
    $instructions =~ s/^\s+//;
    # Replaces sequence of white space with a single space
    $instructions =~ s/\s+/ /g;
    # Removes all end white space
    $instructions =~ s/\s+$//;
    # Remove carriage returns anywhere in the string
    $instructions =~ s/^M$//;
    # Remove Line Feeds
    $instructions =~ s/\n//g;

    my $host = $parms{'errorHost'} || $parms{'err_host'} || '';
    my $system = $parms{'errorSystem'} || $parms{'err_system'} || '';
    my $subSource = $parms{'errorSubSource'} || $parms{'err_subsource'} || '';
    my $program = $parms{'errorProgram'} || $parms{'err_prog'} || '';
$this->{'STATUS'} = system ("clear");
print "######################################################################################################################################## \n";
print "\n";
print "Output being sent to postzmsg....";
print "\n";
print ("$this->{'POSTZ_HOME'}/postzmsg -f $this->{'POSTZ_CONFIG'} -r ${severity} -m '${message}' OnCallGroup=${group} ISOC_Instructions='${instructions}' Node=${host} SubSource=${subSource} System=${system}
Program=${program} ${type} ${source} ");
print "\n";
print "######################################################################################################################################## \n";
print "\n";
    $this->{'STATUS'} = system("$this->{'POSTZ_HOME'}/postzmsg -f $this->{'POSTZ_CONFIG'} -r ${severity} -m '${message}' OnCallGroup=${group} ISOC_Instructions='${instructions}' Node=${host} SubSource=${subS
ource} System=${system} Program=${program} ${type} ${source}");
    return $this->{'STATUS'};
}
## Mostly legacy getters/setters for backwards compatibility
sub setLogFile { my $this = shift; $this->{'log_file'} = shift; }
sub setStatus { my $this = shift; $this->{'STATUS'} = shift; }
sub setStatusMsg { my $this = shift; $this->{'STATUS_MSG'} = shift; }
sub setConfirmEventOn { my $this = shift; $this->{'confirm_event'} = "TRUE"; }
sub setConfirmEventOff { my $this = shift; $this->{'confirm_event'} = ""; }
sub confirmEvent { my $this = shift; return $this->{'confirm_event'}; }
sub getLogFile { my $this = shift; return $this->{'log_file'}; }
sub getStatus { my $this = shift; return $this->{'STATUS'}; }
sub getStatusMsg { my $this = shift; return $this->{'STATUS_MSG'}; }
sub getContentMsg { my $this = shift; return $this->{'CONTENT_MSG'}; }
sub getFromAddr { my $this=shift; return $this->{'email_from_addr'}; }
sub getSuppDistList { my $this=shift; return $this->{'email_distribution_list'}; }
sub getOncallGrp { my $this=shift; return $this->{'default_oncall_group'}; }
sub getURL { my $this=shift; return $this->{'URL'} }
sub setURL { my $this=shift; $this->{'URL'} = shift;}
sub printURL { my $this=shift; return join ("\n", split /\|/, $this->{'URL'}) }
sub isSuccess { my $this = shift; return $this->{'STATUS'} }
## -----------------------------sendErrortoTivoli-------------------------------- ##
## Legacy method used to reformat a hashmap into the postEvent call.
##
sub sendError2Tivoli {
        my $class = shift;
        my $postEvent = shift;
        my %tivEvent = %{$postEvent};
        my $event = GFS::Event->new();
        $event->setConfirmEventOff();
        if (! $tivEvent{'err_host'}) { $tivEvent{'err_host'} = hostname(); }
        $event->postEvent(
                                        errorType => $tivEvent{'err_type'},
                                        errorSeverity => $tivEvent{'err_severity'},
                                        errorGroup => $tivEvent{'err_group'},
                                        errorProgram => $tivEvent{'err_prog'},
                                        errorSystem => $tivEvent{'err_system'},
                                        err_msg => $tivEvent{'err_msg'},
                                        errorHost => $tivEvent{'err_host'},
                                        errorInstructions => $tivEvent{'err_inst'},
                                        errorNumber => "$tivEvent{err_n}",
                                        errorSubsource => $tivEvent{'subsource'}
                                 );
        return $event->getStatusMsg();
}
1;
##
sub sendError2Tivoli {
        my $class = shift;
        my $postEvent = shift;
        my %tivEvent = %{$postEvent};
        my $event = GFS::Event->new();
        $event->setConfirmEventOff();
        if (! $tivEvent{'err_host'}) { $tivEvent{'err_host'} = hostname(); }
        $event->postEvent(
                                        errorType => $tivEvent{'err_type'},
                                        errorSeverity => $tivEvent{'err_severity'},
                                        errorGroup => $tivEvent{'err_group'},
                                        errorProgram => $tivEvent{'err_prog'},
                                        errorSystem => $tivEvent{'err_system'},
                                        err_msg => $tivEvent{'err_msg'},
                                        errorHost => $tivEvent{'err_host'},
                                        errorInstructions => $tivEvent{'err_inst'},
                                        errorNumber => "$tivEvent{err_n}",
                                        errorSubsource => $tivEvent{'subsource'}
                                 );
        return $event->getStatusMsg();
}
1;
__END__
# Documentation...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python (seleniumrequests)Class, Constructor, Method Not Working

Newbie question. I created a class: class WP(seleniumrequests.PhantomJS): def __init__(self, wpurl='https://blah.org/download/release-archive/', bwppurl='https://blah.org/plugins/browse/popular/'): self.wp=wpurl ... (5 Replies)
Discussion started by: metallica1973
5 Replies

2. Shell Programming and Scripting

IF-THEN-ELSE in PERL not working

Guys, i was trying a simple if-then-else statement in perl; but not getting any success in that. can you please help, where i am wrong. I tried $diff variable with double quotes as well, but no go. $region = $ARGV; $diff = $ARGV; if ; then ($date) = split(' ', `ssh -xC $san cat... (2 Replies)
Discussion started by: sdosanjh
2 Replies

3. Emergency UNIX and Linux Support

Perl error: Can't call method "value" on an undefined value

Hi, I am running a perl script to automate a process and I keep running into a error can't find the "value" Can't call method "value" on an undefined value at process_file.pl line 44. file is CVS cell is ifdfdxrfmp.ksh Here is the script I have also attached it as well: ... (2 Replies)
Discussion started by: vpundit
2 Replies

4. Solaris

svc:/network/physical:default: Method "/lib/svc/method/net-physical" failed with exit status 96. [ n

After a memory upgrade all network interfaces are misconfigued. How do i resolve this issue. Below are some out puts.thanks. ifconfig: plumb: SIOCLIFADDIF: eg000g0:2: no such interface # ifconfig eg1000g0:2 plumb ifconfig: plumb: SIOCLIFADDIF: eg1000g0:2: no such interface # ifconfig... (2 Replies)
Discussion started by: andersonedouard
2 Replies

5. Shell Programming and Scripting

\K in perl not working

Hi All, I have just started learning perl and was working on my one-liners tips and tricks. Instead of using the below command : perl -lape 's/(^From:).*/$1 Nelson Elhage <nelhage\@ksplice.com>/' i tried using the \k command using the below command but it gave no results: perl -lape... (2 Replies)
Discussion started by: kunwar
2 Replies

6. Shell Programming and Scripting

method bless perl

Hi, I am using perl with some EDA tool. There is an API function that can be iterate. I try to check the ref and get that it is a string. I assume that it is a hash sub aaa { my $obj = shift; $name = $obj->name; print ref $obj,"\n"; foreach my $var(keys %{$obj}) { my... (0 Replies)
Discussion started by: zivsegal
0 Replies

7. Shell Programming and Scripting

Is a Perl method defined?

In my code, I know I can write... if ( defined &test_sub ) { test_sub(); } else { print "Subroutine doesn't exist"; } This tests the existence of the test_sub subroutine without actually calling it. If, though, I replace test_sub with a package method... if ( defined... (1 Reply)
Discussion started by: JerryHone
1 Replies

8. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

9. Programming

Best Method for installing Perl Modules

Which is the perferred method of installing Perl modules on a Unix system? Is is CPAN or manually installing them via a tar file? Also can anyone point me in the right direction to a decent "how to" on configuring CPAN and how to perform custom installs from a tar? thanks:b: (2 Replies)
Discussion started by: metallica1973
2 Replies

10. Shell Programming and Scripting

Perl, FilePropStore Method

Guys, anyone familiar with this FileProp Store Method.. Im having Compilation Error whenever a value is stored into the tied hash. Run time error sub STORE { my ($self, $key, $value) = @_; my $name = $self ->{name}; unless ($PROPS{$key} and -w $name){ croak "Can't... (1 Reply)
Discussion started by: killerserv
1 Replies
Login or Register to Ask a Question