Subversion Repositories DevTools

Rev

Rev 5793 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5793 Rev 6475
Line 67... Line 67...
67
#
67
#
68
#   Process help and manual options
68
#   Process help and manual options
69
#
69
#
70
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
70
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
71
pod2usage(-verbose => 1)  if ($opt_help == 2 );
71
pod2usage(-verbose => 1)  if ($opt_help == 2 );
72
pod2usage(-verbose => 2)  if ($opt_help > 2);
72
pod2usage(-verbose => 1)  if ($opt_help > 2);
73
 
73
 
74
# Validate options
74
# Validate options
75
Error ("Target machine not specified") unless ($opt_target);
75
Error ("Target machine not specified") unless ($opt_target);
76
 
76
 
77
# Determine the 'run' directory
77
# Determine the 'run' directory
Line 147... Line 147...
147
    if (exists $stats{$name})
147
    if (exists $stats{$name})
148
    {
148
    {
149
        my $value = int($stats{$name});
149
        my $value = int($stats{$name});
150
        if (defined $critical)
150
        if (defined $critical)
151
        {
151
        {
152
            if ($value > int($critical) )
152
            if (compareValues($value, $critical ))
153
            {
153
            {
154
                $isCritical = 1;
154
                $isCritical = 1;
155
                $setCritical = 1;
155
                $setCritical = 1;
156
                push @exitMsgTxt, $Name . ' is Critical'; 
156
                push @exitMsgTxt, $Name . ' is Critical'; 
157
 
157
 
Line 159... Line 159...
159
        }
159
        }
160
        if (! $isCritical)
160
        if (! $isCritical)
161
        {
161
        {
162
            if (defined $warn )
162
            if (defined $warn )
163
            {
163
            {
164
                if ($value > int($warn) )
164
                if (compareValues($value, $warn ))
165
                {
165
                {
166
                    $setWarning = 1;
166
                    $setWarning = 1;
167
                    push @exitMsgTxt, $Name . ' is Warning'; 
167
                    push @exitMsgTxt, $Name . ' is Warning'; 
168
                }
168
                }
169
            }
169
            }
Line 192... Line 192...
192
exit 2 if $setCritical;
192
exit 2 if $setCritical;
193
exit 1 if $setWarning;
193
exit 1 if $setWarning;
194
exit 0;
194
exit 0;
195
 
195
 
196
#-------------------------------------------------------------------------------
196
#-------------------------------------------------------------------------------
-
 
197
# Function        : expandSuffix 
-
 
198
#
-
 
199
# Description     : Convert text like 10Gb to a number 10000000000 
-
 
200
#                   Also removes '_' added to aid readability
-
 
201
#                   Support KB, MB, GB, TB and is case insensitive
-
 
202
#                   
-
 
203
#
-
 
204
# Inputs          : $text   - Test to convert
-
 
205
#
-
 
206
# Returns         : Converted number
-
 
207
#                   Will generate error
-
 
208
#
-
 
209
sub expandSuffix
-
 
210
{
-
 
211
    my ($text) = @_;
-
 
212
    my $number;
-
 
213
    $text =~ s~_~~g;
-
 
214
 
-
 
215
    if ($text =~ m~(\d+)T$~i) {
-
 
216
        $number = int($1) * 1000000000000;
-
 
217
    } elsif ($text =~ m~(\d+)G$~i) {
-
 
218
        $number = int($1) * 1000000000 ;
-
 
219
    } elsif ($text =~ m~(\d+)M$~i) {
-
 
220
        $number = int($1) * 1000000 ;
-
 
221
    } elsif ($text =~ m~(\d+)K$~i) {
-
 
222
        $number = int($1) * 1000 ;
-
 
223
    } elsif ($text =~ m~(\d+)$~i) {
-
 
224
        $number = int($1);
-
 
225
    } else {
-
 
226
        Error ("Number: $text not valid");
-
 
227
    }
-
 
228
    return $number;
-
 
229
}
-
 
230
 
-
 
231
#-------------------------------------------------------------------------------
-
 
232
# Function        : compareValues
-
 
233
#
-
 
234
# Description     : Compares two values
-
 
235
#
-
 
236
# Inputs          : $value          - Data from the machine
-
 
237
#                   $limit          - User limit
-
 
238
#                                     If '-' then sense of comparison is reversed 
-
 
239
#
-
 
240
# Returns         : True: value exceeds limit ( unless - ) 
-
 
241
#
-
 
242
sub compareValues
-
 
243
{
-
 
244
    my ($value, $limit) = @_;
-
 
245
    my $reverse = 0;
-
 
246
    if ( $limit =~ m~-(.*)~) {
-
 
247
        $reverse = 1;
-
 
248
        $limit = $1;
-
 
249
    }
-
 
250
    $limit = expandSuffix($limit);
-
 
251
    if ($reverse) {
-
 
252
        return $value < $limit
-
 
253
    } else {
-
 
254
        return $value > $limit
-
 
255
    }
-
 
256
}
-
 
257
 
-
 
258
 
-
 
259
#-------------------------------------------------------------------------------
197
# Function        : getDataItem 
260
# Function        : getDataItem 
198
#
261
#
199
# Description     : Get an item of statistical data 
262
# Description     : Get an item of statistical data 
200
#
263
#
201
# Inputs          : $name       - Name of the item to get 
264
# Inputs          : $name       - Name of the item to get 
Line 345... Line 408...
345
 
408
 
346
Report a Nagios error state if the value of the named item exceeds the specified value.
409
Report a Nagios error state if the value of the named item exceeds the specified value.
347
 
410
 
348
vw is the warning threshold. vc is the critical threshold.
411
vw is the warning threshold. vc is the critical threshold.
349
 
412
 
350
Multiple items are comma seperated. The argument may be used more than once.
413
The warning and critical thresholds must be numeric with optional multipliers of K, M, G or T.
351
 
414
 
-
 
415
Multiple items are comma seperated. The argument may be used more than once.
352
 
416
 
353
=back
417
=back
354
 
418
 
355
=head1 EXAMPLE
419
=head1 EXAMPLE
356
 
420
 
357
perl blatNagios.pl -target=auawsaarc001 -data=txCount,delCount -data=linkErrors -warn=txCount:40:50
421
perl blatNagios.pl -target=auawsaarc001 -data=txCount,delCount -data=linkErrors -warn=txCount:40:50  -w=Target.avail:15GB:10GB
358
 
422
 
359
=cut
423
=cut
360
 
424