#!/usr/bin/env python ''' Copyright (C) 2007 Peter Froehlich 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 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 ---- This script uses the heartbeat v1 resources.d and init scripts to check which resources are running on this node. Configuration takes place in the head of the script. This is tested on python 2.4 and 2.5. ---- Have fun! ;-) -Peter ''' # <--- configuration ---> # Location of haresources file: HARES="/etc/ha.d/haresources" # Location of resource.d directory: HADIR="/etc/ha.d/resource.d" # Location of main init script directory: INITDIR="/etc/init.d" # <--- end of configuration ---> from os import listdir,system,popen4 from socket import gethostname from sys import exit HOST=gethostname() def GETRES(): ''' Check resources listed in haresources file and list running services. ''' global HARES global HOST global HADIR global INITDIR RES=" " try: HAR=open(HARES) except: print "Error opening "+HARES exit(1) for LINE in HAR.readlines(): for ITEM in LINE.split()[1:]: if ITEM.split(".")[0].isdigit(): if popen4(HADIR+"/IPaddr "+ITEM+" status" )[1].read().__contains__("Running"): RES=RES+", "+ITEM continue if ITEM in listdir(HADIR): if not system(HADIR+"/"+ITEM+" status &> /dev/null" ): RES=RES+", "+ITEM continue if ITEM in listdir(INITDIR): if not system(INITDIR+"/"+ITEM+" status &> /dev/null"): RES=RES+", "+ITEM continue try: if " ".join(RES[:]) == " ": return "None." else: return RES[3:] finally: HAR.close() try: HAR=open(HARES) except: print "Error opening "+HARES exit(1) for LINE in HAR.readlines(): if LINE.split()[0] == HOST: try: RUNNING=GETRES() print "This Node is the master for the following resources:\n"+", ".join(LINE.split()[1:])+"\n\n"+"Running resources:\n"+RUNNING+"\n" except: exit(1) HAR.close()