Using the Nexenta SA-API – nexenta-health plugin for Nagios
This is the first script I created using the NexentaStor SA-API, the install of which is detailed in my previous post here. We use a combination of Nagios and Zabbix to monitor our infrastructure, and a very helpful component of that has been the check_netapp plugin available here, which reports any sort of failure on the netapp, including array health, disk space/quota’s, etc. Netapp provides most of this data with a custom SNMP MIB, but unfortunately NexentaStor doesn’t have one (yet at least). I wanted the same functionality with our NexentaStor boxes, without having to remember to add a volume to our monitoring system every time I create a volume on the storage.
This script examines the state of each volume and the space used/free for each volume with a quota, and reports back any errors. The layout is copied from the check_netapp plugin, and is fairly simple to follow along. Of note, be sure to set the appropriate @INC path for your installation, and the location of your public key if using PKI with NexentaStor. Unfortunately some of the API is not documented, and the functionality is incomplete – I had to play around with the $folder->execute() method to find the correct command to get the space used and quota allocated. It seems like this should be a built in, documented method in the API, so here’s to hoping it makes it in.
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 | #!/usr/bin/perl BEGIN { unshift (@INC, "/opt/build/NexentaStor-SDK-Linux/examples/perl");} use NZA::Common; use strict; $ENV{'NEXENTA_ID_RSA'} = '/home/nagios/.ssh/id_rsa.pub'; #Configure space % threshold here for warnings my $space_threshold = .9; my $IPADDR = $ARGV[0]; if (!$IPADDR) { print "Usage: checkhealth.pl <ip -ADDR>\n"; exit 1; } my $volume = nms_remote_obj($IPADDR, '/Root/Volume'); my $folder = nms_remote_obj($IPADDR, '/Root/Folder'); my @errors; my $volnames = $volume->get_names(''); for my $vol (@$volnames) { #errors: No known data errors #state: ONLINE my $volstatus = $volume->get_status($vol); if (${$volstatus}{'state'}[0] ne 'ONLINE') { push (@errors, "Bad volume status for $vol: ", ${$volstatus}{'state'}[0] ); } if ( ! ${$volstatus}{'errors'}[0] =~ /No known data errors/ ) { push (@errors, "Errors for $vol: ", ${$volstatus}{'errors'}[0] ); } my $folder_names = $folder->get_names(''); for my $fol (@$folder_names) { $folder->reconstruct($fol); my $quota; my $used; my $lines = $folder->execute($fol, "get -H used $fol"); for my $line (@$lines) { $used .= $line }; my $lines = $folder->execute($fol, "get -H quota $fol"); for my $line (@$lines) { $quota .= $line }; my @data = split (/\s+/, $used); $used = $data[2]; my @data = split (/\s+/, $quota); $quota = $data[2]; if ($quota =~ /none/i) { next; } $used = convert_space_units($used); $quota = convert_space_units($quota); #print "$fol - used: $used, quota: $quota\n"; if ($quota > 0) { if ( ($used/$quota) > .9 ) { push (@errors, "Volume almost full: $fol"); } } } } if (scalar(@errors) > 0 ) { print "Nexentastor healthcheck failed! "; for my $error (@errors) { print " $error."; } print "\n"; exit(1); } else { print "Nexentastor healthcheck OK\n"; exit(0); } sub convert_space_units($) { my $string = shift; # K, M, G, T my %factor = ( K => 1000, M => 1000000, G => 1000000000, T => 1000000000000, ); if ($string =~ /([.\d]+)(\w+)/) { if ($factor{$2}) { return $1 * $factor{$2}; } } return ""; } </ip> |







