Subversion Repositories DevTools

Rev

Rev 5399 | Rev 5793 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5399 Rev 5404
Line 34... Line 34...
34
my $opt_help = 0;
34
my $opt_help = 0;
35
my $opt_target;
35
my $opt_target;
36
my $opt_rundir = 'run';
36
my $opt_rundir = 'run';
37
my @opt_data;
37
my @opt_data;
38
my @opt_text;
38
my @opt_text;
-
 
39
my @opt_warn;
39
my %stats;
40
my %stats;
40
my $exitStatus = 0;
-
 
41
my $exitMsg = "OK";
41
my $exitMsg = "OK";
42
my @exitMsgTxt;
42
my @exitMsgTxt;
43
my @perfData;
43
my @perfData;
-
 
44
my $setWarning;
-
 
45
my $setCritical;
44
 
46
 
45
#-------------------------------------------------------------------------------
47
#-------------------------------------------------------------------------------
46
# Function        : Main Entry
48
# Function        : Main Entry
47
#
49
#
48
# Description     :
50
# Description     :
Line 57... Line 59...
57
                "verbose:+"     => \$opt_verbose,       # flag
59
                "verbose:+"     => \$opt_verbose,       # flag
58
                "target=s"      => \$opt_target,        # String
60
                "target=s"      => \$opt_target,        # String
59
                "rundir=s"      => \$opt_rundir,        # String
61
                "rundir=s"      => \$opt_rundir,        # String
60
                "data=s"        => sub{push @opt_data, split(/\s*,\s*/,$_[1])},          # Strings
62
                "data=s"        => sub{push @opt_data, split(/\s*,\s*/,$_[1])},          # Strings
61
                "text=s"        => sub{push @opt_text, split(/\s*,\s*/,$_[1])},          # Strings
63
                "text=s"        => sub{push @opt_text, split(/\s*,\s*/,$_[1])},          # Strings
-
 
64
                "warn=s"        => sub{push @opt_warn, split(/\s*,\s*/,$_[1])},          # Strings
62
                );
65
                );
63
 
66
 
64
#
67
#
65
#   Process help and manual options
68
#   Process help and manual options
66
#
69
#
Line 95... Line 98...
95
while (<$fh>)
98
while (<$fh>)
96
{
99
{
97
    m~(.*):(.*)~;
100
    m~(.*):(.*)~;
98
    $stats{lc($1)} = $2;
101
    $stats{lc($1)} = $2;
99
}
102
}
-
 
103
close $fh;
100
 
104
 
101
#
105
#
102
#   Determine the Nagios State. Will be CRITICAL if
106
#   Determine the Nagios State. Will be CRITICAL if
103
#       state is NOT OK
107
#       state is NOT OK
104
#       timeStamp is more than 5 minutes old
108
#       timeStamp is more than 5 minutes old
105
#       
109
#       
106
unless (defined $stats{state} && $stats{state} eq 'OK')
110
unless (defined $stats{state} && $stats{state} eq 'OK')
107
{
111
{
108
    $exitStatus = 2;
112
    $setCritical = 1;
109
    $exitMsg = $stats{state} || 'Unknown state' ;
113
    $exitMsg = $stats{state} || 'Unknown state' ;
110
}
114
}
111
 
115
 
112
my $dataAge = time() - $stats{timestamp};
116
my $dataAge = time() - $stats{timestamp};
113
if ($dataAge > (10 * 60))
117
if ($dataAge > (10 * 60))
114
{
118
{
115
    $exitStatus = 2;
119
    $setCritical = 1;
116
    $exitMsg = 'Data too old(Secs):' . $dataAge;
120
    $exitMsg = 'Data too old(Secs):' . $dataAge;
117
}
121
}
118
 
122
 
