diff --git a/client/conf-client/Card_10.10.10.3-1666.cfg b/client/conf-client/Card_10.10.10.3-1666.cfg new file mode 100644 index 0000000..352b702 --- /dev/null +++ b/client/conf-client/Card_10.10.10.3-1666.cfg @@ -0,0 +1,4 @@ +10.10.10.3:1666#file#/tmp/coucou +10.10.10.3:1666#file#/tmp/nop +10.10.10.3:1666#file# +10.10.10.3:1666#NotRealSondeName#reboot diff --git a/client/conf-client/Card_10.10.10.4-1666.cfg b/client/conf-client/Card_10.10.10.4-1666.cfg new file mode 100644 index 0000000..8b0ba03 --- /dev/null +++ b/client/conf-client/Card_10.10.10.4-1666.cfg @@ -0,0 +1,4 @@ +10.10.10.4:1666#file#/tmp/coucou +10.10.10.4:1666#file#/tmp/nop +10.10.10.4:1666#file# +10.10.10.4:1666#NotRealSondeName#reboot diff --git a/client/conf-client/exec.sh b/client/conf-client/exec.sh index a324d69..2307940 100755 --- a/client/conf-client/exec.sh +++ b/client/conf-client/exec.sh @@ -6,22 +6,29 @@ cd $(dirname $0) SondeFile=$(pwd)/sonde.cfg source service.cfg source functions +ConfFile=$1 -#[[ "${Crypted}" == "yes" ]] && NcCmd="timeout ${TimeOut} cryptcat -k ${LocalPassword} ${RemoteIp} ${RemotePort} " || NcCmd="timeout ${TimeOut} nc ${RemoteIp} ${RemotePort}" [[ "${Crypted}" == "yes" ]] && NcCmd="timeout ${TimeOut} cryptcat -k ${LocalPassword} " || NcCmd="timeout ${TimeOut} nc " +while [[ ! -f /tmp/endmonitor ]] + do + if [[ -f /tmp/Monithor_${ConfFile}-tmp ]] + then -PrintWeb START_TRATS - while read DATA - do - Remote=$(echo $DATA| cut -d"#" -f1| cut -d":" -f1) - Port=$(echo $DATA| cut -d"#" -f1| cut -d":" -f2) - Cmd=$(echo $DATA| cut -d"#" -f2) - Arg=$(echo $DATA| cut -d"#" -f3) - Res=$( echo -e "${Cmd}#${Arg}" | eval ${NcCmd} ${Remote} ${Port} 2> /dev/null) - Ret=$? - PrintRes "${Res:-5|No sonde $Cmd on serveur $Remote}" - PrintWeb "${Res:-5|No sonde $Cmd on serveur $Remote}" ${Cmd:-Nodata} ${Arg:-Noadata} ${Remote:-Nodata} - done < ${SondeFile} -PrintWeb END_DNE + sleep ${Rotation} + GenerateWebEnd /tmp/Monithor_${ConfFile}-tmp + CheckAllEnd ${TotalConfig} + else + while read DATA + do + Remote=$(echo $DATA| cut -d"#" -f1| cut -d":" -f1) + Port=$(echo $DATA| cut -d"#" -f1| cut -d":" -f2) + Cmd=$(echo $DATA| cut -d"#" -f2) + Arg=$(echo $DATA| cut -d"#" -f3) + Res=$( echo -e "${Cmd}#${Arg}" | eval ${NcCmd} ${Remote} ${Port} 2> /dev/null) + Ret=$? + GenerateWeb "${Res:-5|No sonde $Cmd on serveur $Remote}" ${Cmd:-Nodata} ${Arg:-Noadata} ${Remote:-Nodata} /tmp/Monithor_${ConfFile}-tmp + done < ${ConfFile} + fi + done diff --git a/client/conf-client/functions b/client/conf-client/functions index 7944d32..7354bc7 100644 --- a/client/conf-client/functions +++ b/client/conf-client/functions @@ -5,16 +5,25 @@ PrintRes() { } -PrintWeb() { +CheckAllEnd() { - if [[ ! -f /tmp/webmonithor ]] || [[ "$1" == "START_TRATS" ]] + Total=$1 + Actual=0 + for AcutalFile in $(find /tmp/ -name Monithor_\*-tmp) + do + [[ ! -z $(tail -n 1 $ActualFile | grep 'End of') ]] && Acutal=$((Actual + 1)) + done + + if [[ ${Total} -eq ${Actual} ]] then - echo ' + + echo ' MoniThor on '${RemoteIp}' + MONITHOR Date : '$(date +'%Y-%m-%d %H:%M:%S')' @@ -27,35 +36,48 @@ PrintWeb() { ' > /tmp/webmonithor - fi +cat /tmp/Monithor_* >> /tmp/webmonithor +rm /tmp/Monithor -f - if [ "$1" == "END_DNE" ] - then - echo ' + echo ' ' >> /tmp/webmonithor - mv /tmp/webmonithor ../web/index.html + mv /tmp/webmonithor ../web/index.html - else - Val=$(echo $1 | cut -d"|" -f1) - Txt=$(echo $1 | cut -d"|" -f2) - Sonde=$2 - Arg=$3 - Remote=$4 - Color=red - [[ $Val == "0" ]] && Color=green - [[ $Val == "1" ]] && Color=yellow + fi +} - echo ' +GenerateWebEnd(){ + echo ''| tee -a $1 + +} + +GenerateWeb(){ + + Val=$(echo $1 | cut -d"|" -f1) + Txt=$(echo $1 | cut -d"|" -f2) + Sonde=$2 + Arg=$3 + Remote=$4 + File=$5 + Color=red + [[ $Val == "0" ]] && Color=green + [[ $Val == "1" ]] && Color=yellow + + echo ' '$Remote' '$Sonde' '$Arg' '$Val' '$Txt' -' >> /tmp/webmonithor - fi +' >> ${File} + + } + + + diff --git a/client/conf-client/sonde.cfg b/client/conf-client/sonde.cfg index 352b702..adc506f 100644 --- a/client/conf-client/sonde.cfg +++ b/client/conf-client/sonde.cfg @@ -2,3 +2,7 @@ 10.10.10.3:1666#file#/tmp/nop 10.10.10.3:1666#file# 10.10.10.3:1666#NotRealSondeName#reboot +10.10.10.4:1666#file#/tmp/coucou +10.10.10.4:1666#file#/tmp/nop +10.10.10.4:1666#file# +10.10.10.4:1666#NotRealSondeName#reboot diff --git a/client/service.sh b/client/service.sh index 0bd280b..6898460 100755 --- a/client/service.sh +++ b/client/service.sh @@ -1,17 +1,26 @@ #!/bin/bash - source $(dirname $0)/conf-client/service.cfg +source $(dirname $0)/conf-client/functions -if [[ -z $(ps axf| grep pyhton | grep ${WebPort}) ]] +if [[ "$1" == "start" ]] then + [[ -f /tmp/endmonitor ]] && rm -f /tmp/endmonitor bash ./conf-client/webserver.sh ${WebPort} & - fi -while true - do - ./conf-client/exec.sh - sleep $Rotation - done + export TotalConfig=$(ls -1 ./conf-client | grep Card_.*\.cfg|wc -l) + for Conf in $(ls -1 ./conf-client | grep Card_.*\.cfg) + do + screen -dmS ${Conf} bash -x ./conf-client/exec.sh ${Conf} + done +fi + +if [[ "$1" == "stop" ]] +then + killall python + rm /tmp/Monithor* + touch /tmp/endmonitor + +fi