import logging # Logs
import time # sleep
import string # split strings
-import socket # client/server TCP networking
+import socket # client/server TCP networking
import os,sys,inspect # for the following
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"modules")))
if not conn: break
data = conn.recv(MY_BUFFER_SIZE)
if not data: break
- logger.info("Received HB from " + str(addr) + " : " + str(data))
+ logger.info("HB : Received HB from " + str(addr) + " : " + str(data))
k = pyDes.des(b"DEADJACK", pyDes.CBC, b"\2\2\2\2\2\2\2\2", pad=None, padmode=2)
try:
- logger.info("HB packet content is : " + str(data))
- logger.info("decrypting")
+ logger.debug("HB : HB packet content is : " + str(data))
+ logger.debug("HB : decrypting")
data = k.decrypt(data)
- logger.info("HB packet content is : " + str(data))
+ logger.debug("HB : HB packet content is : " + str(data))
data = data.decode('UTF-8')
- logger.info("decode from UTF-8")
- logger.info("HB packet content is : " + str(data))
+ logger.debug("HB : decode from UTF-8")
+ logger.debug("HB : HB packet content is : " + str(data))
if data == "HB":
- logger.info("sending HB packet back : Received")
+ logger.info("HB : sending HB packet back")
DEST_MESSAGE = bytes("Received", 'UTF-8')
DEST_MESSAGE = k.encrypt(DEST_MESSAGE)
# Sending
conn.send(DEST_MESSAGE)
conn.close()
except:
- logger.info("Received an invalid HB packet")
+ logger.warn("HB : Received an invalid HB packet")
time.sleep(1)
- logger.error("I am out of the infinit HB loop !")
- return False
+ logger.error("HB : I am out of the infinit HB loop !")
+ return 1
+
+ def cleanfs(void):
+ df = 50
+ #seuil = df
+ while True:
+ if df > 5:
+ logger.info("DF : /home/transmission nearly full : " + str(df) + "%")
+ logger.debug("Faut netoyer ...")
+ time.sleep(30)
+ return 1
+
# All functions definitions took place above
try:
while True:
time.sleep(30)
+ # checking if HB child is alive or not
+ if not hbp.is_alive() or hpb.exitcode != None:
+ logger.error("HeartBeat child process seams dead.")
+ break
except:
logger.error("Main infinit while loop interrupted : aborting")
hbp.stop()