forked from aleex42/netapp-cdot-nagios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_cdot_ports.pl
260 lines (198 loc) · 7.17 KB
/
check_cdot_ports.pl
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/perl
# nagios: -epn
# --
# check_cdot_ports.pl - Check physical ports of the cluster
# Copyright (C) 2019 operational services GmbH & Co. KG
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --
use strict;
use warnings;
use lib "/usr/lib/netapp-manageability-sdk/lib/perl/NetApp";
use NaServer;
use NaElement;
use Getopt::Long qw(:config no_ignore_case);
# High resolution alarm, sleep, gettimeofday, interval timers
use Time::HiRes qw();
my $STARTTIME_HR = Time::HiRes::time(); # time of program start, high res
my $STARTTIME = sprintf("%.0f",$STARTTIME_HR); # time of program start
GetOptions(
'H|hostname=s' => \my $Hostname,
'u|username=s' => \my $Username,
'p|password=s' => \my $Password,
'P|port=s' => \my $Port,
'exclude=s' => \my @excludelistarray,
'regexp' => \my $regexp,
'perfdatadir=s' => \my $perfdatadir,
'perfdataservicedesc=s' => \my $perfdataservicedesc,
'help|?' => sub { exec perldoc => -F => $0 or die "Cannot execute perldoc: $!\n"; },
) or Error("$0: Error in command line arguments\n");
# separate exclude strings into arrays
my %Excludelist;
@Excludelist{@excludelistarray}=();
my $excludeliststr = join "|", @excludelistarray;
sub Error {
print "$0: " . $_[0] . "\n";
exit 2;
}
Error('Option --hostname needed!') unless $Hostname;
Error('Option --username needed!') unless $Username;
Error('Option --password needed!') unless $Password;
my ($crit_msg, $warn_msg, $ok_msg);
# Store all perf data points for output at end
my %perfdata=();
my $port_count = 0;
my $s = NaServer->new( $Hostname, 1, 110 );
$s->set_transport_type("HTTPS");
$s->set_style("LOGIN");
$s->set_admin_user( $Username, $Password );
my $iterator = new NaElement('net-port-get-iter');
my $tag_elem = NaElement->new("tag");
$iterator->child_add($tag_elem);
my $desired_attributes = NaElement->new("desired-attributes");
$iterator->child_add($desired_attributes);
# specify which attributes should be returned
my $netportinfo = new NaElement('net-port-info');
$desired_attributes->child_add($netportinfo);
$netportinfo->child_add_string('link-status','link-status');
$netportinfo->child_add_string('port','port');
$netportinfo->child_add_string('node','node');
$netportinfo->child_add_string('ifgrp-port','ifgrp-port');
# specify physical ports only or specific portname provided
my $xi1 = new NaElement('query');
$iterator->child_add($xi1);
my $xi2 = new NaElement('net-port-info');
$xi1->child_add($xi2);
$xi2->child_add_string('port-type','physical');
if($Port){
$xi2->child_add_string('port',$Port);
}
my $next = "";
my (@crit_msg, @warn_msg, @ok_msg);
while(defined($next)){
unless($next eq ""){
$tag_elem->set_content($next);
}
$iterator->child_add_string("max-records", 100);
my $output = $s->invoke_elem($iterator);
last if ($output->child_get_string("num-records") eq 0 );
if ($output->results_errno ne 0) {
my $r = $output->results_reason();
print "UNKNOWN: $r\n";
exit 3;
}
my $ports = $output->child_get("attributes-list");
unless($ports){
print "CRITICAL: no port matching this name\n";
exit 2;
}
my @result = $ports->children_get();
my @down_ports;
foreach my $port (@result){
# get all acquired information
my $port_name = $port->child_get_string("port");
my $node_name = $port->child_get_string("node");
my $link_status = $port->child_get_string("link-status");
my $ifgroup = $port->child_get_string("ifgrp-port");
# if the port is down, send a warning
if($link_status eq "down" && $ifgroup) {
# my $warn_msg = "$port_name (node $node_name) link-status is $link_status";
# if the port is in an ifgrp, return its name
$warn_msg = "$port_name (node $node_name; interface group $ifgroup) link-status is $link_status";
push (@warn_msg, "$warn_msg\n");
} elsif ($link_status eq "unknown") {
my $warn_msg = "$port_name (node $node_name) is $link_status";
push (@warn_msg, "$warn_msg\n");
} else {
my $ok_msg = "$port_name (node $node_name) is $link_status";
push (@ok_msg, "$ok_msg\n");
}
$port_count++;
}
$next = $output->child_get_string("next-tag");
}
my $size;
if(scalar(@crit_msg) ){
$size = @crit_msg;
print "CRITICAL: $size ports are down\n";
print join ("", @crit_msg);
# if ($perf) {
# if($perfdatadir) {
# perfdata_to_file($STARTTIME, $perfdatadir, $hostdisplay, $perfdataservicedesc, $perfdataallstr);
# print "|$perfdataglobalstr\n";
# } else {
# print "|$perfdataallstr\n";
# }
# } else {
# print "\n";
# }
exit 2;
} if(scalar(@warn_msg) ){
$size = @warn_msg;
print "WARNING: $size ports are down\n";
print join ("", @warn_msg);
# if ($perf) {
# if($perfdatadir) {
# perfdata_to_file($STARTTIME, $perfdatadir, $hostdisplay, $perfdataservicedesc, $perfdataallstr);
# print "|$perfdataglobalstr\n";
# } else {
# print "|$perfdataallstr\n";
# }
# } else {
# print "\n";
# }
exit 1;
} if(scalar(@ok_msg) ){
print "OK:\n";
print join ("", @ok_msg);
# if ($perf) {
# if($perfdatadir) {
# perfdata_to_file($STARTTIME, $perfdatadir, $hostdisplay, $perfdataservicedesc, $perfdataallstr);
# print "|$perfdataglobalstr\n";
# } else {
# print "|$perfdataallstr\n";
# }
# } else {
# print "\n";
# }
exit 0;
} else {
print "WARNING: no port with this name found\n";
exit 1;
}
__END__
=encoding utf8
=head1 NAME
check_cdot_ports - Check physical ports of the cluster
=head1 SYNOPSIS
check_cdot_ports.pl --hostname HOSTNAME --username USERNAME \
--password PASSWORD
=head1 DESCRIPTION
Checks if all physical ports of the system are up
=head1 OPTIONS
=over 4
=item --hostname FQDN
The Hostname of the NetApp to monitor
=item --username USERNAME
The Login Username of the NetApp to monitor
=item --password PASSWORD
The Login Password of the NetApp to monitor
=item --port PORT
The Name of the specific port to be checked
=item --exclude
Optional: The name of a port that has to be excluded from the checks (multiple exclude item for multiple volumes)
=item --regexp
Optional: Uses the input in "exclude" parameter as a regex filter for port names. A value must not be set.
=item -help
=item -?
to see this Documentation
=back
=head1 EXIT CODE
3 on Unknown Error
2 if any link is down
0 if everything is ok
=head1 AUTHORS
Alexander Krogloth <git at krogloth.de>
Therese Ho <thereseh at netapp.com>