Commit 5bb2b21e authored by Vinicius Ruoso's avatar Vinicius Ruoso

Initial commit

Signed-off-by: default avatarVinicius Ruoso <vkr07@c3sl.ufpr.br>
parents
#script name:enabled intervalas;link name
prd_ajudaremota:onconnect.d:001-prd_ajudaremota
prd_schoolinfo:onconnect.d:003-prd_schoolinfo
prd_nre:onconnect.d:004-prd_nre
prd_city:onconnect.d:005-prd_city
prd_name:onconnect.d:006-prd_name
prd_version:onconnect.d daily.d:012-prd_version
prd_raid:onconnect.d hourly.d:020-prd_raid
#!/bin/bash
rm -f "Makefile" 2> /dev/null
touch "Makefile"
function makeprint()
{
printf "$*" >> Makefile
}
# get scripts names
SCRIPTS=""
while read LINE; do
NAME=$(cut -d: -f1 <<< $LINE)
grep -q "#" <<< $NAME && continue
SCRIPTS="$SCRIPTS $NAME"
done < autogen.conf
makeprint "PREFIX:=.\n\n"
# the install directive
makeprint "install:"
for SCRIPT in $SCRIPTS; do
makeprint " $SCRIPT-install"
done
makeprint "\n"
makeprint "\t@echo \"All done.\"\n\n"
# the uninstall directive
makeprint "uninstall:"
for SCRIPT in $SCRIPTS; do
makeprint " $SCRIPT-uninstall"
done
makeprint "\n"
makeprint "\t@echo \"All uninstalled.\"\n\n"
# the purge directive
makeprint "purge: uninstall"
for SCRIPT in $SCRIPTS; do
makeprint " $SCRIPT-purge"
done
makeprint "\n"
makeprint "\t@echo \"All purged.\"\n\n"
# the static checkprefix directive
makeprint "checkprefix:\n"
makeprint "\t@test -d \$(PREFIX)\n"
makeprint "\t@test -d \$(PREFIX)/commands-available\n"
makeprint "\t@test -d \$(PREFIX)/states-available\n\n"
# the static checkprefix-install directive
makeprint "checkprefix-install:\n"
makeprint "\t@test -d \$(PREFIX)\n"
makeprint "\t@test -d \$(PREFIX)/commands-enabled\n"
makeprint "\t@test -d \$(PREFIX)/states-enabled\n\n"
# the script specific copy, install, uninstall and purge directives
while read LINE; do
NAME=$(cut -d: -f1 <<< $LINE)
INTERVALS=$(cut -d: -f2 <<< $LINE)
LINKNAME=$(cut -d: -f3 <<< $LINE)
grep -q "#" <<< $NAME && continue
ls $NAME*.st &> /dev/null
HS=$?
# the copy directive
makeprint "$NAME: checkprefix\n"
makeprint "\t@cp $NAME $NAME.po \$(PREFIX)/commands-available\n"
if test $HS = 0; then
makeprint "\t@cp $NAME*.st \$(PREFIX)/states-available\n\n"
else
makeprint "\n"
fi
# the install directive
makeprint "$NAME-install: checkprefix-install $NAME\n"
for INTER in $INTERVALS; do
makeprint "\t@ln -fs \$(PREFIX)/commands-available/$NAME \\\\\n"
makeprint "\t\t\t\$(PREFIX)/commands-enabled/$INTER/$LINKNAME\n"
done
if test $HS = 0; then
makeprint "\t@ln -fs \$(PREFIX)/states-available/$NAME* \\\\\n"
makeprint "\t\t\t\$(PREFIX)/states-enabled/\n\n"
else
makeprint "\n"
fi
# the uninstall directive
makeprint "$NAME-uninstall: checkprefix-install\n"
makeprint "\t@rm -f \$(PREFIX)/commands-enabled/*/$LINKNAME\n"
if test $HS = 0; then
makeprint "\t@rm -f \$(PREFIX)/states-enabled/$NAME*\n\n"
else
makeprint "\n"
fi
# the purge directive
makeprint "$NAME-purge: $NAME-uninstall checkprefix-install\n"
makeprint "\t@rm -f \$(PREFIX)/commands-available/$NAME*\n"
if test $HS = 0; then
makeprint "\t@rm -f \$(PREFIX)/states-available/$NAME*.st\n\n"
else
makeprint "\n"
fi
done < autogen.conf
#!/bin/bash
if grep -q none <<< $(hostname); then
printf "STATUS+ONLINE\n"
printf "PRD_VERSION+Ajuda Remota\n"
ZONE="/prd/prd.zone"
ZONEERROR=true
if ! test -f $ZONE; then
printf "PRD_SCHOOLINFO+NOZONE\n"
else
ME=$(hostname --short)
IP=$(/usr/sbin/ifconfig |grep "inet" |awk -F: '{print $2}' | \
awk '{print $1}')
SCHOLL="$(grep "\<$IP\>" "$ZONE")"
if test -z "$SCHOLL"; then
printf "PRD_SCHOOLINFO+NOINFO\n"
else
ZONEERROR=false
DATA=$(cut -d';' -f2- <<< $SCHOLL |tr '_' ' '|tr '[A-Z]' '[a-z]'| \
sed -e 's#^\(.\)#\u\1#' -e 's#:\(.\)#:\u\1#g' \
-e 's# \(.\)# \u\1#g')
NRE=$(cut -d: -f1 <<< $DATA)
CITY=$(cut -d: -f2 <<< $DATA)
NAME=$(cut -d: -f3 <<< $DATA)
fi
fi
test "$ZONEERROR" = false &&
printf "PRD_CITY+$CITY\n" &&
printf "PRD_NAME+$NAME\n" &&
printf "PRD_NRE+$NRE\n"
while true; do
UPSEC=$(cat /proc/uptime |cut -d. -f1)
((UPDAYS=UPSEC/60/60/24))
((UPHOURS=UPSEC/60/60 - UPDAYS*24))
((UPMINUTES=UPSEC/60 - UPHOURS*60 - UPDAYS*24*60))
printf "UPTIME+$UPDAYS days, $UPHOURS:$UPMINUTES\n"
sleep 1800
done
fi
function getcolumninfo()
{
WEBINTERFACE=false
}
function getstateinfo()
{
STITLE="Ajuda Remota"
SDESCRIPTION="Escolas requisitanto ajuda remota"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status,Uptime,Versão"
SSUMARY="%d escolas em ajuda remota"
}
#!/bin/bash
test "$ZONEERROR" = false && printf "PRD_CITY+$CITY\n"
function prd_city_updatedata()
{
UPDATA="$*"
}
function prd_city_www()
{
PVALUE="$*"
}
function getcolumninfo()
{
WEBINTERFACE=true
COLNAME=Cidade
}
#!/bin/bash
test "$ZONEERROR" = false && printf "PRD_NAME+$NAME\n"
function prd_name_updatedata()
{
UPDATA="$*"
}
function prd_name_www()
{
PVALUE="$*"
}
function getcolumninfo()
{
WEBINTERFACE=true
COLNAME=Escola
}
#!/bin/bash
test "$ZONEERROR" = false && printf "PRD_NRE+$NRE\n"
function prd_nre_updatedata()
{
UPDATA="$*"
}
function prd_nre_www()
{
PVALUE="$*"
PSTATETYPE="prd_schoolinfo_nozone.st:false prd_schoolinfo_noinfo.st:false"
}
function getcolumninfo()
{
WEBINTERFACE=true
COLNAME=NRE
}
# NTP SERVER is 10.175.252.100
(/usr/sbin/ntpdate -b -s -u "10.175.252.100" &> /dev/null &&
printf "PRD_NTPDATE+OK\n")||
printf "PRD_NTPDATE+FAIL\n"
function prd_ntpdate_updatedata()
{
UPDATA="$*"
}
function prd_ntpdate_www()
{
PVALUE="$*"
}
function getcolumninfo()
{
WEBINTERFACE=false
}
if ! test -e /proc/mdstat; then
MSG="PRD_RAID+STATUS+NOTEXIST"
elif grep -q "_" /proc/mdstat; then
MSG="PRD_RAID+STATUS+DEGRADED+"
if ! test -e /dev/sda; then
MSG="$MSG sda_MISSING"
elif ! test -e /dev/sdb; then
MSG="$MSG sdb_MISSING"
elif grep -q "\(F\)" /proc/mdstat; then
FAULTY=$(grep "\(F\)" /proc/mdstat)
FAULTY=$(awk -F"\(F" '{print $1}' <<< $FAULTY|awk '{print $NF}')
FAULTY=$(sed -e "s/\[.*\]//" <<< $FAULTY)
for FAULT in FAULTY; do
MSG="$MSG ${FAULTY}_FAULTY"
done
else
for MDSTAT in $(grep '_' /proc/mdstat|cut -db -f1);do
if grep -B1 $MDSTAT /proc/mdstat|head -1|grep -q sda; then
DISK=sdb
else
DISK=sda
fi
MD=$(grep -B1 $MDSTAT /proc/mdstat|head -1| cut -d\ -f1)
PARTITION=$(grep -B1 $MDSTAT /proc/mdstat|head -1| \
sed -e "s/.*raid1 sd.\([0-9]\).*/\1/")
if test -e /dev/$DISK$PARTITION ; then
if grep -B1 $MDSTAT /proc/mdstat | grep -q recovery ; then
MSG="$MSG $DISK${PARTITION}_SYNCHRONIZING_RAID"
else
MSG="$MSG $DISK${PARTITION}_OUT_OF_RAID"
fi
else
MSG="$MSG $DISK${PARTITION}_MISSING"
fi
done
fi
else
MSG="PRD_RAID+STATUS+OK"
fi
if test "$MSG" = "RAID+STATUS+DEGRADED+"; then
printf "PRD_RAID+STATUS+DEGRADED+NOINFO"
else
MSG=$(sed "s/DEGRADED+ /DEGRADED+/g" <<< "$MSG")
printf "$MSG\n"
fi
function prd_raid_updatedata()
{
UPDATA="$*"
}
function prd_raid_www()
{
PVALUE="$*"
OUT="false"
SYNC="false"
FAULTY="false"
MISSINGPART="false"
MISSINGDISK="false"
NOINFO="false"
grep -q "OUT_OF_RAID" <<< "$PVALUE" && OUT="true"
grep -q "SYNCHRONIZING_RAID" <<< "$PVALUE" && SYNC="true"
grep -q "FAULTY" <<< "$PVALUE" && FAULTY="true"
grep -q "[1-9]_MISSING" <<< "$PVALUE" && MISSINGPART="true"
grep -q "sd[a,b]_MISSING" <<< "$PVALUE" && MISSINGDISK="true"
grep -q "NOINFO" <<< "$PVALUE" && NOINFO="true"
PSTATETYPE="prd_raid_out.st:$OUT prd_raid_sync.st:$SYNC"
PSTATETYPE="$PSTATETYPE prd_raid_faulty.st:$FAULTY"
PSTATETYPE="$PSTATETYPE prd_raid_misspart.st:$MISSINGPART"
PSTATETYPE="$PSTATETYPE prd_raid_noinfo.st:$NOINFO"
PSTATETYPE="$PSTATETYPE prd_raid_missdisk.st:$MISSINGDISK"
if [[ $OUT == "true" || $SYNC == "true" || $FAULTY == "true" || \
$MISSINGPART == "true" || $MISSINGDISK == "true" || \
$NOINFO == "true" ]]; then
PSTATUS=red
fi
if grep -q "OK" <<< "$PVALUE"; then
PVALUE="OK"
else
PVALUE="$(cut -d"+" -f3 <<< "$PVALUE")"
fi
}
function getcolumninfo()
{
WEBINTERFACE=true
COLNAME="RAID"
}
function getstateinfo()
{
STITLE="Partição com problema"
SDESCRIPTION="Escolas com partição com problema"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status,RAID"
SSUMARY="%d escolas com partição com problema"
}
function getstateinfo()
{
STITLE="Falta disco"
SDESCRIPTION="Escolas com disco faltando"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status,RAID"
SSUMARY="%d escolas com disco faltando"
}
function getstateinfo()
{
STITLE="Falta partição"
SDESCRIPTION="Escolas com partição faltando"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status,RAID"
SSUMARY="%d escolas com partição faltando"
}
function getstateinfo()
{
STITLE="Estado inconsistente não identificado"
SDESCRIPTION="Escolas com RAID em estado inconsistente"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status"
SSUMARY="%d escolas com RAID em estado inconsistente"
}
function getstateinfo()
{
STITLE="Partição fora do RAID"
SDESCRIPTION="Escolas com partição fora do RAID"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status,RAID"
SSUMARY="%d escolas com partição fora do RAID"
}
function getstateinfo()
{
STITLE="Partição sincronizando"
SDESCRIPTION="Escolas com partição sincronizando"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status,RAID"
SSUMARY="%d escolas com partição sincronizando"
}
#!/bin/bash
ZONE="/usr/local/share/prd-recovery/prd/prd.zone"
ZONEERROR=true
if ! test -f $ZONE; then
printf "PRD_SCHOOLINFO+NOZONE\n"
else
ME=$(hostname --short)
SCHOLL="$(grep "\<$ME\>" "$ZONE")"
if test -z "$SCHOLL"; then
printf "PRD_SCHOOLINFO+NOINFO\n"
else
ZONEERROR=false
DATA=$(cut -d';' -f2- <<< $SCHOLL |tr '_' ' '|tr '[A-Z]' '[a-z]'| \
sed -e 's#^\(.\)#\u\1#' -e 's#:\(.\)#:\u\1#g' \
-e 's# \(.\)# \u\1#g')
NRE=$(cut -d: -f1 <<< $DATA)
CITY=$(cut -d: -f2 <<< $DATA)
NAME=$(cut -d: -f3 <<< $DATA)
fi
fi
# send /etc/hosts information
function prd_schoolinfo_updatedata()
{
UPDATA="$*"
}
function prd_schoolinfo_www()
{
PVALUE="$*"
if test "$PVALUE" = "NOZONE"; then
PSTATETYPE="prd_schoolinfo_nozone.st:true"
PSTATETYPE="$PSTATETYPE prd_schoolinfo_noinfo.st:false"
else
PSTATETYPE="prd_schoolinfo_nozone.st:false"
PSTATETYPE="$PSTATETYPE prd_schoolinfo_noinfo.st:true"
fi
}
function getcolumninfo()
{
WEBINTERFACE=false
}
function getstateinfo()
{
STITLE="Não está no prd.zone"
SDESCRIPTION="Escolas ausentes do prd.zone"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status,Uptime"
SSUMARY="%d escolas ausentes do prd.zone"
}
function getstateinfo()
{
STITLE="Sem arquivo prd.zone"
SDESCRIPTION="Escolas sem o arquivo prd.zone"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status,Uptime"
SSUMARY="%d escolas sem o arquivo prd.zone"
}
#!/bin/bash
if test -f /etc/prd_version; then
printf "PRD_VERSION+$(cat /etc/prd_version)\n"
else
printf "PRD_VERSION+NOTEXIST\n"
fi
function prd_version_updatedata()
{
UPDATA="$*"
}
function prd_version_www()
{
VERSION="$*"
if test "$VERSION" = "NOTEXIST"; then
PSTATETYPE="prd_ajudaremota_ajuda.st:false"
PSTATETYPE="$PSTATETYPE prd_version_noversion.st:true"
PSTATETYPE="$PSTATETYPE prd_version_prd1.1.st:false"
PSTATUS=gray
elif grep -q "1\.1" <<< "$VERSION"; then
PSTATETYPE="prd_ajudaremota_ajuda.st:false"
PSTATETYPE="$PSTATETYPE prd_version_noversion.st:false"
PSTATETYPE="$PSTATETYPE prd_version_prd1.1.st:true"
PSTATUS=gray
elif test "$VERSION" = "Ajuda Remota"; then
PSTATETYPE="prd_ajudaremota_ajuda.st:true"
PSTATETYPE="$PSTATETYPE prd_version_noversion.st:false"
PSTATETYPE="$PSTATETYPE prd_version_prd1.1.st:false"
PSTATUS=gray
else
PSTATETYPE="prd_ajudaremota_ajuda.st:false"
PSTATETYPE="$PSTATETYPE prd_version_noversion.st:false"
PSTATETYPE="$PSTATETYPE prd_version_prd1.1.st:false"
test "$VERSION" != "2.0r2 Quero-quero" && PSTATUS=gray
fi
PVALUE="$VERSION"
}
function getcolumninfo()
{
WEBINTERFACE=true
COLNAME=Versão
}
function getstateinfo()
{
STITLE="Sem arquivo de versão"
SDESCRIPTION="Escolas sem o arquivo de versão"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status,Uptime,Versão"
SSUMARY="%d escolas sem o arquivo de versão"
}
function getstateinfo()
{
STITLE="PrD 1.1"
SDESCRIPTION="Escolas em PrD 1.1"
SDEFCOLUMNS="ID,NRE,Cidade,Escola,Status,Uptime,Versão"
SSUMARY="%d escolas em PrD 1.1"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment