#!/usr/bin/ksh
#####################################################################
# TITRE:	ESOShowMQ
#--------------------------------------------------------------------
# CREE LE:	05/02/97	Par: D.Stoll
#--------------------------------------------------------------------
# OBJET: 	Afficher les process MQ actifs et non actifs
#			
#====================================================================
# Modifie le:	JJ/MM/AA		Par: 
#	Motif: motif ayant justifie la modification et points
#	modifies si besoin
#####################################################################

# Recuperation du nom du/des gestionnaire
NomGest=`ls /logiciel/mqm/var/mqm/qmgrs | grep -v SYSTEM`

# Definition du fichier temporaire
fic_temp=/tmp/ps_MQ

# Definition des variables globales locales script:
typeset CommandeLs			  # Commande ls en fonction de l'OS
typeset CommandePs			  # Commande ps en focntion de l'OS
typeset OPCMON				  # PATH de la commande opcmon
typeset TypeMachine                       # Recuperation de l'OS  	
typeset VersionOS                         # Recuperation de la version de l'OS 
typeset ReferenceFonction		  # Commande differente suivant l'OS

#####################################################################
# FONCTION: 	DeterminationOS	
# CREEE LE:	12/12/94		Par: Johann CURE HP
# OBJET:	Cette fonction permet de connaitre l'OS sur lequel
#		le script se deroule
#====================================================================
# Modifiee le:	12/12/96		Par:  Vincent Garreau HP
#	Motif: prise en compte de nouvelles plate-formes HP, AIX, SOLARIS, IRIX
#####################################################################
# Modifiee le:	JJ/MM/AA		Par: 
#	Motif: motif ayant justifie la modification et points
#	modifies si besoin
#####################################################################
# REMARQUES:
# 
#####################################################################
function DeterminationOS
{
	TypeMachine=$(uname -s)           # Recuperation de l'OS  	
	VersionOS=$(uname -rv)            # Recuperation de la version de l'OS 

	case ${TypeMachine} in
	HP-UX)
		if [[ "$(echo $VersionOS|cut -d. -f2)" = "10" || "$(echo $VersionOS|cut -d. -f2)" = "11" ]] ; then
			ReferenceFonction=FonctionHPUX10
			OPCMON=/opt/OV/bin/OpC/opcmon
		else
			ReferenceFonction=FonctionHPUX
			OPCMON=/usr/OV/bin/OpC/opcmon
		fi
		CommandeLs="ls -g"
		CommandePs="ps -edf"
		;;
	SunOS)
		if [ "$(echo $VersionOS|cut -c1,2)" = "5." ] ; then
				TypeMachine="Solaris"
				ReferenceFonction=FonctionSolaris
				OPCMON=/opt/OV/bin/OpC/opcmon
				CommandeLs="ls -g"
				CommandePs="ps -edf"
		else	
				ReferenceFonction=FonctionSunOS
				OPCMON=/usr/OV/bin/OpC/opcmon
				CommandeLs="ls -l"
				CommandePs="ps -axlww"
		fi
		;;
	AIX)
		if [ "$(echo $VersionOS|cut -c 3,3)" = "4" ] 
			then ReferenceFonction=FonctionAIX42
			else ReferenceFonction=FonctionAIX
		fi
		OPCMON=/usr/lpp/OV/OpC/opcmon
		CommandePs="ps -edf"
		CommandeLs="ls -g"
		;;
	IRIX)
		ReferenceFonction=FonctionIRIX
		OPCMON=/opt/OV/bin/OpC/opcmon
		CommandePs="ps -edf"
		CommandeLs="ls -g"
		;;

	*)	
		print "$TypeMachine non supporte par ce programme"
		exit 2
		;;
	esac
	return 0
}

#####################################################################
# FONCTION:     FonctionHP-UX
#		FonctionHP-UX10
#		FonctionSunOS 
#		FonctionSolaris
#		FonctionAIX
#		FonctionAIX42
#		FonctionIRIX
# CREEE LE:     12/12/94                Par: Johann CURE HP
# OBJET:        Ces 6 fonctions execute les instructions propres a
#		chaque systeme pour obtenir les memes resultats 
#====================================================================
# Modifiee le:  JJ/MM/AA                Par:
#####################################################################


function FonctionHPUX
	{
	for Gest in ${NomGest}
	do
	  echo""
	  echo "Etat des process MQueue du gestionnaire ${Gest}"
	  echo "--------------------------------------------------"
	  echo
	  for NomProc in amqzxma0 amqhasmx amqharmx amqzllp0 runmqtrm runmqchi mq_evmon
	  do
	    case ${NomProc} in
	    runmqtrm )
	      echo "Trigger Monitor :" ;;
	    runmqchi )
	      echo "Channel Initiator :" ;;
	    mq_evmon )
	      echo "Process de supervision :" ;;
	    esac
	    if [ `grep ${NomProc} ${fic_temp}|grep -c ${Gest}` -ne 0 ]
	    then
	      echo "                    Process ${NomProc} actif"
	    else
	      echo "                    --> PROCESS ${NomProc} NON ACTIF"
	    fi	
	  done
	done
	return 0
	}

function FonctionHPUX10
	{
	FonctionHPUX
	return 0
	}

function FonctionSunOS
	{
	FonctionHPUX
	return 0
	}

function FonctionSolaris
	{
        FonctionHPUX
	return 0
	}

function FonctionAIX
	{
        FonctionHPUX
	return 0
	}

function FonctionAIX42
	{
        FonctionHPUX
	return 0
	}

function FonctionIRIX
	{
        FonctionHPUX
	return 0
	}

####################################################################
#			PROGRAMME PRINCIPAL
####################################################################
if [ -d  /logiciel/mqm ]
then
  DeterminationOS
  ${CommandePs} > ${fic_temp}
  ${ReferenceFonction}
else
  echo "MQueue n'est pas installe sur ce serveur"
fi