119
#
123
#
120
#   Inert Text data - not perf data.
124
#   Insert Text data - not perf data.
121
#   This will be displayed as a part of the output
125
#   This will be displayed as a part of the output
122
#
126
#
123
foreach my $item (@opt_text)
127
foreach my $item (@opt_text)
124
{
128
{
125
    push @exitMsgTxt, $item . '=' . getDataItem($item); 
129
    push @exitMsgTxt, $item . '=' . getDataItem($item); 
Line 131... Line 135...
131
{
135
{
132
    push @perfData, $item . '=' . getDataItem($item); 
136
    push @perfData, $item . '=' . getDataItem($item); 
133
}
137
}
134
 
138
 
135
#
139
#
-
 
140
#   Process warning thresholds
-
 
141
#
-
 
142
foreach my $item (@opt_warn)
-
 
143
{
-
 
144
    my ($Name, $warn, $critical) = split(/:/, $item);
-
 
145
    my $name = lc $Name;
-
 
146
    my $isCritical;
-
 
147
    if (exists $stats{$name})
-
 
148
    {
-
 
149
        my $value = int($stats{$name});
-
 
150
        if (defined $critical)
-
 
151
        {
-
 
152
            if ($value > int($critical) )
-
 
153
            {
-
 
154
                $isCritical = 1;
-
 
155
                $setCritical = 1;
-
 
156
                push @exitMsgTxt, $Name . ' is Critical'; 
-
 
157
 
-
 
158
            }
-
 
159
        }
-
 
160
        if (! $isCritical)
-
 
161
        {
-
 
162
            if (defined $warn )
-
 
163
            {
-
 
164
                if ($value > int($warn) )
-
 
165
                {
-
 
166
                    $setWarning = 1;
-
 
167
                    push @exitMsgTxt, $Name . ' is Warning'; 
-
 
168
                }
-
 
169
            }
-
 
170
            else
-
 
171
            {
-
 
172
                push @exitMsgTxt, "$item bad format";
-
 
173
                $setWarning = 1; 
-
 
174
            }
-
 
175
        }
-
 
176
    }
-
 
177
    else
-
 
178
    {
-
 
179
        push @exitMsgTxt, "$Name not known";
-
 
180
        $setWarning = 1; 
-
 
181
    }
-
 
182
}
-
 
183
 
-
 
184
#
136
# Prepare the output
185
# Prepare the output
137
#   STATUS, Status Text, Performance Data
186
#   STATUS, Status Text, Performance Data
138
# 
187
# 
139
print($exitMsg);
188
print($exitMsg);
140
print (' - ',join(' ', @exitMsgTxt)) if (@exitMsgTxt);
189
print (' - ',join(', ', @exitMsgTxt)) if (@exitMsgTxt);
141
print ('|',join('; ', @perfData), ';') if (@perfData);
190
print ('|',join('; ', @perfData), ';') if (@perfData);
142
print("\n");
191
print("\n");
143
exit $exitStatus;
192
exit 2 if $setCritical;
-
 
193
exit 1 if $setWarning;
-
 
194
exit 0;
144
 
195
 
145
#-------------------------------------------------------------------------------
196
#-------------------------------------------------------------------------------
146
# Function        : getDataItem 
197
# Function        : getDataItem 
147
#
198
#
148
# Description     : Get an item of statistical data 
199
# Description     : Get an item of statistical data 
Line 246... Line 297...
246
    -man               - Full documentation
297
    -man               - Full documentation
247
    -target=name       - Target Machine name
298
    -target=name       - Target Machine name
248
    -rundir=path       - Alternate run directory
299
    -rundir=path       - Alternate run directory
249
    -data=item         - Data item to report as performance data. Multiple allowed
300
    -data=item         - Data item to report as performance data. Multiple allowed
250
    -text=item         - Data item to report as text. Multiple allowed
301
    -text=item         - Data item to report as text. Multiple allowed
-
 
302
    -warn=item:vw:vc   - Report warnings for item. Multiple allowed
251
 
303
 
252
=head1 OPTIONS
304
=head1 OPTIONS
253
 
305
 
254
=over 8
306
=over 8
255
 
307
 
Line 287... Line 339...
287
 
339
 
288
One or more data items to be returned as a part of the text message.
340
One or more data items to be returned as a part of the text message.
289
 
341
 
290
Multiple items are comma seperated. The argument may be used more than once.
342
Multiple items are comma seperated. The argument may be used more than once.
291
 
343
 
-
 
344
=item B<-warn=item:vw:vc>
-
 
345
 
-
 
346
Report a Nagios error state if the value of the named item exceeds the specified value.
-
 
347
 
-
 
348
vw is the warning threshold. vc is the critical threshold.
-
 
349
 
-
 
350
Multiple items are comma seperated. The argument may be used more than once.
-
 
351
 
-
 
352
 
292
=back
353
=back
293
 
354
 
294
=head1 EXAMPLE
355
=head1 EXAMPLE
295
 
356
 
296
perl blatNagios.pl -target=auawsaarc001 -data=txCount,delCount -data=linkErrors
357
perl blatNagios.pl -target=auawsaarc001 -data=txCount,delCount -data=linkErrors -crit=txCount:40:50
297
 
358
 
298
=cut
359
=cut
299
 
360