I've added logs to cover these situations and modules:

Configuration reset
    Configuration Insert
    Configuration Update
    Report steps
    Monkey downloads
    Env startup logs

Also I've changed the logging init position so it covers every functions from main, some functions and vars are being called and init from import level, in order to log those situations I had to init the log system right on the beginning of the module.
This commit is contained in:
maor.rayzin 2018-05-31 19:27:26 +03:00
parent ad0d9f4567
commit f37fabaf75
5 changed files with 9 additions and 9 deletions

View File

@ -22,7 +22,7 @@ def load_env_from_file():
try: try:
__env_type = load_env_from_file() __env_type = load_env_from_file()
env = ENV_DICT[__env_type]() env = ENV_DICT[__env_type]()
logger.info('Monkey\'s env is: {0}'.format(env)) logger.info('Monkey\'s env is: {0}'.format(env.__class__.__name__))
except Exception: except Exception:
logger.error('Failed initializing environment', exc_info=True) logger.error('Failed initializing environment', exc_info=True)
raise raise

View File

@ -9,11 +9,15 @@ BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if BASE_PATH not in sys.path: if BASE_PATH not in sys.path:
sys.path.insert(0, BASE_PATH) sys.path.insert(0, BASE_PATH)
from cc.island_logger import json_setup_logging
# This is here in order to catch EVERYTHING, some functions are being called on imports the log init needs to be on top.
json_setup_logging(default_path='island_logger_default_config.json', default_level=logging.DEBUG)
logger = logging.getLogger(__name__)
from cc.app import init_app from cc.app import init_app
from cc.utils import local_ip_addresses from cc.utils import local_ip_addresses
from cc.environment.environment import env from cc.environment.environment import env
from cc.database import is_db_server_up from cc.database import is_db_server_up
from cc.island_logger import json_setup_logging
def main(): def main():
@ -21,9 +25,6 @@ def main():
from tornado.httpserver import HTTPServer from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop from tornado.ioloop import IOLoop
json_setup_logging(default_path='island_logger_default_config.json', default_level=logging.DEBUG)
logger = logging.getLogger(__name__)
mongo_url = os.environ.get('MONGO_URL', env.get_mongo_url()) mongo_url = os.environ.get('MONGO_URL', env.get_mongo_url())
while not is_db_server_up(mongo_url): while not is_db_server_up(mongo_url):

View File

@ -20,7 +20,7 @@ class ClientRun(flask_restful.Resource):
if monkey is not None: if monkey is not None:
is_monkey_running = not monkey["dead"] is_monkey_running = not monkey["dead"]
else: else:
logger.info("") logger.info("Monkey is not running")
is_monkey_running = False is_monkey_running = False
return jsonify(is_running=is_monkey_running) return jsonify(is_running=is_monkey_running)

View File

@ -1,6 +1,7 @@
import flask_restful
import logging import logging
import flask_restful
from cc.auth import jwt_required from cc.auth import jwt_required
from cc.services.island_logs import IslandLogService from cc.services.island_logs import IslandLogService
@ -16,4 +17,3 @@ class IslandLog(flask_restful.Resource):
return IslandLogService.get_log_file() return IslandLogService.get_log_file()
except Exception as e: except Exception as e:
logger.error('Monkey Island logs failed to download', exc_info=True) logger.error('Monkey Island logs failed to download', exc_info=True)

View File

@ -19,7 +19,6 @@ class MonkeyConfiguration(flask_restful.Resource):
config_json = json.loads(request.data) config_json = json.loads(request.data)
if 'reset' in config_json: if 'reset' in config_json:
ConfigService.reset_config() ConfigService.reset_config()
else: else:
ConfigService.update_config(config_json, should_encrypt=True) ConfigService.update_config(config_json, should_encrypt=True)
return self.get() return self.get()