[UPDATE] - add debian package and rebuild
This commit is contained in:
parent
6cacea01ba
commit
69069c5919
10
debs/index.html
Normal file
10
debs/index.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>MoniThor on </title>
|
||||||
|
<meta http-equiv="refresh" content="1" />
|
||||||
|
</head>
|
||||||
|
<title>MONITHOR</title>
|
||||||
|
|
||||||
|
!!!! Initialization !!!!
|
||||||
|
|
||||||
|
|
||||||
BIN
debs/monithor-client_1.0-0_noarch.deb
Normal file
BIN
debs/monithor-client_1.0-0_noarch.deb
Normal file
Binary file not shown.
6
debs/monithor-client_1.0-0_noarch/DEBIAN/control
Normal file
6
debs/monithor-client_1.0-0_noarch/DEBIAN/control
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Package: monithor-client
|
||||||
|
Version: 1.0
|
||||||
|
Architecture: all
|
||||||
|
Dependsd:netcat,cryptcat,screen,python,netcat,cryptcat,elinks
|
||||||
|
Maintainer: Guillaume Astier <guillaume@gastier.net>
|
||||||
|
Description: monithor client (with simple http server python)
|
||||||
37
debs/monithor-client_1.0-0_noarch/etc/init.d/monithor-c
Executable file
37
debs/monithor-client_1.0-0_noarch/etc/init.d/monithor-c
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: monithor-c
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop:
|
||||||
|
# Short-Description: MoniThor Server
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
test -x /usr/local/bin/monithor-client || exit 0
|
||||||
|
|
||||||
|
umask 022
|
||||||
|
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
if [ ! -z $(ps axf| grep monithor-client | grep -v grep) ]
|
||||||
|
then
|
||||||
|
logger "monithor-client is running ..."
|
||||||
|
else
|
||||||
|
logger "Starting MoniThor Server"
|
||||||
|
/usr/local/bin/monithor-client start
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
logger "Stoping MoniThor server" "monithor-c" || true
|
||||||
|
/usr/local/bin/monithor-client stop
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Usage: /etc/init.d/monithor-c {start|stop|status}" || true
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
@ -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
|
||||||
@ -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
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
RemoteIp=10.10.10.3:1666
|
||||||
|
LocalPassword='Evil@MonitoR-666'
|
||||||
|
Crypted=no
|
||||||
|
Rotation=1
|
||||||
|
TimeOut=2
|
||||||
|
WebPort=80
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
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
|
||||||
|
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
|
||||||
31
debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client
Executable file
31
debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client
Executable 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
debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThor
Executable file
31
debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThor
Executable 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BIN
debs/monithor-server_1.0-0_noarch.deb
Normal file
BIN
debs/monithor-server_1.0-0_noarch.deb
Normal file
Binary file not shown.
6
debs/monithor-server_1.0-0_noarch/DEBIAN/control
Normal file
6
debs/monithor-server_1.0-0_noarch/DEBIAN/control
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Package: monithor-server
|
||||||
|
Version: 1.0
|
||||||
|
Architecture: all
|
||||||
|
Dependsd:netcat,cryptcat
|
||||||
|
Maintainer: Guillaume Astier <guillaume@gastier.net>
|
||||||
|
Description: monithor Server (nrpe like in netcat/cryptcat and bash)
|
||||||
37
debs/monithor-server_1.0-0_noarch/etc/init.d/monithor-d
Executable file
37
debs/monithor-server_1.0-0_noarch/etc/init.d/monithor-d
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: monithor-d
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop:
|
||||||
|
# Short-Description: MoniThor Server
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
test -x /usr/local/bin/monithor-server || exit 0
|
||||||
|
|
||||||
|
umask 022
|
||||||
|
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
if [ ! -z $(ps axf| grep monithor-server | grep -v grep) ]
|
||||||
|
then
|
||||||
|
logger "monithor-server is running ..."
|
||||||
|
else
|
||||||
|
logger "Starting MoniThor Server"
|
||||||
|
/usr/local/bin/monithor-server start
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
logger "Stoping MoniThor server" "monithor-d" || true
|
||||||
|
/usr/local/bin/monithor-server stop
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Usage: /etc/init.d/monithor-d {start|stop|status}" || true
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
LocalIp=127.0.0.1
|
||||||
|
LocalPort=8080
|
||||||
|
#########
|
||||||
|
Crypted=no
|
||||||
|
LocalPassword='Evil@MonitoR-666'
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
network#ip.sh
|
||||||
|
file#file-present.sh
|
||||||
|
|
||||||
48
debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server
Executable file
48
debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server
Executable file
@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
ScriptDir=/usr/local/bin/monithor-server.d/
|
||||||
|
SondeFile=/etc/monithor-server/sonde.cfg
|
||||||
|
source /etc/monithor-server/service.cfg
|
||||||
|
|
||||||
|
[[ "${Crypted}" == "yes" ]] && NcCmd="cryptcat -k ${LocalPassword} -l ${LocalIp} -p ${LocalPort} " || NcCmd="nc -l ${LocalIp} ${LocalPort}"
|
||||||
|
|
||||||
|
if [[ "${1}" == "start" ]]
|
||||||
|
then
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
#coproc cryptcat -k ${LocalPassword} -l ${LocalIp} -p ${LocalPort}
|
||||||
|
coproc eval ${NcCmd}
|
||||||
|
while read -r cmd; do
|
||||||
|
logger "Running $cmd"
|
||||||
|
cpt=0
|
||||||
|
while read DATA
|
||||||
|
do
|
||||||
|
Sonde=$(echo ${DATA}| cut -d"#" -f1)
|
||||||
|
Exec=$(echo ${DATA}| cut -d"#" -f2)
|
||||||
|
RealCmd=$(echo ${cmd} | cut -d"#" -f1)
|
||||||
|
ArgCmd=$(echo ${cmd} | cut -d"#" -f2)
|
||||||
|
if [[ "${RealCmd}" == "$Sonde" ]]
|
||||||
|
then
|
||||||
|
logger "Exec $Exec $Arg $cpt"
|
||||||
|
[ "$1" == '-d' ] && echo "############ Exec $Exec $Arg $cpt" 1>&2
|
||||||
|
bash ${ScriptDir}/${Exec} $ArgCmd
|
||||||
|
cpt=$((cpt+1))
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done < ${SondeFile}
|
||||||
|
[[ "${cpt}" -eq 0 ]] && logger "You Failed $Sonde $Exec $Arg"
|
||||||
|
|
||||||
|
done <&"${COPROC[0]}" >&"${COPROC[1]}"
|
||||||
|
done &
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${1}" == "stop" ]]
|
||||||
|
then
|
||||||
|
|
||||||
|
for Pid in $(ps axf| grep -E 'nc -l|monithor-server' | grep -v grep | awk '{print $1}' | sort )
|
||||||
|
do
|
||||||
|
kill ${Pid}
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
Exit() {
|
||||||
|
|
||||||
|
|
||||||
|
Val=$(echo $1| cut -d"|" -f1)
|
||||||
|
Txt=$(echo $1| cut -d"|" -f2)
|
||||||
|
echo "$Val|$Txt"
|
||||||
|
exit $Val
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
source $(dirname $0)/FunctionOutput
|
||||||
|
|
||||||
|
File="${1}"
|
||||||
|
|
||||||
|
[[ -z ${File} ]] && Exit "5|no argument"
|
||||||
|
|
||||||
|
|
||||||
|
[[ -f ${File} ]] && Exit "0|File $File exist" || Exit "2|File $File is NOT present"
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user