Example #1
0
	def get_value_by_key(self, key):
		return_value = ""

		try:
			return_value = self.datas[key]
		except Exception, e:
			logger.error("while parsing json file")
Example #2
0
    def get_value_by_key(self, key):
        return_value = ""

        try:
            return_value = self.datas[key]
        except Exception, e:
            logger.error("while parsing json file")
Example #3
0
 def open_file_and_get_datas(self):
     try:
         with open(self.config_file) as data_file:
             self.datas = json.load(data_file)
     except:
         logger.error("[JSON_PARSER] fail to opening %s check the file" %
                      self.config_file)
Example #4
0
	def set_attr(self, datas):
		self.conexion_available = True
		credentials_string = 'mongodb://' + datas["mongo_user"] + ':' + datas["mongo_pwd"] + '@' + datas["mongo_host"] + ':' + str(datas["mongo_port"]) + '/' + datas["mongo_db"]

		try:
			self.client = MongoClient(credentials_string)
			self.db_connection = self.client[datas["mongo_db"]]
		except:
			logger.error("[MONGO_DRIVER] Mongo db connection fail !")
			self.conexion_available = False
Example #5
0
	def configuration_error_handler(self):
		self.config.start_reconection()
		self.stop_all_agents_thread()
		logger.error("Connection failed !")

		while (self.config.have_to_be_waited()):
			logger.info("Connection lost Hestia is trying to reconnect")
			self.delay()

		if not self.config.can_run():
			self.server_is_running = False
Example #6
0
    def configuration_error_handler(self):
        self.config.start_reconection()
        self.stop_all_agents_thread()
        logger.error("Connection failed !")

        while (self.config.have_to_be_waited()):
            logger.info("Connection lost Hestia is trying to reconnect")
            self.delay()

        if not self.config.can_run():
            self.server_is_running = False
Example #7
0
    def set_attr(self, datas):
        self.conexion_available = True
        credentials_string = 'mongodb://' + datas["mongo_user"] + ':' + datas[
            "mongo_pwd"] + '@' + datas["mongo_host"] + ':' + str(
                datas["mongo_port"]) + '/' + datas["mongo_db"]

        try:
            self.client = MongoClient(credentials_string)
            self.db_connection = self.client[datas["mongo_db"]]
        except:
            logger.error("[MONGO_DRIVER] Mongo db connection fail !")
            self.conexion_available = False
Example #8
0
	def write(self, value):
		try:
			if self.pin_type == "digital":
				if "1" in str(value):
					value = self.arduino.HIGH
				else:
					value = self.arduino.LOW
				self.arduino.digitalWrite(self.pin_number, value)
			elif self.pin_type == "analogic":
				self.arduino.analogWrite(self.pin_number, str(value))
		except:
			logger.error("Arduino communication fail !")
Example #9
0
	def read(self):
		value_to_return = ""

		try:
			if self.pin_type == "digital":
				value_to_return = self.arduino.digitalRead(self.pin_number)
			elif self.pin_type == "analogic":
				value_to_return = self.arduino.analogRead(self.pin_number)
		except:
			logger.error("Arduino communication fail !")

		return value_to_return
Example #10
0
    def try_to_reconnect(self):
        number_of_reconnection_attempt = 6
        delay = 10

        for i in range(0, number_of_reconnection_attempt):
            if self.server_can_run:
                self.is_trying_to_reconected = False
                pass

            try:
                self.server_can_run = self.all_ressources_are_available()
            except:
                self.is_trying_to_reconected = True

            if not self.server_can_run:
                logger.error("Reconnection failed !")
                time.sleep(delay)
            else:
                logger.info("Hestia is coming back !")
	def try_to_reconnect(self):
		number_of_reconnection_attempt = 6
		delay = 10

		for i in range(0, number_of_reconnection_attempt):
			if self.server_can_run:
				self.is_trying_to_reconected = False
				pass

			try:
				self.server_can_run = self.all_ressources_are_available()
			except:
				self.is_trying_to_reconected = True

			if not self.server_can_run:
				logger.error("Reconnection failed !")
				time.sleep(delay)
			else:
				logger.info("Hestia is coming back !")
Example #12
0
	def run(self):
		logger.info("Hestia is running !")

		while self.server_is_running:
			if not self.agents_threads_are_started:
				self.start_all_agents_thread()

			try:
				if self.config.all_ressources_are_available():
					self.delay()
				else:
					self.configuration_error_handler()
			except KeyboardInterrupt:
				self.server_is_running = False
			except:
				logger.error("[CRITICAL ERROR] ")
				self.server_is_running = False

		logger.info("Hestia is quitting !")

		sys.exit(0)
Example #13
0
    def run(self):
        logger.info("Hestia is running !")

        while self.server_is_running:
            if not self.agents_threads_are_started:
                self.start_all_agents_thread()

            try:
                if self.config.all_ressources_are_available():
                    self.delay()
                else:
                    self.configuration_error_handler()
            except KeyboardInterrupt:
                self.server_is_running = False
            except:
                logger.error("[CRITICAL ERROR] ")
                self.server_is_running = False

        logger.info("Hestia is quitting !")

        sys.exit(0)
Example #14
0
from src.server.server.server_core import server_core
from src.commons.utils.logger import logger

import sys

if __name__ == "__main__":
	args = sys.argv[1:]

	#try:
	if len(args) >= 2:
		logger.set_level(args[1])
	elif len(args) <= 0:
		logger.error("[MAIN] Please add configuration file path to launch command parameters")

	logger.info("Hello !")
	server = server_core(args[0])

	#start all the threads
	server.run()

	logger.info("Bye !")
	#except:
	#	logger.error("[CRITICAL_ERROR] Hestia is stoping !]")
	#	exit(1)

	exit(0)
Example #15
0
	def open_file_and_get_datas(self):
		try:
			with open(self.config_file) as data_file:
					self.datas = json.load(data_file)
		except:
			logger.error("[JSON_PARSER] fail to opening %s check the file" % self.config_file)
Example #16
0
from src.server.server.server_core import server_core
from src.commons.utils.logger import logger

import sys

if __name__ == "__main__":
    args = sys.argv[1:]

    #try:
    if len(args) >= 2:
        logger.set_level(args[1])
    elif len(args) <= 0:
        logger.error(
            "[MAIN] Please add configuration file path to launch command parameters"
        )

    logger.info("Hello !")
    server = server_core(args[0])

    #start all the threads
    server.run()

    logger.info("Bye !")
    #except:
    #	logger.error("[CRITICAL_ERROR] Hestia is stoping !]")
    #	exit(1)

    exit(0)