forked from arigaud/Home
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_emc_clariion.pl
2595 lines (2170 loc) · 99.7 KB
/
check_emc_clariion.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
# ------------------------------------------------------------------------------
# check_emc_clariion.pl - checks the EMC CLARIION SAN devices
# Copyright (C) 2005 NETWAYS GmbH, www.netways.de
# Original Author: Michael Streb <michael.streb@netways.de>
# Maintained by: Troy Lea <plugins@box293.com> Twitter: @Box293
# See all my Nagios Projects on the Nagios Exchange:
# http://exchange.nagios.org/directory/Owner/Box293/1
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#
# To see the license type:
# check_emc_clariion.pl --license | more
#
# ------------------------------------------------------------------------------
# Version Notes
# ------------------------------------------------------------------------------
# Version : 1.0 or 1315 2009-01-08 09:16:31Z
# Date : January 8 2009
# Notes : This is the original plugin
#
#
# Version : 2011-03-24
# Date : March 24 2011
# Notes : Modified plugin to perform a Percentage Of Dirty Pages check that
# returns performance data (cache_pdp)
#
# Version : 2011-03-28
# Date : March 28 2011
# Notes : Modified plugin to perform SP Busy and SP Idle checks that
# returns performance data (sp_busy and sp_idle)
#
#
# Version : 2011-05-08
# Date : May 5 2011
# Notes : Modified plugin to peform an SP Busy check [that uses the controller
# busy and idle ticks] and returns performance data (sp_cbt_busy).
# This is more accurate than the (sp_busy and sp_idle) method.
# Removed (sp_busy and sp_idle) checks from the help text, left them
# in the plugin so can can still be used if desired.
#
#
# Version : 2011-06-29
# Date : June 29th 2011
# Notes : Modified sp_cbt_busy to check for negative numbers in the data
# obtained from the SAN. If this occurs then abort. This happens
# randomnly so this will avoid incorrect data.
#
#
# Version : 2011-07-04
# Date : July 4th 2011
# Notes : Modified sp_cbt_busy to ensure calculated value does not exceed
# 100%. If this occurs then abort. This happens randomnly so this
# will avoid incorrect data.
#
#
# Version : 2012-03-06
# Date : March 6th 2012
# Notes : Modified check_disk to look for Removed drives, this was missing.
# Also removed a double || symbol in the same section.
# Modified check_portstate to include code supplied from Federspiel
# Till. Problem occurred when all ports were checked, the error_count
# was being incorrectly determined.
#
#
# Version : 2012-10-23
# Date : October 23rd 2012
# Notes : Corrected POD formatting to fix POD ERRRORS.
# Added error checking to ensure we are getting expected results from
# the Navisphere CLI app.
#
#
# Version : 2012-12-05
# Date : December 5th 2012
# Notes : Updated plugin to check for navicli or naviseccli, it will use
# naviseccli if present. Also makes sure that the username and password
# arguments have been provided. This fixes a problem with newer
# releases of Navisphere that only come with naviseccli (reported by
# Charles Breite).
#
#
# Version : 2012-12-11
# Date : December 11th 2012
# Notes : Fixed bug in portstate check, it is now performing a regex that is
# not case sensative (reported by Charles Breite). Also added a check
# to detect if the user did not provide any options, if not it will
# display the help.
#
#
# Version : 2012-12-19
# Date : December 19th 2012
# Notes : Updated code to prevent errors if required arguments are missing, if
# so it will display the help. Updated the help to include information
# about Secure vs Non-Secure and also provided several examples.
#
#
# Version : 2013-01-25
# Date : January 25th 2013
# Notes : Added LUN check (requested by Nishith N. Vyas) to report the State,
# ID, Name, Size, Free Space, RAID Group Type and Percentage Rebuilt.
# Added RAID Group check (requested by Nishith N. Vyas) to report the
# State, ID, RAID Group Type, Logical Size, Free Space, Percentage
# Defragmentation Complete, Percentage Expansion Complete.
# Fixed bug in the disk check that was counting Empty disk slots as
# disks, (reported by Nishith N. Vyas). Added SP Information check
# that will report information about the SP ID, Agent Revision,
# FLARE Revision, PROM Revision, Model/Type, Memory and Serial Number.
# Added functionality that will pause for 7 seconds if an error occurs
# before showing the help text, this gives you time to read the error
# message. Added error checking for "Could not connect to the specified
# host". Updated SP check to account for enclosures which return
# certain parts (Fans etc) with a status of N/A (as reported by
# davesykes on Nagios Exhcange). Added information to the Help about
# what states will be returned for each check. If warn or crit values
# are incorrect or not present when the arguments are, only an error
# is displayed, the help is not displayed. Fixed bug "Illegal division
# by zero" error when running the sp_cbt_busy check (reported by
# Charles Breite). Added full GNU license.
#
# Version : 2013-01-28
# Date : January 28th 2013
# Notes : Fixed RAID Group type being identified as hot_spare instead of 'Hot
# Spare'.
#
# Version : 2013-01-30
# Date : January 30th 2013
# Notes : Removed space from performance data string for LUN and RAID Group
# checks as identified by Fernando Coelho.
#
#
# Version : 2013-02-09
# Date : February 9th 2013
# Notes : Fixed bug in LUN and RAID Group checks, they were not triggering
# correctly on the warning and critical thresholds. Updated the help
# to explain how the warning and critical thresholds are triggered as
# the existing help was not very clear.
#
# Version : 2013-03-09
# Date : March 9th 2013
# Notes : Plugin updated to incorporate new functionality of using a credentials
# file instead of supplying a username and password. This code was
# supplied by Uwe Kirbach. Fixed a bug that was caused by older versions
# of perl and the use of switch statements. Changed these switch
# statements to if elsif statements to allow plugin to run on older
# versions of perl.
#
# Version : 2013-12-19
# Date : December 19th 2013
# Notes : Add an option to set min spare disk expected (--minspare <COUNT>).
#
# Version : 2014-05-06
# Date : May 6th 2014
# Notes : Added a check to get the inlet air temperature as a nagios perf
# metric (Contributed by Max Vernimmen from www.comparegroup.eu).
# Fixed duplicate port bug when checking just one port. Can now check
# several specific ports at one time like --port 1,3. (Port fixes
# contributed by Stanislav German-Evtushenko).
# Added a check for reporting on Storage Pools (requested and tested by
# Vitaly Burshteyn, tested by Stanislav German-Evtushenko).
#
#
# Version : 2015-03-24
# Author : Alexandre Rigaud <arigaud.prosodie.cap(AT)free.fr>
# Date : March 24th 2015
# Notes : Added a function to check exit value of commands (check_for_errors was useless).
# Added debug option to displaying navicli return.
# Added output option (nagios states, one line stdout for faults only)
# Added Timeout option, default is 10 sec.
# ------------------------------------------------------------------------------
# basic requirements
use strict;
use Getopt::Long;
use File::Basename;
use Pod::Usage;
# predeclared subs
use subs qw/print_help print_license check_sp get_sp_info check_temp check_sp_busy check_sp_idle check_sp_cbt_busy check_disk check_portstate check_hbastate check_cache check_cache_pdp check_faults check_lun check_raid_group check_storage_pool check_test size_format raid_group_state/;
# predeclared vars
use vars qw (
$PROGNAME
$VERSION
$NAVICLI
$NAVISECCLI
$NAVICLI_CMD
%state_names
$state
$opt_host
$opt_sp
$opt_verbose
$opt_help
$opt_checktype
$opt_warn
$opt_crit
$opt_pathcount
$opt_node
$opt_secfilepath
$opt_user
$opt_password
$opt_lun_id
$opt_temp_type
$opt_debug
$opt_state
$opt_timeout
$output
$secure
$debug
);
# I'm setting these variable with no values to prevent some coding errors.
my $opt_host = '';
my $opt_sp = '';
my $opt_verbose = '';
my $opt_help = '';
my $opt_license = '';
my $opt_checktype = '';
my $opt_pathcount = '';
my $opt_node = '';
my $opt_secfilepath = '';
my $opt_user = '';
my $opt_password = '';
my $opt_lun_id = '';
my $opt_raid_group_id = '';
my $opt_storage_pool_id = '';
my $opt_hot_spare_min_count = 1;
my $output = '';
my $secure = '';
my $opt_debug = '';
my $opt_state= '';
my $opt_lineout= '';
my $opt_timeout= 10;
my $first;
### add some declaration in order to manage the --port option for check_portstate();
my $opt_port;
$opt_port=-1;
# Main values
$PROGNAME = basename($0);
$VERSION = '2015-03-24';
$NAVICLI = '/opt/Navisphere/bin/navicli';
$NAVISECCLI = '/opt/Navisphere/bin/naviseccli';
$NAVICLI_CMD= '';
# Nagios exit states
our %states = (
OK => 0,
WARNING => 1,
CRITICAL => 2,
UNKNOWN => 3
);
# Nagios state names
%state_names = (
0 => 'OK',
1 => 'WARNING',
2 => 'CRITICAL',
3 => 'UNKNOWN'
);
# Checking to see if options have been supplied.
if ( @ARGV == 0 ) {
print_help('jh', 2);
exit ($states{UNKNOWN});
}
# Get the options from cl
Getopt::Long::Configure('bundling');
GetOptions(
'h' => \$opt_help,
'help' => \$opt_help,
'license' => \$opt_license,
'H=s' => \$opt_host,
'node=s' => \$opt_node,
'sp=s' => \$opt_sp,
't=s' => \$opt_checktype,
'warn=i' => \$opt_warn,
'crit=i' => \$opt_crit,
'lun_id=i' => \$opt_lun_id,
'raid_group_id=i' => \$opt_raid_group_id,
'storage_pool_id=i' => \$opt_storage_pool_id,
'secfilepath=s' => \$opt_secfilepath,
'u=s' => \$opt_user,
'p=s' => \$opt_password,
'port=s' => \$opt_port,
'paths=s' => \$opt_pathcount,
'temp_type=s' => \$opt_temp_type,
'minspare=s' => \$opt_hot_spare_min_count,
'debug' => \$opt_debug,
'state' => \$opt_state,
'lineout' => \$opt_lineout,
'T:i' => \$opt_timeout,
) || print_help('warn', 0);
# If somebody wants the help ...
if ($opt_help) {
print_help('jh', 2);
}
# If somebody wants the license ...
if ($opt_license) {
print_license();
}
if ($opt_user) {
$secure = 'u';
}
if ($opt_password) {
$secure = $secure . 'p';
}
if ($opt_secfilepath) {
$secure = $secure . 's';
}
if ($opt_debug) {
$debug = 1;
}
# Check if NAVICLI exists
if (-e $NAVICLI) {
$NAVICLI_CMD="$NAVICLI";
$secure = 0;
}
# Check if NAVISECCLI exists
elsif (-e $NAVISECCLI) {
# Check if secfilepath or user and password for Naviseccli is given
# If it is providen, then it passes in secure mode for the command to the array.
# else we are staying in navicli mode
if ($secure =~ /u/i || $secure =~ /p/i) {
if (!defined($opt_user)) {
# The user argument has not been supplied
print "\nThe -u argument has not been supplied, aborting.\n";
exit ($states{UNKNOWN});
}
elsif (!defined($opt_password)) {
# The password argument was not supplied
print "\nThe -p argument has not been supplied, aborting.\n";
exit ($states{UNKNOWN});
}
else {
$NAVICLI_CMD="$NAVISECCLI -t $opt_timeout -User $opt_user -Password $opt_password -Scope 0";
$secure = 1;
}
}
elsif ($secure =~ /s/i) {
if (!defined($opt_secfilepath)) {
# The secfilepath argument has not been supplied
print "\nThe --secfilepath argument has not been supplied, aborting.\n";
exit($states{UNKNOWN});
}
else {
if (-x $opt_secfilepath && -e "$opt_secfilepath/SecuredCLISecurityFile.xml" && -e "$opt_secfilepath/SecuredCLIXMLEncrypted.key") {
$NAVICLI_CMD="$NAVISECCLI -t $opt_timeout -secfilepath $opt_secfilepath";
$secure = 1;
}
else {
print "\nThe secfilepath $opt_secfilepath does not exist or SecuredCLI files are not created, aborting.\n";
print "\nYou can create the SecuredCLI files with the command:\n";
print "\t\tmkdir <path to SecuredCLI files>\n";
print "\t\t$NAVISECCLI -secfilepath <path to SecuredCLI files> -User <username> -Password <password> -Scope <0 = global 1 = local 2 = LDAP> -AddUserSecurity\n";
exit($states{UNKNOWN});
}
}
}
}
# If neither file exists then we need to exit as Navisphere is not installed
if (! -e $NAVICLI) {
if (! -e $NAVISECCLI) {
print "\nNavisphere does not appear to be installed in /opt/Navisphere/bin/\n";
exit ($states{UNKNOWN});
}
}
# Check if all needed options present
if ( $opt_host && $opt_checktype ) {
# do the work
if ($opt_checktype eq "sp" && $opt_sp ne "") {
check_sp();
}
if ($opt_checktype eq "sp_info") {
get_sp_info();
}
if ($opt_checktype eq "sp_busy") {
check_sp_busy();
}
if ($opt_checktype eq "sp_idle") {
check_sp_idle();
}
if ($opt_checktype eq "sp_cbt_busy" && $opt_sp ne "") {
$opt_sp = uc $opt_sp;
check_sp_cbt_busy();
}
if ($opt_checktype eq "disk") {
check_disk();
}
if ($opt_checktype eq "cache") {
check_cache();
}
if ($opt_checktype eq "cache_pdp") {
check_cache_pdp();
}
if ($opt_checktype eq "faults") {
check_faults();
}
if ($opt_checktype eq "portstate" && $opt_sp ne "") {
check_portstate();
}
if ($opt_checktype eq "hbastate" && $opt_pathcount ne "" && $opt_node ne "") {
check_hbastate();
}
if ($opt_checktype eq "lun" && $opt_lun_id ne "") {
check_lun();
}
if ($opt_checktype eq "raid_group" && $opt_raid_group_id ne "") {
check_raid_group();
}
if ($opt_checktype eq "storage_pool" && $opt_storage_pool_id ne "") {
check_storage_pool();
}
if ($opt_checktype eq "test") {
check_test();
}
if ($opt_checktype eq "temp") {
# Define temperature type if not defined
if (!defined($opt_temp_type)) {
$opt_temp_type = 'c';
get_temperature();
}
else {
# Otherwise check if it's a valid value
if ($opt_temp_type eq 'c' or $opt_temp_type eq 'f' ) {
get_temperature();
}
else {
print "\n--temp_type value \'$opt_temp_type\' is not valid!\n";
}
}
}
print_help('uhoh', 2, 'Wrong parameters specified!');
}
else {
print_help('jh', 2);
}
# -------------------------
# THE SUBS:
# -------------------------
# check_sp();
# check state of the storage processors
sub check_sp {
open (NAVICLIOUT ,"$NAVICLI_CMD -h $opt_host getcrus |");
my $sp_line = 0;
my $error_count = 0;
while (<NAVICLIOUT>) {
# First lets check for errors before proceeding
$first = check_for_errors($_);
if ($_ =~ m/^DPE|^SPE/ ) {
# got an DPE line
$sp_line=1;
}
if ($sp_line == 1) {
# check for SP lines
if( $_ =~ m/^SP\s$opt_sp\s\w+:\s+(\w+)/) {
if ($1 =~ m/(Present|Valid)/) {
$output .= "SP $opt_sp $1,";
}
else {
$output .= "SP $opt_sp failed,";
$error_count++;
}
}
# check for Enclosure lines
if( $_ =~ m/Enclosure\s(\d+|\w+)\s(\w+)\s$opt_sp\d?\s\w+:\s+(\w+)/) {
my $check = $2;
if ($3 =~ m/Present|Valid|N/) {
$output .= "$check ok,";
}
else {
$output .= "$check failed,";
$error_count++;
}
}
# check for Cabling lines
if( $_ =~ m/Enclosure\s(\d+|\w+)\s\w+\s$opt_sp\s(\w+)\s\w+:\s+(\w+)/) {
my $check = $2;
if ($3 =~ m/Present|Valid/) {
$output .= "$check ok";
}
else {
$output .= "$check failed";
$error_count++;
}
}
# end of section
if ( $_ =~ m/^\s*$/) {
$sp_line=0;
}
}
}
close (NAVICLIOUT);
check_exit_val($first);
if ($error_count == 0 && $output ne "") {
$state = 'OK';
}
elsif ($output eq "") {
$output = "UNKNOWN: No output from $NAVICLI";
$state = 'UNKNOWN';
}
else {
$state = 'CRITICAL';
}
$output = $state. ": $output" if $opt_state;
print $output."\n";
exit $states{$state};
} # End sub check_sp {
# get_sp_info();
# gathers SP Information
sub get_sp_info {
my $sp_id = '';
my $sp_agent_rev = '';
my $sp_flare_rev = '';
my $sp_prom_rev = '';
my $sp_model = '';
my $sp_model_type = '';
my $sp_memory_total = '';
my $sp_serial_number = '';
$state = 'OK';
open (NAVICLIOUT ,"$NAVICLI_CMD -h $opt_host getagent -ver -rev -prom -model -type -mem -serial -spid |");
while (<NAVICLIOUT>) {
# First lets check for errors before proceeding
$first = check_for_errors($_);
if ( $_ =~ m/^SP Identifier:\s+(.*)$/) {
$sp_id = $1;
}
if ( $_ =~ m/^Agent Rev:\s+(.*)$/) {
$sp_agent_rev = $1;
}
if ( $_ =~ m/^Revision:\s+(.*)$/) {
$sp_flare_rev = $1;
}
if ( $_ =~ m/^Prom Rev:\s+(.*)$/) {
$sp_prom_rev = $1;
}
if ( $_ =~ m/^Model:\s+(.*)$/) {
$sp_model = $1;
}
if ( $_ =~ m/^Model Type:\s+(.*)$/) {
$sp_model_type = $1;
}
if ( $_ =~ m/^SP Memory:\s+(.*)$/) {
$sp_memory_total = size_format($1*1048576);
}
if ( $_ =~ m/^Serial No:\s+(.*)$/) {
$sp_serial_number = $1;
}
}
close (NAVICLIOUT);
check_exit_val($first);
$output .= "{SP ID:".$sp_id."} {Agent Revision:".$sp_agent_rev."} {FLARE Revision:".$sp_flare_rev."} {PROM Revision:".$sp_prom_rev."} {Model:".$sp_model.", ".$sp_model_type."} {Memory:".$sp_memory_total."} {Serial Number:".$sp_serial_number."}";
$output = $state. ": $output" if $opt_state;
print $output."\n";
exit $states{$state};
} # End sub get_sp_info {
# get_temperature();
# gathers inlet air temperature per enclosure
# Contributed by Max Vernimmen from www.comparegroup.eu
sub get_temperature {
my $perf = '';
$state = 'OK';
open (NAVICLIOUT ,"$NAVICLI_CMD -h $opt_host environment -list -enclosure -intemp $opt_temp_type |");
my $line_nr = 0;
while (<NAVICLIOUT>) {
# First lets check for errors before proceeding
$first = check_for_errors($_);
if ($_ =~ m/^(.+)\s+Bus\s+(.*)\s+Enclosure\s+([0-9]+)\s*$/) {
$output .= "{enclosure: ".$1."} {number: ".$3."} ";
$perf .= "$1-$3=";
}
if ($_ =~ m/^Present\(degree\):\s+([0-9]+)\s*$/) {
$output .= "{inlet air temperature : ".$1." ".$opt_temp_type."}";
$perf .= "$1;;;;";
}
}
close (NAVICLIOUT);
check_exit_val($first);
$output .= "|".$perf;
$output = $state. ": $output" if $opt_state;
print $output."\n";
exit $states{$state};
} # End sub get_temperature {
# check_sp_busy();
# Use of this should be avoided, check_sp_cbt_busy is more accurate
# returns the percentage of how busy the sp is
sub check_sp_busy {
$state = 'OK';
my $errorcheck = 1;
open (NAVICLIOUT ,"$NAVICLI_CMD -h $opt_host getcontrol -busy -idle |");
my $busy_value;
my $idle_value;
while (<NAVICLIOUT>) {
# First lets check for errors before proceeding
$first = check_for_errors($_);
$errorcheck = 2;
#print "\n$_\n\n";
if ( $_ =~ /^Prct Busy:\s+(\d+)/) {
#print "\n$_\n\n";
my @sp_busy_values = split(/:/,$_);
$busy_value = $sp_busy_values[1];
$busy_value =~ s/\s//g;
#print "\n$busy_value\n\n";
}
elsif ( $_ =~ /^Prct Idle:\s+(\d+)/) {
#print "\n$_\n\n";
my @sp_idle_values = split(/:/,$_);
$idle_value = $sp_idle_values[1];
$idle_value =~ s/\s//g;
#print "\n$idle_value\n\n";
}
}
# Check for warning value
no warnings;
if (defined($opt_warn)) {
# Check for critical value
if (defined($opt_crit)) {
# Ensure warning is a smaller value than critical
if ($opt_warn > $opt_crit) {
print_help('uhoh', 2, 'The "warn" value must be smaller than the "crit" value');
}
# Check if critical value has been exceeded
elsif ($busy_value >= $opt_crit) {
$state = 'CRITICAL';
}
# Otherwise check if warning value has been exceeded
elsif ($busy_value >= $opt_warn) {
$state = 'WARNING';
}
}
# If no critical value was defined check if warning value has been exceeded
elsif ($busy_value >= $opt_warn) {
$state = 'WARNING';
}
}
# Check for critical value
if (defined($opt_crit) && !defined($opt_warn)) {
# Check if critical value has been exceeded
if ($busy_value >= $opt_crit) {
$state = 'CRITICAL';
}
}
close (NAVICLIOUT);
check_exit_val($first);
if ($errorcheck==1) {
$state = 'UNKNOWN';
exit $states{$state};
}
else {
$output .= "SP is $busy_value% Busy|SP Busy=$busy_value%;$opt_warn;$opt_crit;; SP Idle=$idle_value%;;;;";
print $state . ": " . $output."\n";
}
use warnings;
exit $states{$state};
} # End sub check_sp_busy {
# check_sp_idle();
# Use of this should be avoided, check_sp_cbt_busy is more accurate
# returns the percentage of how idle the sp is
sub check_sp_idle {
$state = 'OK';
my $errorcheck = 1;
open (NAVICLIOUT ,"$NAVICLI_CMD -h $opt_host getcontrol -idle -busy |");
my $idle_value;
my $busy_value;
while (<NAVICLIOUT>) {
# First lets check for errors before proceeding
$first = check_for_errors($_);
$errorcheck = 2;
#print "\n$_\n\n";
if ( $_ =~ /^Prct Idle:\s+(\d+)/) {
#print "\n$_\n\n";
my @sp_idle_values = split(/:/,$_);
$idle_value = $sp_idle_values[1];
$idle_value =~ s/\s//g;
#print "\n$idle_value\n\n";
}
elsif ( $_ =~ /^Prct Busy:\s+(\d+)/) {
#print "\n$_\n\n";
my @sp_busy_values = split(/:/,$_);
$busy_value = $sp_busy_values[1];
$busy_value =~ s/\s//g;
#print "\n$busy_value\n\n";
}
}
# Check for warning value
no warnings;
if (defined($opt_warn)) {
# Check for critical value
if (defined($opt_crit)) {
# Ensure warning is a larger value than critical
if ($opt_warn < $opt_crit) {
print_help('uhoh', 2, 'The "warn" value must be larger than the "crit" value');
}
# Check if critical value has been exceeded
elsif ($idle_value <= $opt_crit) {
$state = 'CRITICAL';
}
# Otherwise check if warning value has been exceeded
elsif ($idle_value <= $opt_warn) {
$state = 'WARNING';
}
}
# If no critical value was defined check if warning value has been exceeded
elsif ($idle_value <= $opt_warn) {
$state = 'WARNING';
}
}
# Check for critical value
if (defined($opt_crit) && !defined($opt_warn)) {
# Check if critical value has been exceeded
if ($idle_value <= $opt_crit) {
$state = 'CRITICAL';
}
}
close (NAVICLIOUT);
check_exit_val($first);
if (!defined($opt_warn)) {
my $opt_warn = "";
}
if (!defined($opt_crit)) {
my $opt_crit = "";
}
if ($errorcheck==1) {
$state = 'UNKNOWN';
exit $states{$state};
}
else {
$output .= "SP is $idle_value% Idle|SP Idle=$idle_value%;$opt_warn;$opt_crit;; SP Busy=$busy_value%;;;;";
print $state . ": " . $output."\n";
}
use warnings;
exit $states{$state};
} # End sub check_sp_idle {
sub check_test {
$state = 'OK';
my $opt_host_uc = uc $opt_host;
print "\n$opt_host_uc\n";
exit $states{$state};
} # End sub check_test {
# check_sp_cbt_busy();
# returns the percentage of how busy the sp is
sub check_sp_cbt_busy {
$state = 'OK';
my $errorcheck = 1;
my $opt_host_uc = uc $opt_host;
my $cbtbusy_tmp_file = '/tmp/check_emc_clariion_cbtbusy_'.$opt_host_uc.'_'.$opt_sp.'_tmp.txt';
my $cbtbusy_tmp_file_exists = 1;
my $cbt_busy_value_old;
my $cbt_idle_value_old;
my $cbtbusy_tmp_file_line = 1;
if (-e $cbtbusy_tmp_file) {
open TEMPFILE_CONTENTS, '<', $cbtbusy_tmp_file;
while (<TEMPFILE_CONTENTS>) {
if ($cbtbusy_tmp_file_line == 1) {
$cbt_busy_value_old = $_;
#print "Busy OLD \n$cbt_busy_value_old\n";
}
if ($cbtbusy_tmp_file_line == 2) {
$cbt_idle_value_old = $_;
#print "Idle OLD \n$cbt_idle_value_old\n";
}
$cbtbusy_tmp_file_line++
}
close TEMPFILE_CONTENTS;
$cbtbusy_tmp_file_exists = 2;
}
open (NAVICLIOUT ,"$NAVICLI_CMD -h $opt_host getcontrol -cbt |");
my $cbt_busy_value_new;
my $cbt_busy_value;
my $cbt_idle_value_new;
my $malform_check = 1;
while (<NAVICLIOUT>) {
# First lets check for errors before proceeding
$first = check_for_errors($_);
$errorcheck = 2;
#print "\n$_\n\n";
if ( $_ =~ /^Controller busy ticks:\s+(\d+)/) {
#print "\n$_\n\n";
my @sp_cbt_busy_values = split(/:/,$_);
$cbt_busy_value_new = $sp_cbt_busy_values[1];
$cbt_busy_value_new =~ s/\s//g;
#print "\n$cbt_busy_value_new\n\n";
#Checking to see if the returned value is a negative number
if ($cbt_busy_value_new < 0) {
$malform_check = 2;
}
}
elsif ( $_ =~ /^Controller idle ticks:\s+(\d+)/) {
#print "\n$_\n\n";
my @sp_cbt_idle_values = split(/:/,$_);
$cbt_idle_value_new = $sp_cbt_idle_values[1];
$cbt_idle_value_new =~ s/\s//g;
#print "\n$cbt_idle_value_new\n\n";
#Checking to see if the returned value is a negative number
if ($cbt_idle_value_new < 0) {
$malform_check = 2;
}
}
}
close (NAVICLIOUT);
check_exit_val($first);
#If any of the values are negative then abort
if ($malform_check == 2) {
$output .= "Waiting for more data to be collected";
print $state . ": " . $output."\n";
exit $states{$state};
}
if ($cbtbusy_tmp_file_exists == 2) {
my $cbt_busy_diff = $cbt_busy_value_new - $cbt_busy_value_old;
my $cbt_idle_diff = $cbt_idle_value_new - $cbt_idle_value_old;
my $cbt_total_diff = $cbt_busy_diff + $cbt_idle_diff;
# Checking values to avoide divide by zero errors
if ($cbt_busy_diff == 0 && $cbt_total_diff == 0) {
$cbt_busy_value = 0;
}
else {
$cbt_busy_value = sprintf("%.2f", ($cbt_busy_diff / $cbt_total_diff) * 100);
}
#If the calculated percentage is over 100% then start data collection from scratch
if ($cbt_busy_value > 100) {
unlink($cbtbusy_tmp_file);
$output .= "Waiting for more data to be collected";
print $state . ": " . $output."\n";
exit $states{$state};
}
}
# Check for warning value
no warnings;
if ($cbtbusy_tmp_file_exists == 2) {
if (defined($opt_warn)) {
# Check for critical value
if (defined($opt_crit)) {
# Ensure warning is a smaller value than critical
if ($opt_warn > $opt_crit) {
print_help('warn', 2, 'The "warn" value must be smaller than the "crit" value');
}
# Check if critical value has been exceeded
elsif ($cbt_busy_value >= $opt_crit) {
$state = 'CRITICAL';
}
# Otherwise check if warning value has been exceeded
elsif ($cbt_busy_value >= $opt_warn) {
$state = 'WARNING';
}
}
# If no critical value was defined check if warning value has been exceeded
elsif ($cbt_busy_value >= $opt_warn) {
$state = 'WARNING';
}
}
# Check for critical value
if (defined($opt_crit) && !defined($opt_warn)) {
# Check if critical value has been exceeded
if ($cbt_busy_value >= $opt_crit) {
$state = 'CRITICAL';
}
}
}
if (!defined($opt_warn)) {
my $opt_warn = "";
}
if (!defined($opt_crit)) {
my $opt_crit = "";
}
if ($errorcheck!=1) {
open TEMPFILE_CONTENTS, ">$cbtbusy_tmp_file";
print TEMPFILE_CONTENTS "$cbt_busy_value_new\n";
print TEMPFILE_CONTENTS "$cbt_idle_value_new\n";
close TEMPFILE_CONTENTS;
}
if ($errorcheck==1) {
$state = 'UNKNOWN';
exit $states{$state};
}
elsif ($cbtbusy_tmp_file_exists == 1) {
$output .= "Waiting for more data to be collected";
print $state . ": " . $output."\n";
}
else {
$output .= "SP".$opt_sp." % Busy is ".$cbt_busy_value."%|'SP".$opt_sp." % Busy'=".$cbt_busy_value."%;".$opt_warn.";".$opt_crit.";;";
print $state . ": " . $output."\n";
}
use warnings;
exit $states{$state};
} # End sub check_sp_cbt_busy {
# check_disk();
# check state of the disks
sub check_disk {
my $disk_line = 0;
my $crit_count = 0;
my $warn_count = 0;
my $hotspare_count = 0;
my $disk_ok_count = 0;
my ($bus,$enclosure,$disk) = 0;
$state = 'UNKNOWN';
open (NAVICLIOUT ,"$NAVICLI_CMD -h $opt_host getdisk -state |");
while (<NAVICLIOUT>) {
# First lets check for errors before proceeding
$first = check_for_errors($_);
# check for disk lines
if( $_ =~ m/^Bus\s(\d+)\s\w+\s(\d+)\s+\w+\s+(\d+)/) {
$bus = $1;
$enclosure = $2;
$disk = $3;
$disk_line=1;
}
if ($disk_line == 1) {
# check for States lines
if( $_ =~ m/^State:\s+(.*)$/) {
my $status = $1;
if ($status =~ m/Hot Spare Ready/) {
$hotspare_count++;
$disk_ok_count++;
}
elsif ($status =~ m/Binding|Enabled|Expanding|Unbound|Powering Up|Ready/) {
$disk_ok_count++;
}
elsif ($status =~ m/Empty/) {