forked from aleex42/netapp-cdot-nagios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_cdot_multipath.pl
executable file
·208 lines (153 loc) · 5.42 KB
/
check_cdot_multipath.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
#!/usr/bin/perl
# nagios: -epn
# --
# check_cdot_multipath - Check if all disks are multipathed (4 paths)
# Copyright (C) 2013 noris network AG, http://www.noris.net/
# --
# 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 Data::Dumper;
use 5.10.0;
use strict;
use warnings;
use lib "/usr/lib/netapp-manageability-sdk/lib/perl/NetApp";
use NaServer;
use NaElement;
use Getopt::Long;
GetOptions(
'hostname=s' => \my $Hostname,
'username=s' => \my $Username,
'password=s' => \my $Password,
'onepath-config'=> \my $Exception,
'help|?' => sub { exec perldoc => -F => $0 or die "Cannot execute perldoc: $!\n"; },
) or Error("check_cdot_aggr: Error in command line arguments\n");
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 $must_paths;
my $s = NaServer->new( $Hostname, 1, 3 );
$s->set_transport_type("HTTPS");
$s->set_style("LOGIN");
$s->set_admin_user( $Username, $Password );
# MCC check
my $mcc_iterator = NaElement->new("metrocluster-get");
my $desired_attributes = NaElement->new("desired-attributes");
my $metrocluster_info = NaElement->new("metrocluster-info");
$metrocluster_info->child_add('local-cluster-name','local-cluster-name');
$metrocluster_info->child_add('local-configuration-state','local-configuration-state');
$metrocluster_info->child_add('configuration-type','local-configuration-type');
my $mcc_response = $s->invoke_elem($mcc_iterator);
my $mcc = $mcc_response->child_get("attributes");
my $mcc_info = $mcc->child_get("metrocluster-info");
my $config_state = $mcc_info->child_get_string("local-configuration-state");
my $mcc_name = $mcc_info->child_get_string("local-cluster-name");
if($config_state eq "configured"){
my $type = $mcc_info->child_get_string("configuration-type");
if ($type eq "stretch") {
$must_paths = 2;
} elsif ($type eq "fabric") {
$must_paths = 8;
} elsif ($type eq "two_node_fabric") {
print $Exception;
$must_paths = 1;
} else {
$must_paths = 4;
}
} else {
if($Exception) {
$must_paths = 1;
} else {
$must_paths = 4;
}
}
print $must_paths;
my $iterator = NaElement->new("storage-disk-get-iter");
my $tag_elem = NaElement->new("tag");
$iterator->child_add($tag_elem);
my $next = "";
my @failed_disks;
my @info_disks;
while(defined($next)){
unless($next eq ""){
$tag_elem->set_content($next);
}
$iterator->child_add_string("max-records", 100);
my $output = $s->invoke_elem($iterator);
if ($output->results_errno != 0) {
my $r = $output->results_reason();
print "UNKNOWN: $r\n";
exit 3;
}
my $heads = $output->child_get("attributes-list");
my @result = $heads->children_get();
foreach my $disk (@result){
my $paths = $disk->child_get("disk-paths");
my $path_count = $paths->children_get("disk-path-info");
my $disk_name = $disk->child_get_string("disk-name");
my $path_info = $paths->child_get("disk-path-info");
foreach my $path ($path_info){
my $disk_path_name = $path->child_get_string("disk-name");
my @split = split(/:/,$disk_path_name);
if ($must_paths > 1) {
if((@split eq 2) && ($path_count ne $must_paths)){
unless($path_count > $must_paths){
push @failed_disks, "$disk_name: $path_count instead of $must_paths paths\n";
}
}
} else {
if(($path_count ne $must_paths)){
unless($path_count > $must_paths){
push @failed_disks, "$disk_name: $path_count instead of $must_paths path\n";
}
push @info_disks, "$disk_name: $path_count instead of $must_paths path\n";
}
}
}
}
$next = $output->child_get_string("next-tag");
}
if (@failed_disks) {
print "\nWARNING: disk(s) not multipath:\n" . join( " ", @failed_disks );
exit 2;
} else {
if(@info_disks) {
print "\nOK: disk(s) having more than 1 path:\n" . join( " ", @info_disks );
} else {
print "\nOK: All disks multipath or with one path as configured.\n";
}
exit 0;
}
__END__
=encoding utf8
=head1 NAME
check_cdot_multipath - Check if all disks are multipathed (4 paths)
=head1 SYNOPSIS
check_cdot_multipath.pl --hostname HOSTNAME --username USERNAME \
--password PASSWORD
=head1 DESCRIPTION
Checks if all Disks are multipathed (4 paths)
=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 -help
=item -?
to see this Documentation
=back
=head1 EXIT CODE
3 if timeout occured
2 if one or more disks doesn't have 4 Paths
0 if everything is ok
=head1 AUTHORS
Alexander Krogloth <git at krogloth.de>
Stelios Gikas <sgikas at demokrit.de>