-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_netapp_api_cluster_network.pl
227 lines (161 loc) · 4.99 KB
/
check_netapp_api_cluster_network.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
#!/usr/bin/perl
# nagios: -epn
# --
# check_netapp_cluster_network - Check Network Ports of NetApp Cluster
# --
# 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.
#
# Author: Juergen Vigna <[email protected]>
# Date: 2025/01/13
# --
use strict;
use warnings;
use Getopt::Long;
use IO::Socket::SSL qw();
use LWP;
use JSON::XS;
use Try::Tiny;
use Data::Dumper;
sub json_from_call;
Getopt::Long::Configure('bundling');
GetOptions(
'H|hostname=s' => \my $Hostname,
'u|username=s' => \my $Username,
'p|password=s' => \my $Password,
'w|warning=i' => \my $Warning,
'c|critical=i' => \my $Critical,
'f|perf' => \my $perf,
'e|exclude=s' => \my $exclude,
'r|regexp' => \my $regexp,
'v|verbose' => \my $verbose,
'h|help' => sub { exec perldoc => -F => $0 or die "Cannot execute perldoc: $!\n"; },
) or Error("$0: Error in command line arguments\n");
my $ua = LWP::UserAgent->new(
ssl_opts => {
'verify_hostname' => 0,
'SSL_verify_mode' => IO::Socket::SSL::SSL_VERIFY_NONE,
},
);
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;
#Error( 'Option --warning needed!' ) unless $Warning;
#Error( 'Option --critical needed!' ) unless $Critical;
my $json;
$json = json_from_call( "/network/ethernet/ports?fields=*" );
#print Data::Dumper::Dumper($json);
my $perfmsg = "";
my $errmsg = "";
my $warnmsg = "";
my $ports = $json->{'records'};
my $totports = 0;
my $downports = 0;
my $upports = 0;
my $exclports = 0;
my $verbout = "";
foreach my $port (sort { $a->{name} cmp $b->{name} } @$ports){
my $port_name = $port->{node}->{name} . "-" . $port->{'name'};
my $port_enabled = $port->{'enabled'};
my $port_state = $port->{'state'};
$totports++;
if (defined($exclude)) {
if (($regexp and ($port_name =~ m/$exclude/)) or ($port_name =~ m/^$exclude$/)) {
$exclports++;
if ($port_enabled || ($port_state =~ m/up/)) {
$warnmsg .= " ${port_name}:${port_enabled}:${port_state}";
}
next;
}
}
if ($verbose) {
$verbout .= "${port_name}: ${port_enabled}:${port_state}\n";
}
if (!$port_enabled || ($port_state !~ m/up/)) {
$downports++;
$errmsg .= " ${port_name}:${port_enabled}:${port_state}";
} else {
$upports++;
}
}
if ($perf) {
$perfmsg = " ports=${totports} ports_up=${upports} ports_down=${downports} ports_exclude=${exclports}";
}
if ($downports > 0) {
print "CRITICAL - $downports ports in DISABLED and/or DOWN status |$perfmsg\n";
if ($warnmsg) { print "WARNING: " . $warnmsg . "\n"; }
if ($verbose) { print $verbout; }
exit 2;
}
if ($warnmsg) {
print "WARNING - some excluded ports are not in DISABLED/DOWN, $warnmsg | $perfmsg\n";
exit 1;
}
print "OK - ALL enabled ports are UP |$perfmsg\n";
if ($verbose) { print $verbout; }
exit 0;
sub json_from_call($) {
my $url = shift;
my $req = HTTP::Request->new( GET => "https://$Hostname/api$url" );
$req->content_type( "application/json" );
$req->authorization_basic( $Username, $Password );
my $res = $ua->request( $req );
die $res->status_line unless $res->is_success;
my $result_decoded;
my $decode_error = 0;
try {
$result_decoded = JSON::XS::decode_json( $res->content );
}
catch {
$decode_error = 1;
};
die "Konnte JSON nicht dekodieren" if $decode_error;
return $result_decoded;
}
__END__
=encoding utf8
=head1 NAME
check_netapp_api_cluster_disk_totals - Check Cluster real Space Usage
=head1 SYNOPSIS
check_netapp_api_cluster_disk_totals.pl -H HOSTNAME -u USERNAME
-p PASSWORD -w PERCENT_WARNING [-v|--verbose]
-c PERCENT_CRITICAL [--perf|-f] [-r|--regex] [--aggr|-A AGGR]
=head1 DESCRIPTION
Checks the Aggregates-Sum real Space Usage of the NetApp System and warns
if warning or critical Thresholds are reached
=head1 OPTIONS
=over 4
=item -H | --hostname FQDN
The Hostname of the NetApp to monitor (Cluster or Node MGMT)
=item -u | --username USERNAME
The Login Username of the NetApp to monitor
=item -p | --password PASSWORD
The Login Password of the NetApp to monitor
=item -w | --warning PERCENT_WARNING
The Warning threshold
=item -c | --critical PERCENT_CRITICAL
The Critical threshold
=item -f | --perf
Flag for performance data output
=item -A | --aggr
Check only specific aggregate
=item -e | --exclude
Optional: String for names of ports to exclude from check
=item -r | --regex
Optional: aggregate name is a regex
=item -h | --help
=item -?
to see this Documentation
=back
=head1 EXIT CODE
3 on Unknown Error
2 if Critical Threshold has been reached
1 if Warning Threshold has been reached
0 if everything is ok
=head1 AUTHORS
Alexander Krogloth <git at krogloth.de>