[UPDATE] - refact deb + generate

This commit is contained in:
2022-03-17 08:50:36 +01:00
parent 192382c8c2
commit d4300b4ca5
32 changed files with 68 additions and 256 deletions
+31
View File
@@ -0,0 +1,31 @@
#!/bin/bash
source /etc/monithor-client/service.cfg
if [[ $(id -u) != "0" ]]
then
echo "Not Root"
exit
fi
if [[ "$1" == "start" ]]
then
[[ -f /tmp/endmonitor ]] && rm -f /tmp/endmonitor
rm /tmp/Monitor* /tmp/webmonithor &> /dev/null
TotalConfig=$(ls -1 /etc/monithor-client/conf/ | grep Card_.*\.cfg|wc -l)
for Conf in $(ls -1 /etc/monithor-client/conf/ | grep Card_.*\.cfg)
do
screen -dmS ${Conf} bash /usr/local/bin/monithor-client.d/MoniThor ${Conf}
done
screen -dmS webserver bash /usr/local/bin/monithor-client.d/MoniThorWebServer ${WebPort} $TotalConfig
fi
if [[ "$1" == "stop" ]]
then
killall python &> /dev/null
rm /tmp/Monithor* &> /dev/null
touch /tmp/endmonitor
fi
+31
View File
@@ -0,0 +1,31 @@
#!/bin/bash
SondeFile=/etc/monithor-client/sonde.cfg
source /etc/monithor-client/service.cfg
source /usr/local/bin/monithor-client.d/MoniThorFnct
ConfFile=$1
[[ "${Crypted}" == "yes" ]] && NcCmd="timeout ${TimeOut} cryptcat -k ${LocalPassword} " || NcCmd="timeout ${TimeOut} nc "
while [[ ! -f /tmp/endmonitor ]]
do
if [[ -f /tmp/Monithor_${ConfFile}-tmp ]]
then
GenerateWebEnd /tmp/Monithor_${ConfFile}-tmp
sleep ${Rotation}
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 < /etc/monithor-client/conf/${ConfFile}
fi
done
@@ -0,0 +1,76 @@
#!/bin/bash
PrintRes() {
echo "$1"
}
CheckAllEnd() {
if [[ ! -f /tmp/webmonithor ]]
then
Total=$1
Actual=0
for ActualFile in $(find /tmp/ -name Monithor_\*-tmp)
do
[[ ! -z $(tail -n 1 $ActualFile | grep 'End of') ]] && Actual=$((Actual + 1))
done
if [[ ${Total} -eq ${Actual} ]]
then
echo '
<html>
<head>
<title>MoniThor on '${RemoteIp}' </title>
<meta http-equiv="refresh" content="1" />
</head>
<title>MONITHOR</title>
Date : '$(date +'%Y-%m-%d %H:%M:%S')'
<table border="1" color="#FFFFFF">
<thead>
<tr>
<th colspan="4">MoniThor Result</th>
</tr>
</thead>
<tbody>' > /tmp/webmonithor
cat /tmp/Monithor_*-tmp >> /tmp/webmonithor
echo '
</tbody>
</table> ' >> /tmp/webmonithor
mv /tmp/webmonithor /var/www/html/monithor/index.html
rm /tmp/Monithor_* -f
fi
fi
}
GenerateWebEnd(){
echo '<!--End of '$1' '$(pwd)'-->' >> $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 '
<tr> <td>'$Remote'</td> <td>'$Sonde'</td> <td>'$Arg'</td> <td style="background-color:'${Color}';" > '$Val' </td> <td> '$Txt'</td> </tr>' >> ${File}
}
@@ -0,0 +1,34 @@
#!/bin/bash
[[ ! -d /var/www/html/monithor ]] && mkdir -p /var/www/html/monithor
pushd /var/www/html/monithor
source /usr/local/bin/monithor-client.d/MoniThorFnct
python -m SimpleHTTPServer ${1} &
echo '<html>
<head>
<title>MoniThor on '${RemoteIp}' </title>
<meta http-equiv="refresh" content="1" />
</head>
<title>MONITHOR</title>
!!!! Initialization !!!!
' > index.html
while [[ ! -f /tmp/endmonitor ]]
do
if [[ ! -z $(ls -1 /tmp/ | grep Monithor_.*-tmp) ]]
then
CheckAllEnd $2
echo INSIDE
fi
sleep 1
done