[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

09/01/2009 at 03:04PM PDT, ID: 24699662
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Perl match pattern inside array, not working properly

Asked by jedblack in Perl Programming Language

Hi all,

I'm trying to put together a nagios script that will login to the service processor of our old hardware and pull the hardware information.  I have everything working good and the array is being populated with the information, but i'm trying to match pattern and then react depending on what pattern is found -- problem is that perl doesnt seem to be matching the pattern correctly...

here is the output that gets put into array (@lines) ....


=============== Environmental Status ===============


--------------------------------------------------------------------------------
System Temperatures (Temperatures in Celsius):
--------------------------------------------------------------------------------
Sensor         Status    Temp LowHard LowSoft LowWarn HighWarn HighSoft HighHard
--------------------------------------------------------------------------------
MB.P0.T_CORE    OK         58     --      --      --     110      115      118
MB.P1.T_CORE    OK         61     --      --      --     110      115      118
MB.T_ENC        OK         23     -6      -3       5      40       48       51

--------------------------------------
Front Status Panel:
--------------------------------------
Keyswitch position: NORMAL

--------------------------------------------------------
System Indicator Status:
--------------------------------------------------------
MB.LOCATE            MB.SERVICE           MB.ACT              
--------------------------------------------------------
OFF                  ON                   ON                  

--------------------------------------------
System Disks:
--------------------------------------------
Disk   Status            Service  OK2RM
--------------------------------------------
HDD0   OK                OFF      OFF
HDD1   OK                OFF      OFF
HDD2   OK                OFF      OFF
HDD3   OK                OFF      OFF

----------------------------------------------------------
Fans (Speeds Revolution Per Minute):
----------------------------------------------------------
Sensor           Status           Speed   Warn    Low
----------------------------------------------------------
F0.RS            OK                5532     --   1000
F1.RS            OK                5720     --   1000
F2.RS            OK                5818     --   1000
MB.P0.F0.RS      OK               16071   2000   2000
MB.P0.F1.RS      OK               16463   2000   2000
MB.P1.F0.RS      OK               16875   2000   2000
MB.P1.F1.RS      FAILED              --   2000   2000

--------------------------------------------------------------------------------
Voltage sensors (in Volts):
--------------------------------------------------------------------------------
Sensor         Status       Voltage LowSoft LowWarn HighWarn HighSoft
--------------------------------------------------------------------------------
MB.P0.V_CORE   OK             1.48      --    1.26    1.54       --
MB.P1.V_CORE   OK             1.48      --    1.26    1.54       --
MB.V_VTT       OK             1.31      --    1.17    1.43       --
MB.V_GBE_+2V5  OK             2.50      --    2.25    2.75       --
MB.V_GBE_CORE  OK             1.20      --    1.08    1.32       --
MB.V_VCCTM     OK             2.55      --    2.25    2.75       --
MB.V_+2V5      OK             2.63      --    2.34    2.86       --
MB.V_+1V5      OK             1.51      --    1.35    1.65       --
MB.BAT.V_BAT   OK             2.98      --    2.70      --       --

--------------------------------------------
Power Supply Indicators:
--------------------------------------------
Supply    Active  Service  OK-to-Remove
--------------------------------------------
PS0       ON      OFF      OFF
PS1       ON      OFF      OFF

------------------------------------------------------------------------------
Power Supplies:
------------------------------------------------------------------------------
Supply  Status          Underspeed  Overtemp  Overvolt  Undervolt  Overcurrent
------------------------------------------------------------------------------
PS0     OK              OFF         OFF       OFF       OFF        OFF
PS1     OK              OFF         OFF       OFF       OFF        OFF

----------------------
Current sensors:
----------------------
Sensor          Status
----------------------
MB.FF_SCSI       OK
####################################################

you'll see that there is clearly a "FAILED" that i awas to match against... but when i run the script...i get this...

[root@poll1 dev]# ./v240hwcheck_new.sh 10.5.9.4
Hardware OK[root@poll1 dev]#


any ideas....?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
#!/usr/bin/perl -ws
##script to check hardware status of Sun V20/v40z/v440/v490 via telnet into the Service Processor
$host = $ARGV[0];
use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10,
                            Prompt => '/sc> $/',
                            input_log => "input_log",
                            dump_log => "dump_log",
                            errmode=>sub {&exit});
 
$telnet->open ("$host") or die("Cannot open");
$telnet->waitfor('/Please login:/i');
$telnet->print("admin");
$telnet->waitfor('/Please Enter password:/i');
$telnet->print("pass123");
$telnet->waitfor('/sc>/i');
@lines = $telnet->cmd("showenvironment");
###@lines is what gets populated with system status info
#########################################
$telnet->print("logout");
 
#######################################
foreach my $stat ( @lines ) {
   if ($stat =~ m/FAILED/i) {
print "CRITICAL; $stat";
exit 2;
}
elsif ($stat =~ m/WARN/i) {
   print "WARNING; $stat";
exit 1;
}
else {
print "Hardware OK";
exit 0;
}
}
##########################################
sub exit{
print "Nagios could not login to the ALOM, will try again.\n";
};
 
Keywords: Perl match pattern inside array, not w…
 
Loading Advertisement...
 
[+][-]09/01/09 03:23 PM, ID: 25236769

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/01/09 03:26 PM, ID: 25236791

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/02/09 07:55 AM, ID: 25241698

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/02/09 11:30 AM, ID: 25244058

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Sign Up Now!
Solution Provided By: Adam314
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20080625