For purposes of supervision with nagios on HP-UX, I started using Perl which I never tried yet. But now I encountered an issue. To explain the context, I need to compare the values of swap used by both of my servers to values that are passed as parameters (to set critical threshold and warning). So I need to retrieve the results of two commands "swapinfo" and put them each in a table to be treated thereafter. This is where I stopped for the moment.
Here's what I did:
Code:
#!/opt/perl/bin/perl
#
# check multiswap hpux
#
use strict;
use Getopt::Std;
use vars qw(@swap1 @swap2 $command_line1 $command_line2 %exit_codes);
# Codes prefer finished for Nagios
%exit_codes = ('UNKNOWN',-1,'OK',0,'WARNING',1,'CRITICAL',2);
# Get the info of the swap1 in /dev/vg00/lvol2
$command_line1 = `swapinfo -tam | grep lvol2`;
# Get the info of the swap2 in /dev/vg00/lvol9
$command_line2 = `swapinfo -tam | grep lvol9`;
# Put the result into a table for swap1
chomp $command_line1;
@swap1 = split(/ /,$command_line1);
# Put the result into a table for swap2
chomp $command_line2;
@swap2 = split(/ /, $command_line2);
With the command "swapinfo -tam," I noted that, for example, the 3rd column (counting from 0) gives the number of MB free, and 4th columns provide the percentage used. Thus, to verify that I could well use the values of the table eventually, I tried to read by adding at the end of the script:
Code:
print $swap1[3],"\n";
print $swap1[4],"\n";
print $swap2[3],"\n";
print $swap2[4],"\n";
But at runtime, nothing appears. After several tries, I realized that only
Code:
print $swap1[0],"\n";
print $swap2[0],"\n";
actually gives me what I asked. When I try to display the following columns, nothing appears. Did I inevitably missed something? Since I do not know how to do that, could anyone of you help me please?
Bookmarks