Link to home
Start Free TrialLog in
Avatar of linuxpig
linuxpig

asked on

Perl issue with script

Im using a script for Nagios that runs a query in oracle and returns a number. The script can be found at http://nagiosexchange.altinity.org/nagiosexchange/check_oracle_generic/check_oracle_generic. When this script is run command line with all the correct flag definitions, it returns the correct out put. But when nagios runs it automatically, there is an error that shows up in the web interface. The error is below:

**ePN failed to compile /usr/local/nagios/libexec/check_oracle_generic: "Global symbol "$SID" requires explicit package name at (eval 1) line 74,

Ive read several different forums where it says to add main:: to the line at 74 which looks like:

if (!$SID || !$dbuser || !$dbpassword || !$w || !$c || !$q)
      {    # this is line 74

And ive tried this and added it to several other places, while it does return a different error, it still doesnt work.

Ive checked the LD library paths for nagios and root, added the paths to the /etc/init.d/httpd and /etc/sysconfig/httpd.


The other weird thing is is if i put the command line arguments in a shell script wrapper, it works as well. Problem with this it doesnt return the status codes nagios needs to alert.

So can someone whos great with perl please help me out with this? Thanks!
Avatar of Adam314
Adam314

Can you post more of the script.
Avatar of linuxpig

ASKER

Click the link in my original post, it will show you the entire script.
Add this after line 30:
    use vars qw($SID $dbuser $dbpassword $w $c $q);
Didnt work, it returns the following error instead:

**ePN failed to compile /usr/lib64/nagios/plugins/check_oracle_generic: "Global symbol "$h" requires explicit package name at (eval 10) line 83,
Performance Data:      Global symbol "$dbhandle" requires explicit package name at (eval 10) line 100.
When nagios exectues this, does it use the #! line to determine how to handle the file?  Or do you specify how to process the file and options somewhere?  It looks like perl is being run with the strict pragma, but this isn't in this file.

You can solve this error by hadding a use vars statement similar to above with the undefined variable names, or modifying the previous use vars statement to include these:
    use vars qw($h $dbhandle);

Note that if perl isn't being run with the -s switch, the program would have to be modified to handle the command line arguments.  If nagios isn't using the #! line to process the file, it's possible it isn't using the -s switch.
If you click on the link in the original post, you will see the code and see that it is using the -s flag. I appreciate the input but it seems like people are just submitting guesses. Im looking for a legitimate thread of troubleshooting here.
It use vars statement will solve this problem.  As I don't have nagios, I can't test any of my suggestions.

What I meant by my previous comment, is that it appears that nagios is not executing the script exactly as it appears, but is doing something else - like using the eval function to process the script.

Did you add the use vars statement?  Do you get any errors?
Yes it continued to error.
What is the new error?
**ePN failed to compile etc..., Since this seems like it will never end, Is there way of just taking this awful perl script and write a shell script that will do the same thing? It seems like the way to go at this point.
Not a shell script, but you could write a new perl script.  What do you need the script to do?  How do you want it to get it's information (such as SID, username, password) - through command line parameters, environment variables, have them hard-coded?

Does it need to return specific values, as this script does?
Yes it needs to do exactly what this bad script can.
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Adam for the quick response. Will it get around the ePN issue in Nagios the other script had? It tests fine command line but the true test it for Nagios to run it, but i cant test it yet because our network is down. Go figure
BTW, Adam can you please tell me the differences between your script and the original script. Im curious how you were able to get around the ePN issue incase it happens again
Like I mentioned, it appears that Nagios is running the script with eval, rather than starting another perl process - and that Nagios is running the script with the strict pragma.  This pragma requires that all your variables are declared, which was not the case in the original script.  Also, the original script was using the -s switch to perl to get the command line variables, while this script uses the Getopt::Long module.  Other than that, I just used more common coding practices.  You'll notice that this new script is similar to the original.
Adam, i finally had a chance to run the script, the problem is when an error is happening, the return just says Warning or Critical and not Warning: result = 50 or Critical; result = 60

#new line 63:
    print "CRITICAL: result = $row[0]";
 
#new line 67
    print "WARNING: result = $row[0]";

Open in new window

Mistake, i didnt mean to mark this for deletion
Let it be known, Adam is the man! Thanks adam
Adam was great in assisting with this issue which was very critical for me.