As I wrote before, we have a bunch of filers (and a ton of volumes w/ luns on them), that I need to monitor. At first, I tried the existing NetApp Nagios-Plugin(s), but they all use SNMP and with that I can either watch all volumes or none. And that didn’t satisfy me.
Don’t get me wrong, the existing plugins are okay and I still use them for stuff (like GLOBALSTATUS or FAN/CPU/POWER) which isn’t present in the API or real hard to get at, however I wanted more. So I ended up looking at the NetApp API, and ended up writing a “short” plugin for Nagios using Perl.
Maybe if I’m ever bored, I’ll rewrite it using C, but for now the Perl plugin has to suffice.
So far the plugin supports the following things:
- Monitoring FlexVolumes (simply watching the free space)
- Monitoring LUN space (the allocated space inside a FlexVolume for iSCSI/FC LUNs)
- Monitoring Snapshot space (the allocated space inside a FlexVolume for Snapshots)
- Monitoring SnapVault relations (and their age)
- Monitoring SnapMirror relations (and their age)
The plugin will return performance data for most (if not all) of those classes. It needs a user on the filer you wish to monitor – which sadly needs to have the admin role.
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 |
#!/usr/bin/perl -w # check_netapp-volume is a Nagios plugin to monitor a single volume # and it's occupied space. # Copyright (c) 2013, Christian Thomas Heim <christian.heim@barfoo.org> # # This module is free software; you can redistribute it and/or modify it # under the terms of GNU General Public License (GPL) version 3. use strict; use warnings; use lib "/usr/lib/perl5/site_perl/5.10.0/NetApp"; use NaServer; use NaElement; use Nagios::Plugin; use File::Basename; # IMPORTANT: Nagios plugins could be executed using embedded perl in this case # the main routine would be executed as a subroutine and all the # declared subroutines would therefore be inner subroutines # This will cause all the global lexical variables not to stay shared # in the subroutines! # # All variables are therefore declared as package variables... use vars qw( $VERSION $PROGNAME $plugin $verbose $WAFL_VOL_RESERVE ); $VERSION = '0.1'; $PROGNAME = basename($0); $WAFL_VOL_RESERVE = '1.03'; $plugin = Nagios::Plugin->new( usage=> "Usage: %s --hostname=<hostname> --cliuser=<cliuser> --clipassword=<clipassword> --flexvol=<volumename> ( -w|--warning=<warningthreshold> ) ( -c|--critical=<criticalthreshold> ) ( --snapreserve ) ( --lunspace ) ( --free ) ( --snapvault ) ( --snapmirror ) ( --aggr=aggr0 )", version => $VERSION, blurb => 'This plugin checks a single volume for it\'s occupied space', license => "This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. It may be used, redistributed and/or modified under the terms of the GNU General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).", extra => " Examples: Checking the free space of a FlexVolume (default): $PROGNAME -H 10.0.0.35 -u root -p toaster123 --flexvol=sles_boot --free -w 85 -c 92 Checking the amount of lun space for a FlexVolume: $PROGNAME -H 10.0.0.35 -u root -p toaster123 --flexvol=sles_boot --lunspace Checking the Snap Reserve of a FlexVolume: $PROGNAME -H 10.0.0.35 -u root -p toaster123 --flexvol=sles_boot --snapreserve -w 80 -c 92 Checking the SnapVault age of a Qtree-transfer: $PROGNAME -H 10.0.0.35 -u root -p toaster123 --flexvol=sles_boot --snapvault -w 24 -c 26 Checking the SnapMirror age of a Qtree-transfer: $PROGNAME -H 10.0.0.35 -u root -p toaster123 --flexvol=sles_boot --snapmirror -w 24 -c 26 Checking the free space of an aggregate: $PROGNAME -H 10.0.0.35 -u root -p toaster123 --aggr=aggr0 -w 85 -c 92 " ); $plugin->add_arg( spec => 'hostname|H=s', help => qq{-H, --hostname=STRING Hostname/IP-Adress to use for the check.}, required => 1, ); $plugin->add_arg( spec => 'cliuser=s', help => qq{--cliuser=STRING Username for CLI/API access.}, required => 1, ); $plugin->add_arg( spec => 'clipassword=s', help => qq{--clipassword=STRING Password for CLI/API access.}, required => 1, ); $plugin->add_arg( spec => 'flexvol=s', help => qq{-f, --flexvol=STRING FlexVolume that should be checked.}, required => 0, ); $plugin->add_arg( spec => 'aggr=s', help => qq{-a, --aggr=STRING Aggregate that should be checked.}, required => 0, ); $plugin->add_arg( spec => 'snapreserve', help => qq{--snapreserve Check the Snap Reserve of the selected volume.}, required => 0, ); $plugin->add_arg( spec => 'lunspace', help => qq{--lunspace Check if all LUNs and the Snapshot reserve fit into the volume.}, required => 0, ); $plugin->add_arg( spec => 'snapvault', help => qq{--snapvault Check the SnapVault age of a Qtree-SnapVault transfer.}, required => 0, ); $plugin->add_arg( spec => 'snapmirror', help => qq{--snapmirror Check the SnapMirror age of a Qtree-SnapVault transfer.}, required => 0, ); $plugin->add_arg( spec => 'sis', help => qq{--sis Check the Deduplication information.}, required => 0, ); $plugin->add_arg( spec => 'free', help => qq{--free Check the free space of a volume.}, required => 0, ); $plugin->add_arg( spec => 'warning|w=i', help => qq{-i, --warning=INTEGER Free space left in percent that should be considered WARNING.}, required => 0, ); $plugin->add_arg( spec => 'critical|c=i', help => qq{-c, --critical=INTEGER Free space left in percent that should be considered CRITICAL.}, required => 0, ); # Parse arguments and process standard ones (e.g. usage, help, version) $plugin->getopts; my ( $hostname, $username, $password, $aggregate, $flexvol, $warning, $critical, $stdout, $filer, $mode ); $hostname = $plugin->opts->hostname; $aggregate = $plugin->opts->aggr; $flexvol = $plugin->opts->flexvol; $username = $plugin->opts->cliuser; $password = $plugin->opts->clipassword; $warning = $plugin->opts->warning; $critical = $plugin->opts->critical; $verbose = $plugin->opts->verbose; if ( defined $plugin->opts->aggr ) { $mode = "aggregate"; } elsif ( defined $plugin->opts->lunspace ) { $mode = "lunspace"; } elsif ( defined $plugin->opts->snapreserve ) { $mode = "snapreserve"; } elsif ( defined $plugin->opts->snapvault ) { $mode = "snapvault"; } elsif ( defined $plugin->opts->snapmirror ) { $mode = "snapmirror"; } elsif ( defined $plugin->opts->sis ) { $mode = "sis"; } elsif ( defined $plugin->opts->free ) { $mode = "volspace"; } else { $mode = "volspace"; } $filer = NaServer->new($hostname, 1, 3); $stdout = $filer->set_style("LOGIN"); if (ref ($stdout) eq "NaElement" && $stdout->results_errno != 0 ) { $plugin->nagios_exit(UNKNOWN, "Unable to set login type. ". $stdout->results_reason()); } $filer->set_admin_user($username, $password); $stdout = $filer->set_transport_type("HTTPS"); if (ref ($stdout) eq "NaElement" && $stdout->results_errno != 0 ) { $plugin->nagios_exit(UNKNOWN, "Unable to set transport to HTTPS. ". $stdout->results_reason() ); } sub byteconv($) { my $c = shift; $c >= 1073741824 ? sprintf("%0.2fTB", $c/1073741824) : $c >= 1048576 ? sprintf("%0.2fGB", $c/1048576) : $c >= 1024 ? sprintf("%0.2fMB", $c/1024) : $c . "B"; } sub timeconv($) { my $secs = shift; if ($secs >= 365*24*60*60) { return sprintf '%.1f years', $secs/(365*24*60*60) } elsif ($secs >= 24*60*60) { return sprintf '%.1f days', $secs/(24*60*60) } elsif ($secs >= 60*60) { return sprintf '%.1f hours', $secs/(60*60) } elsif ($secs >= 60) { return sprintf '%.1f minutes', $secs/(60) } else { return sprintf '%.1f seconds', $secs } } sub aggrspaceinfo { my $session = $_[0]; my $aggr = $_[1]; my $out; my $status; my @result; my $aggrinfo; my $aggr_size; my $aggr_free; my $aggr_used; my $aggr_vol_alloc; my $aggr_vol_used; my %aggri = (); $out = $session->invoke("aggr-space-list-info", "aggregate", $aggr); if ($out->results_status() eq "failed") { $plugin->nagios_exit(UNKNOWN, $out->results_reason()); } $status = $out->child_get("aggregates"); if ($status->children_get() eq 0) { # snapreserve might be 0 } elsif ($status) { @result = $status->children_get(); } else { $plugin->nagios_exit(UNKNOWN, "Unable to process result."); } foreach $aggrinfo (@result){ $aggr_size = $aggrinfo->child_get_string("size-nominal")/1024; $aggr_free = $aggrinfo->child_get_string("size-free")/1024; $aggr_used = $aggrinfo->child_get_string("size-used")/1024; $aggr_vol_alloc = $aggrinfo->child_get_string("size-volume-allocated")/1024; $aggr_vol_used = $aggrinfo->child_get_string("size-volume-used")/1024; if ($verbose) { print("aggr_size: ". byteconv($aggr_size) ."\n"); print("aggr_used: ". byteconv($aggr_used) ."\n"); print("aggr_free: ". byteconv($aggr_free) ."\n"); print("aggr_vol_allocated: ". byteconv($aggr_vol_alloc) ."\n"); print("aggr_vol_used: ". byteconv($aggr_vol_used) ."\n"); } } $aggri{"aggr_size"} = $aggr_size; $aggri{"aggr_free"} = $aggr_free; $aggri{"aggr_used"} = $aggr_used; $aggri{"aggr_vol_alloc"} = $aggr_vol_alloc; $aggri{"aggr_vol_used"} = $aggr_vol_used; return (\%aggri); } sub snaplistinfo { my $session = $_[0]; my $vol = $_[1]; my $out; my $status; my @result; my $snapinfo; my $snap_used; my $snap_cumulative; my %snapi = (); $out = $session->invoke("snapshot-list-info", "target-type", "volume", "target-name", $vol); if ($out->results_status() eq "failed") { $plugin->nagios_exit(UNKNOWN, $out->results_reason()); } $status = $out->child_get("snapshots"); if ($status->children_get() eq 0) { # snapreserve might be 0 } elsif ($status) { @result = $status->children_get(); } else { $plugin->nagios_exit(UNKNOWN, "Unable to process result."); } foreach $snapinfo (@result){ $snap_used += $snapinfo->child_get_string("total"); if ($verbose) { print("snap_name: ". $snapinfo->child_get_string("name") ."\n"); print("snap_size: ". byteconv($snapinfo->child_get_string("total")) ."\n"); print("snap_used: " . byteconv($snap_used) ."\n"); } } # Another fix for API misbehaviour. If there are no snapshots inside # a volume, the API returns nothing ... if ( !$snap_used ) { $snap_used = "0" }; $snapi{"snap_total"} = $snap_used; return (\%snapi); } sub vollistinfo { my $session = $_[0]; my $vol = $_[1]; my $out; my $status; my @result; my $volinfo; my %voli; my $vol_size_avail; my $vol_size_used; my $vol_size_total; my $vol_snap_reserve; $out = $session->invoke("volume-list-info", "volume", $vol); if ($out->results_status() eq "failed") { $plugin->nagios_exit(UNKNOWN, $out->results_reason()); } $status = $out->child_get("volumes"); if ($status->children_get() eq 0) { # No output $plugin->nagios_exit(UNKNOWN, "FlexVol not found."); } elsif ($status) { @result = $status->children_get(); } else { $plugin->nagios_exit(UNKNOWN, "Unable to process result."); } # Get the total size used in this volume for luns foreach $volinfo (@result){ if ($verbose) { print("vol-size-avail: " . byteconv($volinfo->child_get_string("size-available")/1024) ."\n"); print("vol-size-used: " . byteconv($volinfo->child_get_string("size-used")/1024) ."\n"); print("vol-size-total: " . byteconv($volinfo->child_get_string("size-total")/1024) ."\n"); print("snapshot-blocks-reserved: " . byteconv($volinfo->child_get_string("snapshot-blocks-reserved")) ."\n"); print("snapshot-percent-reserved: " . $volinfo->child_get_string("snapshot-percent-reserved") ."\n"); } $vol_size_avail = $volinfo->child_get_string("size-available")/1024; $vol_size_used = $volinfo->child_get_string("size-used")/1024; $vol_size_total = $volinfo->child_get_string("size-total")/1024; $vol_snap_reserve = $volinfo->child_get_string("snapshot-blocks-reserved"); } $voli{"vol_size_avail"} = $vol_size_avail; $voli{"vol_size_used"} = $vol_size_used; $voli{"vol_size_total"} = $vol_size_total; $voli{"vol_snap_reserve"} = $vol_snap_reserve; return (\%voli); } sub lunlistinfo { my $session = $_[0]; my $vol = $_[1]; my $out; my $status; my @result; my $luninfo; my $lunsize_total; my $lunsize_used; my %luni = (); $out = $session->invoke("lun-list-info", "volume-name", $vol); if ($out->results_status() eq "failed") { $plugin->nagios_exit(UNKNOWN, $out->results_reason()); } $status = $out->child_get("luns"); if ($status->children_get() eq 0) { # No output $plugin->nagios_exit(UNKNOWN, "FlexVol not found."); } elsif ($status) { @result = $status->children_get(); } else { $plugin->nagios_exit(UNKNOWN, "Unable to process result."); } # Get the total size used in this volume for luns foreach $luninfo (@result){ if ($verbose) { print("alignment: " . $luninfo->child_get_string("alignment") ."\n"); print("mapped: " . $luninfo->child_get_string("mapped") ."\n"); print("online: " . $luninfo->child_get_string("online") ."\n"); print("lun-size: " . byteconv($luninfo->child_get_string("size")/1024) ."\n"); print("lun-size-used: " . byteconv($luninfo->child_get_string("size-used")/1024) ."\n"); } $lunsize_total += $luninfo->child_get_string("size")/1024; $lunsize_used += $luninfo->child_get_string("size-used")/1024; } if ( $lunsize_used > $lunsize_total ) { my $tmp_used = $lunsize_used; my $tmp_total = $lunsize_total; if ($verbose) { print("lun-size(rewritten): ". byteconv($tmp_total) ."\n"); print("lun-size-used(rewritten): ". byteconv($tmp_used) ."\n"); } $lunsize_total = $tmp_used; $lunsize_used = $tmp_total; } $luni{"lun_size_total"} = $lunsize_total; $luni{"lun_size_used"} = $lunsize_used; $luni{"lun_size_free"} = $lunsize_total - $lunsize_used; return (\%luni); } sub snapvaultinfo { my $session = $_[0]; my $vol = $_[1]; # Define all variables used in this sub-routine as local thus avoiding # variable clashing and other - potential dangerous stuff my $out; my $status; my @result; my $sv_state; my $sv_status; my $sv_progress; my $sv_lag_time; my $sv_error; my $svinfo; my %svi = (); # Run the API command with the full vol-path constructed as /vol/$flexvol/sv $out = $session->invoke("snapvault-primary-get-relationship-status", "system-path", "/vol/". $vol ."/sv"); # If results_status equals failed, die. if ($out->results_status() eq "failed") { $plugin->nagios_exit(UNKNOWN, $out->results_reason()); } # Get the API status element $status = $out->child_get("status"); # Die if children_get equals 0, otherwise fill the array if ($status->children_get() eq 0) { $plugin->nagios_exit(UNKNOWN, "FlexVol not found."); } elsif ($status) { @result = $status->children_get(); } else { $plugin->nagios_exit(UNKNOWN, "Unable to process result."); } # Walk through each array element (there should only be one, as we # explicitly selected only a single volume) foreach $svinfo (@result){ $sv_state = $svinfo->child_get_string("state"); $sv_status = $svinfo->child_get_string("status"); $sv_progress = $svinfo->child_get_string("transfer-progress"); $sv_lag_time = $svinfo->child_get_string("lag-time"); $sv_error = $svinfo->child_get_string("current-transfer-error"); } # Sadly the API isn't written that well ... if there is no current-transfer-error # the whole element doesn't exist. So in order that we get through 'use strict' # we need a small hack. if ( !$sv_error ) { $sv_error = "none" }; if ( !$sv_progress ) { $sv_progress = "none" }; if ( !$sv_lag_time ) { $sv_lag_time = 0 }; if ( $verbose ) { print("sv_state: $sv_state\n"); print("sv_status: $sv_status\n"); print("sv_lag-time: ". $sv_lag_time ."s\n"); print("sv_progress: $sv_progress\n"); print("sv_transfer-error: $sv_error\n"); } # Add the below values as hash elements $svi{"sv_state"} = $sv_state; $svi{"sv_status"} = $sv_status; $svi{"sv_progress"} = $sv_progress; $svi{"sv_lag_time"} = $sv_lag_time; $svi{"sv_error"} = $sv_error; # Return the hash return (\%svi); } sub snapmirrorinfo { my $session = $_[0]; my $vol = $_[1]; # Define all variables used in this sub-routine as local thus avoiding # variable clashing and other - potential dangerous stuff my $out; my $status; my @result; my $sm_state; my $sm_status; my $sm_progress; my $sm_lag_time; my $sm_error; my $sminfo; my %smi = (); # Run the API command with the FlexVol name $out = $session->invoke("snapmirror-get-status", "location", $vol); # If results_status equals failed, die. if ($out->results_status() eq "failed") { $plugin->nagios_exit(UNKNOWN, $out->results_reason()); } # Get the API status element $status = $out->child_get("snapmirror-status"); # Die if $status is unset, otherwise fill the array if ($status) { @result = $status->children_get(); } else { $plugin->nagios_exit(UNKNOWN, "Unable to process result."); } # Walk through each array element (there should only be one, as we # explicitly selected only a single volume) foreach $sminfo (@result){ $sm_state = $sminfo->child_get_string("state"); $sm_status = $sminfo->child_get_string("status"); $sm_progress = $sminfo->child_get_string("transfer-progress"); $sm_lag_time = $sminfo->child_get_string("lag-time"); $sm_error = $sminfo->child_get_string("current-transfer-error"); } # Sadly the API isn't written that well ... if there is no current-transfer-error # the whole element doesn't exist. So in order that we get through 'use strict' # we need a small hack. if ( !$sm_error ) { $sm_error = "none" }; if ( !$sm_progress ) { $sm_progress = 0 }; if ( $verbose ) { print("sm_state: $sm_state\n"); print("sm_status: $sm_status\n"); print("sm_lag-time: ". $sm_lag_time ."s\n"); print("sm_progress: $sm_progress\n"); print("sm_transfer-error: $sm_error\n"); } # Add the below values as hash elements $smi{"sm_state"} = $sm_state; $smi{"sm_status"} = $sm_status; $smi{"sm_progress"} = $sm_progress; $smi{"sm_lag_time"} = $sm_lag_time; $smi{"sm_error"} = $sm_error; # Return the hash return (\%smi); } sub sisinfo { my $session = $_[0]; my $vol = $_[1]; # Define all variables used in this sub-routine as local thus avoiding # variable clashing and other - potential dangerous stuff my $out; my $status; my @result; my $sis_state; my $sis_changelog_usage; my $sis_stale_fingerprint; my $sis_last_operation_end; my $sis_last_success_operation; my $sisinfo; my %sis = (); # Run the API command with the FlexVol name $out = $session->invoke("sis-status", "path", '/vol/'.$vol, "verbose", "true"); # If results_status equals failed, die. if ($out->results_status() eq "failed") { $plugin->nagios_exit(UNKNOWN, $out->results_reason()); } # Get the API status element $status = $out->child_get("sis-object"); # Die if $status is unset, otherwise fill the array if ($status) { @result = $status->children_get(); } else { $plugin->nagios_exit(UNKNOWN, "Unable to process result."); } # Walk through each array element (there should only be one, as we # explicitly selected only a single volume) foreach $sisinfo (@result){ $sis_state = $sisinfo->child_get_string("state"); $sis_stale_fingerprint = $sisinfo->child_get_string("stale-fingerprint-percentage"); $sis_changelog_usage = $sisinfo->child_get_string("changelog-used-percent"); $sis_last_operation_end = $sisinfo->child_get_string("last-operation-end-timestamp"); $sis_last_success_operation = $sisinfo->child_get_string("last-success-operation-end-timestamp"); } if ( $verbose ) { print("sis_state $sis_state\n"); print("sis_changelog_usage $sis_changelog_usage\n"); print("sis_stale_fingerprint $sis_stale_fingerprint\n"); print("sis_last_operation_end ".scalar(localtime($sis_last_operation_end))."\n"); print("sis_last_success_operation ".scalar(localtime($sis_last_success_operation))."\n"); print("timestamps:\n"); print("sis_last_operation_end: $sis_last_operation_end\n"); print("sis_last_success_operation: $sis_last_success_operation\n"); print("current_time: ".time."\n"); } # Add the below values as hash elements $sis{"sis_state"} = $sis_state; $sis{"sis_changelog_usage"} = $sis_changelog_usage; $sis{"sis_stale_fingerprint"} = $sis_stale_fingerprint; $sis{"sis_last_operation_end"} = $sis_last_operation_end; $sis{"sis_last_success_operation"} = $sis_last_success_operation; # Return the hash return (\%sis); } if ( $mode eq "aggregate" ) { # Get the aggregate information my $info = aggrspaceinfo($filer, $aggregate); my $aggr_size = $info->{"aggr_size"}; my $aggr_free = $info->{"aggr_free"}; my $aggr_used = $info->{"aggr_used"}; my $aggr_vol_alloc = $info->{"aggr_vol_alloc"}; my $aggr_vol_used = $info->{"aggr_vol_used"}; $plugin->set_thresholds( warning => $warning, critical => $critical, ); $plugin->add_perfdata( label => "aggr_size", value => $aggr_size, uom => 'KB', ); $plugin->add_perfdata( label => "aggr_free", value => $aggr_free, uom => 'KB', ); $plugin->add_perfdata( label => "aggr_used", value => $aggr_used, uom => 'KB', ); $plugin->add_perfdata( label => "aggr_vol_alloc", value => $aggr_vol_alloc, uom => 'KB', ); # Calculate the warning threshold if (defined $warning) { $warning = sprintf "%.0f", $aggr_size / 100 * $warning; if ($verbose) { print("warning: ". $warning ."\n") }; } # Calculate the critical threshold if (defined $critical) { $critical = sprintf "%.0f", $aggr_size / 100 * $critical; if ($verbose) { print("critical: ". $critical ."\n") }; } if ( defined $warning && defined $critical ) { if ( ($aggr_used > $warning) && ($aggr_used < $critical) ) { $plugin->nagios_exit(WARNING, "Aggregate ". $aggregate ." has grown above the defined WARNING threshold (". byteconv($warning) .")."); } if ( ($aggr_used > $warning) && ($aggr_used > $critical) ) { $plugin->nagios_exit(CRITICAL, "Aggregate ". $aggregate ." has grown above the defined CRITICAL threshold (". byteconv($warning) .")."); } if ( ($critical > $aggr_used) && ($warning > $aggr_used) && ($aggr_size > $aggr_used) ) { $plugin->nagios_exit(OK, "Aggregate ". $aggregate ." is ok."); } } else { # Check the volume allocation if ( ($aggr_vol_alloc > $aggr_size) && ($aggr_vol_used < $aggr_size) ) { $plugin->nagios_exit(WARNING, "Aggregate ". $aggregate ." is overcommited, but has enough free space to accomodate all volumes for now."); } if ( ($aggr_vol_alloc < $aggr_vol_used) || ($aggr_size > $aggr_used) ) { $plugin->nagios_exit(OK, "Aggregate ". $aggregate ." is ok."); } } } elsif ( $mode eq "lunspace" ) { # Get a list of all luns and sum them up # Get the snapreserve my $luns = lunlistinfo($filer, $flexvol); my $vols = vollistinfo($filer, $flexvol); my $snap = snaplistinfo($filer, $flexvol); # lun info my $lun_avail = $luns->{"lun_size_free"}; my $lun_used = $luns->{"lun_size_used"}; my $lun_total = $luns->{"lun_size_total"}; # vol info (Data Space) my $vol_avail = $vols->{"vol_size_avail"}; my $vol_used = $vols->{"vol_size_used"}; my $vol_total = $vols->{"vol_size_total"}; # snap info (Snapshot Reserve) my $snap_avail = $vols->{"vol_snap_reserve"} - $snap->{"snap_total"}; my $snap_used = $snap->{"snap_total"}; my $snap_total = $vols->{"vol_snap_reserve"}; # flex info my $flex_used = $vol_used + $snap_used; my $flex_total = $vol_total + $snap_total; my $flex_avail = $flex_total - $flex_used; $plugin->add_perfdata( label => "lun_total", value => $lun_total, uom => 'KB', ); $plugin->add_perfdata( label => "lun_used", value => $lun_used, uom => 'KB', ); $plugin->add_perfdata( label => "lun_avail", value => $lun_avail, uom => 'KB', ); $plugin->add_perfdata( label => "vol_total", value => $vol_total, uom => 'KB', ); $plugin->add_perfdata( label => "vol_used", value => $vol_used, uom => 'KB', ); $plugin->add_perfdata( label => "vol_avail", value => $vol_avail, uom => 'KB', ); $plugin->add_perfdata( label => "flex_total", value => $flex_total, uom => 'KB', ); $plugin->add_perfdata( label => "flex_used", value => $flex_used, uom => 'KB', ); $plugin->add_perfdata( label => "flex_avail", value => $flex_avail, uom => 'KB', ); $plugin->add_perfdata( label => "snap_total", value => $snap_total, uom => 'KB', ); $plugin->add_perfdata( label => "snap_used", value => $snap_used, uom => 'KB', threshold => $plugin->threshold, ); $plugin->add_perfdata( label => "snap_avail", value => $snap_avail, uom => 'KB', threshold => $plugin->threshold, ); # Only consider snapshot reserve stuff if it is above 0 if ( $snap_total > 0 ) { # FlexVol still has space left if ( ($lun_used + $snap_used) < $flex_total ) { if ( $snap_used >= $snap_total && $lun_used < $lun_total ) { $plugin->nagios_exit(WARNING, "Snapshot Reserve lending space from Data space. Missing capacity: ". byteconv($snap_used-$snap_total)); } if ( $lun_used >= $lun_total && $snap_used < $snap_total ) { $plugin->nagios_exit(WARNING, "Data Space lending space from Snapshot Reserve. Missing capacity: ". byteconv($lun_used-$lun_total)); } if ( $lun_used < $lun_total && $snap_used < $snap_total ) { $plugin->nagios_exit(OK, "Data Space (". byteconv($lun_total) .") and Snapshot Reserve (". byteconv($snap_total) .") fit into FlexVol (". byteconv($flex_total). "). "); } } else { $plugin->nagios_exit(CRITICAL, "Data Space and Snapshot Reserve are out out space. Missing capacity (Data): ". byteconv($lun_used-$lun_total) ." (Snap): ". byteconv($snap_used-$snap_total)); } } if ( $snap_total == 0 ) { # FlexVol still has space left if ( $lun_used < $flex_total && $lun_used < $lun_total ) { $plugin->nagios_exit(OK, "Data Space (". byteconv($lun_total) .") and Snapshot Reserve (". byteconv($snap_total) .") fit into FlexVol (". byteconv($flex_total). "). "); } else { $plugin->nagios_exit(CRITICAL, "Data Space and Snapshot Reserve are out out space. Missing capacity (Data): ". byteconv($lun_used-$lun_total) ." (Snap): ". byteconv($snap_used-$snap_total)); } } } elsif ( $mode eq "volspace" ) { my $vols = vollistinfo($filer, $flexvol); # Just get the volume size and the free space left # vol_size_avail: Free space inside the volume # vol_size_used: Used space inside the volume my $vol_size_a = sprintf "%.0f", $vols->{"vol_size_avail"}; my $vol_size_u = sprintf "%.0f", $vols->{"vol_size_used"}; my $vol_size_t = sprintf "%.0f", $vol_size_a + $vol_size_u; if ( defined $warning && defined $critical) { $warning = sprintf "%.0f", $vol_size_t / 100 * $warning; $critical = sprintf "%.0f", $vol_size_t / 100 * $critical; if ($verbose) { print("warning: ". $warning ."\n") }; if ($verbose) { print("critical: ". $critical ."\n") }; $plugin->set_thresholds( warning => $warning, critical => $critical, ); $plugin->add_perfdata( label => "volspace_used", value => $vol_size_u, uom => 'KB', ); $plugin->add_perfdata( label => "volspace_total", value => $vol_size_t, uom => 'KB', threshold => $plugin->threshold, ); $plugin->nagios_exit($plugin->check_threshold($vol_size_u), "FlexVol remaining space: ". byteconv($vol_size_a)); } else { $plugin->nagios_exit(UNKNOWN, "You need warning and critical to use the volspace mode."); } } elsif ( $mode eq "snapreserve" ) { my $vols = vollistinfo($filer, $flexvol); my $snap = snaplistinfo($filer, $flexvol); # Get the snapreserve and the used snapreserve my $snap_total = $vols->{"vol_snap_reserve"}; my $snap_used = $snap->{"snap_total"}; my $snap_avail = $vols->{"vol_snap_reserve"} - $snap->{"snap_total"}; my $vol_total = $vols->{"vol_size_total"}; my $vol_used = $vols->{"vol_size_used"}; my $vol_avail = $vols->{"vol_size_avail"}; if ( defined $warning && defined $critical) { $warning = sprintf "%.0f", $snap_total / 100 * $warning; $critical = sprintf "%.0f", $snap_total / 100 * $critical; if ($verbose) { print("warning: ". $warning ."\n"); print("critical: ". $critical ."\n"); } $plugin->set_thresholds( warning => $warning, critical => $critical, ); $plugin->add_perfdata( label => "snapreserve_total", value => $snap_total, uom => 'KB', ); $plugin->add_perfdata( label => "snapreserve_used", value => $snap_used, uom => 'KB', threshold => $plugin->threshold, ); if ( $snap_total > 0 ) { my $snap_percent = sprintf "%.0f", $snap_used / $snap_total * 100; $plugin->nagios_exit($plugin->check_threshold($snap_used), "FlexVol Snap Reserve used: ". byteconv($snap_used). " (". $snap_percent ."%)"); } else { $plugin->nagios_exit($plugin->check_threshold($snap_used), "FlexVol Snap Reserve used: ". byteconv($snap_used)); } } else { $plugin->add_perfdata( label => "snapreserve_total", value => $snap_total, uom => 'KB', ); $plugin->add_perfdata( label => "snapreserve_used", value => $snap_used, uom => 'KB', ); if ( $vol_used < $vol_total && $snap_used > $snap_total ) { $plugin->nagios_exit(WARNING, "Snapshots are lending space from data space (Used: ". byteconv($snap_used) ." vs. Reserve: ". byteconv($snap_total) .")"); } elsif ( $vol_used > $vol_total && $snap_used > $snap_total ) { $plugin->nagios_exit(CRITICAL, "Snapshots are lending space from data space, the volume is out of space and resulted in offline luns!"); } else { $plugin->nagios_exit(OK, "Snap reserve (". byteconv($snap_total) .") of FlexVol $flexvol is OK."); } } } elsif ( $mode eq "snapvault" ) { my $sv = snapvaultinfo($filer, $flexvol); if ( defined $warning ) { $warning = $warning*60*60 }; if ( defined $critical ) { $critical = $critical*60*60 }; my $sv_lag_time = $sv->{"sv_lag_time"}; my $sv_state = $sv->{"sv_state"}; my $sv_status = $sv->{"sv_status"}; my $sv_progress = $sv->{"sv_progress"}; my $sv_error = $sv->{"sv_error"}; if ( defined $warning && defined $critical ) { $plugin->set_thresholds( warning => $warning, critical => $critical, ); } $plugin->add_perfdata( label => "snapvault_lag_time", value => $sv_lag_time, uom => 's', threshold => $plugin->threshold, ); if ($sv_state eq "snapvaulted" && $sv_status eq "quiescing" && $sv_error eq "could not register source qtree information") { $plugin->nagios_exit(CRITICAL, "SnapVault in stuck in quiescing-state - no space left?"); } elsif ($sv_state eq "snapvaulted" && $sv_status eq "quiescing" && $sv_error eq "replication destination write failed: No space left on device") { $plugin->nagios_exit(CRITICAL, "SnapVault in stuck in quiescing-state - no space left!"); } elsif ($sv_state eq "snapvaulted" && $sv_status eq "idle" && $sv_error eq "replication destination failed to create checksum storage") { $plugin->nagios_exit(CRITICAL, "SnapVault in stuck in quiescing-state"); } elsif ($sv_state eq "snapvaulted" && $sv_status eq "idle" && $sv_error eq "process was aborted") { $plugin->nagios_exit(CRITICAL, "SnapVault transfer was aborted"); } elsif ($sv_state eq "snapvaulted" && $sv_status eq "idle" && $sv_error eq "destination requested snapshot that does not exist on the source") { $plugin->nagios_exit(CRITICAL, "SnapVault was unable to transfer a snapshot - none found. Possible configuration error?"); } elsif ($sv_state eq "snapvaulted" && $sv_status eq "idle" && ($sv_error eq "none" || $sv_error eq "source contains no new data; suspending transfer to destination")) { if(!$warning && !$critical) { $plugin->nagios_exit(OK, "SnapVault Age: ". timeconv($sv_lag_time)); } else { if ($sv_lag_time >= $critical) { $plugin->nagios_exit(CRITICAL, "SnapVault Age: ". timeconv($sv_lag_time)); } elsif ($sv_lag_time < $critical && $sv_lag_time >= $warning) { $plugin->nagios_exit(WARNING, "SnapVault Age: ". timeconv($sv_lag_time)); } else { $plugin->nagios_exit(OK, "SnapVault Age: ". timeconv($sv_lag_time)); } } } elsif ($sv_state eq "uninitialized" && $sv_status eq "transferring") { $plugin->nagios_exit(OK, "SnapVault baseline transfer: ". byteconv($sv_progress)); } elsif ($sv_state eq "snapvaulted" && $sv_status eq "transferring") { $plugin->nagios_exit(OK, "SnapVault update transfer: ". byteconv($sv_progress)); } elsif ($sv_state eq "snapvaulted" && $sv_status eq "idle" && $sv_error eq "replication destination write failed: No space left on device" ) { $plugin->nagios_exit(CRITICAL, "SnapVault aborted: no space left!"); } elsif ($sv_state eq "snapvaulted" && $sv_status eq "idle" && $sv_error eq "could not register source qtree information" ) { $plugin->nagios_exit(CRITICAL, "SnapVault in stuck in quiescing-state - no space left?"); } elsif ($sv_state eq "snapvaulted" && $sv_status eq "idle" && $sv_error eq "transfer aborted because of network error: Connection reset by peer" ) { $plugin->nagios_exit(WARNING, "SnapVault transfer aborted, networking issues? - Age: ". timeconv($sv_lag_time)); } } elsif ( $mode eq "snapmirror" ) { my $sm = snapmirrorinfo($filer, $flexvol); if ( defined $warning ) { $warning = $warning*60*60 }; if ( defined $critical ) { $critical = $critical*60*60 }; my $sm_lag_time = $sm->{"sm_lag_time"}; my $sm_state = $sm->{"sm_state"}; my $sm_status = $sm->{"sm_status"}; my $sm_progress = $sm->{"sm_progress"}; my $sm_error = $sm->{"sm_error"}; if ( defined $warning && defined $critical ) { $plugin->set_thresholds( warning => $warning, critical => $critical, ); } $plugin->add_perfdata( label => "snapmirror_lag_time", value => $sm_lag_time, uom => 's', threshold => $plugin->threshold, ); if ($sm_state eq "snapmirrored" && $sm_status eq "quiescing" && $sm_error eq "could not register source qtree information") { $plugin->nagios_exit(CRITICAL, "SnapMirror is stuck in quiescing-state - no space left?"); } elsif ($sm_state eq "snapmirrored" && $sm_status eq "idle" && $sm_error eq "destination requested snapshot that does not exist on the source") { $plugin->nagios_exit(CRITICAL, "SnapMirror was unable to transfer a snapshot - none found. Possible configuration error?"); } elsif ($sm_state eq "unknown" && $sm_status eq "idle") { $plugin->nagios_exit(WARNING, "SnapMirror orphan found. Should be removed!"); } elsif ($sm_state eq "unknown" && $sm_status eq "idle with restart checkpoint" && $sm_error eq "destination is offline, is restricted, or does not exist") { $plugin->nagios_exit(CRITICAL, "SnapMirror: Destination volume offline or missing"); } elsif ( ($sm_state eq "snapmirrored" || $sm_state eq "source") && $sm_status eq "idle" && ($sm_error eq "none" || $sm_error eq "Nothing to transfer")) { if(!$warning && !$critical) { $plugin->nagios_exit(OK, "SnapMirror Age: ". timeconv($sm_lag_time)); } else { if ($sm_lag_time >= $critical) { $plugin->nagios_exit(CRITICAL, "SnapMirror Age: ". timeconv($sm_lag_time)); } elsif ($sm_lag_time < $critical && $sm_lag_time >= $warning) { $plugin->nagios_exit(WARNING, "SnapMirror Age: ". timeconv($sm_lag_time)); } else { $plugin->nagios_exit(OK, "SnapMirror Age: ". timeconv($sm_lag_time)); } } } elsif ($sm_state eq "uninitialized" && $sm_status eq "transferring") { $plugin->nagios_exit(OK, "SnapMirror baseline transfer: ". byteconv($sm_progress)); } elsif ( ($sm_state eq "snapmirrored" || $sm_state eq "source") && $sm_status eq "transferring") { $plugin->nagios_exit(OK, "SnapMirror update transfer: ". byteconv($sm_progress)); } elsif ($sm_state eq "snapmirrored" && $sm_status eq "pending") { $plugin->nagios_exit(OK, "SnapMirror update transfer pending"); } elsif ($sm_state eq "snapmirrored" && $sm_status eq "idle" && $sm_error eq "replication transfer failed to complete") { $plugin->nagios_exit(CRITICAL, "SnapMirror aborted the transfer!"); } elsif ($sm_state eq "snapmirrored" && $sm_status eq "pending" && $sm_error eq "destination volume too small; it must be equal to or larger than the source volume") { $plugin->nagios_exit(CRITICAL, "SnapMirror aborted due to no space left in FlexVol!"); } elsif ($sm_state eq "unknown" && $sm_status eq "pending with restart checkpoint" && $sm_error eq "volume is not online; cannot execute operation") { $plugin->nagios_exit(CRITICAL, "SnapMirror: Volume offline!"); } } elsif ( $mode eq "sis" ) { my $sis = sisinfo($filer, $flexvol); if ( defined $warning ) { $warning = $warning*24*60*60 }; if ( defined $critical ) { $critical = $critical*24*60*60 }; my $sis_state = $sis->{"sis_state"}; my $sis_changelog_usage = $sis->{"sis_changelog_usage"}; my $sis_stale_fingerprint = $sis->{"sis_stale_fingerprint"}; my $sis_last_operation_end = $sis->{"sis_last_operation_end"}; my $sis_last_success_operation = $sis->{"sis_last_success_operation"}; if ( defined $warning && defined $critical ) { $plugin->set_thresholds( warning => $warning, critical => $critical, ); } $plugin->add_perfdata( label => "sis_changelog_usage", value => $sis_changelog_usage, oum => '%' ); $plugin->add_perfdata( label => "sis_stale_fingerprint", value => $sis_stale_fingerprint, oum => '%' ); if ( $sis_state eq "Disabled" && $sis_changelog_usage gt 0 ) { $plugin->nagios_exit(CRITICAL, "SIS enabled, but no SIS run configured - see NetApp Bug-ID 533238"); } if ( $sis_state eq "Enabled" ) { # Sadly, even if a SIS run is cancelled, the # last-operation-state returns 'success'. So we can't really # use it to check the state of the last SIS run. if ( $sis_last_success_operation < (time - $critical) ) { $plugin->nagios_exit(CRITICAL, "SIS last operation failed. Last success: ". scalar(localtime($sis_last_success_operation))); } elsif ( $sis_last_success_operation < (time - $warning) ) { $plugin->nagios_exit(WARNING, "SIS last operation failed. Last success: ". scalar(localtime($sis_last_success_operation))); } else { if ( $sis_stale_fingerprint > 60 ) { $plugin->nagios_exit(WARNING, "SIS ran successful, however the Stale Fingerprints is above 60 percent."); } elsif ( $sis_changelog_usage > 60 ) { $plugin->nagios_exit(WARNING, "SIS ran successful, however the ChangeLog usage is above 60 percent."); } else { $plugin->nagios_exit(OK, "SIS ran successful."); } } } } |
Very nice! My #1 check is
I watch a bunch of other things (like IOPS per protocol) but mostly for historical purposes. Generally if there is an actual problem with the filer this will pick it up.
Yeah, the global status is one of those things I am using additionally 🙂
Hi,
Like what you written but wondered if you had anything similar that did not require nagios that would simply monitor the snapmirror and restart a relationship if it dies.
Can you let me know.? Thanks
Phillip
Hi,
This script doesn’t works for me.
This error appears:
readline() on unopened filehandle S at /usr/local/lib/perl5/site_perl/5.10.1/NetApp/NaServer.pm line 467.
Could you send me the script?
Regards