Skip to content

Instantly share code, notes, and snippets.

@tsleite
Created January 4, 2021 15:03
Show Gist options
  • Save tsleite/7c54f70a01b4695535af5425c624ef27 to your computer and use it in GitHub Desktop.
Save tsleite/7c54f70a01b4695535af5425c624ef27 to your computer and use it in GitHub Desktop.
#!/bin/bash
##################################################################
# Script: check_sap_availability.sh #
# Author: Wilson Fernandes #
# Contact: Email: wilsonwers@gmail.com #
# Date: 2019-08-15 #
# Description: Monitoramento Disponibilidade SAP #
# Use: check_sap_availability.sh hdbnameserver 00 #
##################################################################
#################################################################################
# Modificacao: max.santos- 10/11/2020 #
# Atualizacao: tleite - 11/11/2020 #
# Motivacao: Descoberta automatica e criacao JSON #
# Instancias, Codigos de Instancias, Nome de Processos, Descricao de Processos #
#################################################################################
SAPCMD="/usr/sap/hostctrl/exe/saphostctrl"
INST=$(${SAPCMD} -function ListInstances | awk '{print $4" "$6}')
case ${1} in
database)
echo "{"
echo "\"data\":["
comma=""
while read iNAME iCOD
do
#printf "$iNAME $iCOD\n"
PROC=$(/usr/sap/hostctrl/exe/sapcontrol -nr ${iCOD} -function GetProcessList | grep hdb | tr -d ' ')
if [ -n ${#PROC[@]} ]; then
for i in $PROC
do
pNAME=$(printf "%s $i" | awk -F ',' '{print $1}' | tr -d ' ')
pDESC=$(printf "%s $i" | awk -F ',' '{print $2}' | tr -d ' ')
#pSTATUS=$(printf "%s $i" | awk -F ',' '{print $4}' | tr -d ' ')
echo " $comma{\"{#INAME}\":\"$iNAME\" ,"
echo " \"{#ICOD}\":\"$iCOD\", "
echo " \"{#PNAME}\":\"$pNAME\", "
echo " \"{#PDESC}\":\"$pDESC\"} "
comma=","
#echo "$pNAME $pDESC $pSTATUS"
done
fi
done << EOF
$INST
EOF
echo "]"
echo "}"
;;
*)
PROC=$(/usr/sap/hostctrl/exe/sapcontrol -nr ${1} -function GetProcessList | grep hdb | tr -d ' ')
bRetorno="1"
if [ -n ${#PROC[@]} ]; then
for i in $PROC
do
pDESC=$(printf "%s $i" | awk -F ',' '{print $2}' | tr -d ' ')
pSTATUS=$(printf "%s $i" | awk -F ',' '{print $4}' | tr -d ' ')
#echo "$pDESC"
#echo "$pSTATUS"
if [[ $pDESC == ${2} && $pSTATUS == "Running" ]]; then
bRetorno="0"
break
fi
done
fi
echo $bRetorno
;;
esac
@tsleite
Copy link
Author

tsleite commented Jan 4, 2021

Create JSON
Monitoring SAP DBHANA with Zabbix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment