Subversion Repositories DevTools

Rev

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

Rev 5398 Rev 5399
Line 33... Line 33...
33
my $opt_verbose = 1;
33
my $opt_verbose = 1;
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 %stats;
39
my %stats;
39
my $exitStatus = 0;
40
my $exitStatus = 0;
40
my $exitMsg = "OK";
41
my $exitMsg = "OK";
-
 
42
my @exitMsgTxt;
41
my @perfData;
43
my @perfData;
42
 
44
 
43
#-------------------------------------------------------------------------------
45
#-------------------------------------------------------------------------------
44
# Function        : Main Entry
46
# Function        : Main Entry
45
#
47
#
Line 53... Line 55...
53
                "help:+"        => \$opt_help,          # flag, multiple use allowed
55
                "help:+"        => \$opt_help,          # flag, multiple use allowed
54
                "manual:3"      => \$opt_help,          # flag
56
                "manual:3"      => \$opt_help,          # flag
55
                "verbose:+"     => \$opt_verbose,       # flag
57
                "verbose:+"     => \$opt_verbose,       # flag
56
                "target=s"      => \$opt_target,        # String
58
                "target=s"      => \$opt_target,        # String
57
                "rundir=s"      => \$opt_rundir,        # String
59
                "rundir=s"      => \$opt_rundir,        # String
58
                "data=s"        => \@opt_data,          # Strings
60
                "data=s"        => sub{push @opt_data, split(/\s*,\s*/,$_[1])},          # Strings
-
 
61
                "text=s"        => sub{push @opt_text, split(/\s*,\s*/,$_[1])},          # Strings
59
                );
62
                );
60
 
63
 
61
#
64
#
62
#   Process help and manual options
65
#   Process help and manual options
63
#
66
#
Line 112... Line 115...
112
    $exitStatus = 2;
115
    $exitStatus = 2;
113
    $exitMsg = 'Data too old(Secs):' . $dataAge;
116
    $exitMsg = 'Data too old(Secs):' . $dataAge;
114
}
117
}
115
 
118
 
116
#
119
#
-
 
120
#   Inert Text data - not perf data.
-
 
121
#   This will be displayed as a part of the output
-
 
122
#
-
 
123
foreach my $item (@opt_text)
-
 
124
{
-
 
125
    push @exitMsgTxt, $item . '=' . getDataItem($item); 
-
 
126
}
-
 
127
#
117
#   Insert the required performance data
128
#   Insert the required performance data
118
#   
129
#   
119
foreach my $items (@opt_data)
130
foreach my $item (@opt_data)
120
{
131
{
121
    foreach my $item ( split(/\s*,\s*/, $items))
-
 
122
    {
-
 
123
        my $data = 'Unknown';
-
 
124
        $data =  $stats{lc $item} if (defined $stats{lc $item});
-
 
125
        push @perfData, $item . '=' . $data; 
132
    push @perfData, $item . '=' . getDataItem($item); 
126
    }
-
 
127
}
133
}
128
 
134
 
129
#
135
#
130
# Prepare the output
136
# Prepare the output
-
 
137
#   STATUS, Status Text, Performance Data
131
# 
138
# 
132
print($exitMsg);
139
print($exitMsg);
133
if (@perfData)
-
 
134
{
-
 
135
    print("|");
-
 
136
    foreach my $item ( @perfData)
140
print (' - ',join(' ', @exitMsgTxt)) if (@exitMsgTxt);
137
    {
-
 
138
        print("$item; ");
141
print ('|',join('; ', @perfData), ';') if (@perfData);
139
    }
-
 
140
}
-
 
141
print("\n");
142
print("\n");
142
exit $exitStatus;
143
exit $exitStatus;
143
 
144
 
144
#-------------------------------------------------------------------------------
145
#-------------------------------------------------------------------------------
-
 
146
# Function        : getDataItem 
-
 
147
#
-
 
148
# Description     : Get an item of statistical data 
-
 
149
#
-
 
150
# Inputs          : $name       - Name of the item to get 
-
 
151
#
-
 
152
# Returns         : The value of the item or the text 'Unknown'
-
 
153
#
-
 
154
sub getDataItem
-
 
155
{
-
 
156
    my ($name) = @_;
-
 
157
    $name = lc $name;
-
 
158
    return 'Unknown' unless exists $stats{$name};
-
 
159
    return $stats{$name}; 
-
 
160
}
-
 
161
 
-
 
162
 
-
 
163
#-------------------------------------------------------------------------------
145
# Function        : testPid 
164
# Function        : testPid 
146
#
165
#
147
# Description     : See if a PID exists    
166
# Description     : See if a PID exists    
148
#
167
#
149
# Inputs          : $name               - Name of pid file to examine
168
# Inputs          : $name               - Name of pid file to examine
Line 152... Line 171...
152
#
171
#
153
sub testPid
172
sub testPid
154
{
173
{
155
    my ($name) = @_;
174
    my ($name) = @_;
156
    my $pidfile = catfile( $opt_rundir, $name . '.pid');
175
    my $pidfile = catfile( $opt_rundir, $name . '.pid');
157
    open my $fh, $pidfile || return 0;
176
    open (my $fh, $pidfile) || return 0;
158
    my ($pid) = <$fh>;
177
    my ($pid) = <$fh>;
159
    close $fh;
178
    close $fh;
160
 
179
 
161
    if (defined $pid)
180
    if (defined $pid)
162
    {
181
    {
Line 225... Line 244...
225
    -help              - brief help message
244
    -help              - brief help message
226
    -help -help        - Detailed help message
245
    -help -help        - Detailed help message
227
    -man               - Full documentation
246
    -man               - Full documentation
228
    -target=name       - Target Machine name
247
    -target=name       - Target Machine name
229
    -rundir=path       - Alternate run directory
248
    -rundir=path       - Alternate run directory
-
 
249
    -data=item         - Data item to report as performance data. Multiple allowed
230
    -data=item         - Data item to report. Multiple allowed
250
    -text=item         - Data item to report as text. Multiple allowed
231
 
251
 
232
=head1 OPTIONS
252
=head1 OPTIONS
233
 
253
 
234
=over 8
254
=over 8
235
 
255
 
Line 261... Line 281...
261
 
281
 
262
One or more data items to be returned as a part of the performance data.
282
One or more data items to be returned as a part of the performance data.
263
 
283
 
264
Multiple items are comma seperated. The argument may be used more than once.
284
Multiple items are comma seperated. The argument may be used more than once.
265
 
285
 
-
 
286
=item B<-text=item>
-
 
287
 
-
 
288
One or more data items to be returned as a part of the text message.
-
 
289
 
-
 
290
Multiple items are comma seperated. The argument may be used more than once.
-
 
291
 
266
=back
292
=back
267
 
293
 
268
=head1 EXAMPLE
294
=head1 EXAMPLE
269
 
295
 
270
perl blatNagios.pl -target=auawsaarc001 -data=txCount,delCount -data=linkErrors
296
perl blatNagios.pl -target=auawsaarc001 -data=txCount,delCount -data=linkErrors