# # A script to: # look at the pools in data protector # find any that have 'free' in their name # check the number of media in the pool # check the status of the tapes in the pool # output something that nagios can consume for monitoring # provide a nagios return code. 0=ok, 1=warning, 2=critical, 3=unknown # # Author: Derek Jones, CQUniversity Australia, Apr 2016 # # Version: 1.0 $warning_limit = 6; # less than this many free tapes is just a warning, greater than or equal to this is OK $critical_limit = 3; # less than this many free tapes is BAD if ( $critical_limit -ge $warning_limit ) { write-output "WARNING: critical limit is greater than warning limit... that makes no sense"; exit(3); # unknown state } # we want the output to show criticals first, then warnings... so we put out output into # arrays, and print it all when we're finished $criticals = @(); $warnings = @(); $oks = @(); # use the Data Protector omnimm command to list all of the pools $output = cmd /c omnimm.exe -list_pool # Loop over each line of the output $line_number = 0; foreach ( $line in $output.split("`r`n") ) { # skip the first 3 lines... they're just headers $line_number++; if ( $line_number -le 3 ) { continue; } # skip any of our OLD pools if ( $line -like "*OLD*" ) { continue; } # we only want any line with "free" written on it, because we're after free pools if ( $line -like "*free*" ) { # break the line up into an array $fields = ($line -replace '\s+', ' ').split() # grab the name of the pool $pool = $fields[1]; # get detailed output about this pool... lists all tapes in the pool, their location and status $detailed_output = cmd /c omnimm.exe -list_pool "$pool" 2>&1 $detail_line_number = 0; $tapes_in_this_pool = 0; if ( $detailed_output.length ) { if ( $detailed_output -like "*No media configured in specified pool*" ) { $tapes_in_this_pool = 0; } else { foreach ( $detail_line in $detailed_output.split("`r`n") ) { # skip the first 3 lines... they're just headers $detail_line_number++; if ( $detail_line_number -le 3 ) { continue; } # skip any tapes that aren't actually IN the physical tape library... we only care about tapes actually IN the library # because tapes in storage won't get used automatically, and we don't care if they're poor quality # from being 3 years old :) if ( -not ( ( $detail_line -like "*MSL-*" ) -or ( $detail_line -like "*VTL*" ) ) ) { continue; } # line should start with "Good" if the tape is in good condition... otherwise, let us know if ( -not ( $detail_line -like "*Good*" ) ) { # but we only care about physical tapes in poor condition if ( $detail_line -like "*MSL-*" ) { $warnings+="$pool has a tape that won't get used"; } continue; } $tapes_in_this_pool++; } } } # make sure the pool size is an integer if ( -not ( $tapes_in_this_pool -match "^[0-9]+$" ) ) { write-output "Tape pool size '$tapes_in_this_pool' doesn't seem to be an integer"; exit(3); # unknown state } # is the number of free tapes in this pool a problem? if ( [int]$tapes_in_this_pool -le [int]$warning_limit ) { if ( [int]$tapes_in_this_pool -le [int]$critical_limit ) { # yep, this is bad $criticals+="$pool has $tapes_in_this_pool usable tapes (less than $critical_limit)"; } else { # just a warning $warnings+="$pool has $tapes_in_this_pool usable tapes (less than $warning_limit)"; } } else { $oks+="$pool has $tapes_in_this_pool usable tapes"; } } } # That's the end of parsing the omnimm output. # Now, and the all important nagios output. If nagios sees the word "CRITICAL" then # nagios will treat is as a critical, so we write those first. Same for warnings. # If all is well, we write OK $returnState=3; # unknown if ( $criticals.length ) { $string = $criticals -join ', '; "CRITICAL: " + $string; $returnState=2; #critical } if ( $warnings.length ) { $string = $warnings -join ', '; "WARNING: " + $string; if ( $returnState -eq 3 ) { $returnState=1; # warning } } # if we didn't see any warnings or criticals, then all is well. Show nagios an "OK" in the output if ( -not ( $criticals.length -or $warnings.length ) ) { write-output "OK: Free pools size and free pools tape quality look good"; if ( $returnState -eq 3 ) { $returnState = 0; # OK } } foreach ( $ok in $oks ) { write-output "$ok"; } exit $returnState