#!/usr/bin/python # check_swraid - plugin for nagios to check the status of linux swraid devices # # 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 2 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 Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Copyright 2004 Duke University # Written by Sean Dilda # Version: 0.3 # patched with the rouilj's patch (03.02.2006) by Virer (28.07.2006) import os import sys import string mdstat = '/proc/mdstat' mdFile = open(mdstat).readlines() # two cases: two starting lines or just one starting line. # Remove the first and lasts lines as we don't need them mdFile = mdFile[1:-1] if (len(mdFile) % 3) != 0: mdFile = mdFile[1:] if (len(mdFile) % 3) != 0: # must have two starting lines print 'Error with mdstat file' sys.exit(3) if len(mdFile) == 0: print 'Error no md devices configured' sys.exit(3) mdData = [] while len(mdFile) > 0: mdData.append((mdFile[0],mdFile[1])) mdFile = mdFile[3:] overallStatus = 0 errorMsg = '' devices = '' for tup in mdData: device, colon, status, type, drives = string.split(tup[0], None, 4) drives = string.split(drives) values = string.split(tup[1])[-2] values = values[1:-1] normal, current = string.split(values, '/') normal = int(normal) current = int(current) devices = devices + " " + device # Status of 0 == Ok, 1 == Warning, 2 == Critical status = 0 failed = 0 degraded = 0 msg = '' failed = [] for drive in drives: if drive[-3:] == '(F)': failed.append(drive[:string.index(drive, '[')]) status = 1 failed = ' (' + string.join(failed, ', ') + ').' if status == 'inactive': status = 2 msg = device + ' is inactive.' if type == 'raid5': if current < (normal -1): msg = device + ' failed' + failed status = 2 elif current < normal: msg = device + ' degraded' + failed status = 1 else: if current < normal: msg = device + ' failed' + failed status = 2 if len(msg) > 0: if len(errorMsg) > 0: errorMsg = errorMsg + '; ' errorMsg = errorMsg + msg overallStatus = max(overallStatus, status) if overallStatus == 0: print 'All md devices (' + devices + ' ) Ok.' sys.exit(0) else: print errorMsg sys.exit(overallStatus) #EOF