Add logging to Alexandria.
This will be helpful later to debug the application.
This commit is contained in:
parent
19fb04ed21
commit
c16cfd05bd
|
@ -5,6 +5,8 @@ from flask import jsonify
|
|||
from flask import request
|
||||
import sys
|
||||
import pprint
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
import config
|
||||
import models
|
||||
import configuration_item
|
||||
|
@ -40,6 +42,7 @@ def api_driver(driver_name):
|
|||
@app.route('/shutdown', methods=['POST'])
|
||||
def shutdown():
|
||||
shutdown_server()
|
||||
app.logger.info("Stopping Alexandria...")
|
||||
return 'Server shutting down...'
|
||||
|
||||
@app.route('/bruno', methods=['POST'])
|
||||
|
@ -50,19 +53,26 @@ def bruno():
|
|||
|
||||
@app.route('/ci', methods=['POST'])
|
||||
def create_ci():
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
||||
ci = configuration_item.ConfigurationItem(request.json["uuid"],
|
||||
request.json["ip_mgmt"],
|
||||
request.json["login"],
|
||||
request.json["password"])
|
||||
|
||||
# Error cas uuid already available
|
||||
# TODO : Error case uuid already available
|
||||
# Uuid malformed
|
||||
# Generate a random uuid (check uuid module) if uuid = None
|
||||
|
||||
alexandria_cis.update({request.json["uuid"]: ci })
|
||||
|
||||
#driver_list = conf_file.get_drivers()
|
||||
|
||||
#for driver in driver_list:
|
||||
#driver.get(ci)
|
||||
pp.pprint(alexandria_cis)
|
||||
|
||||
app.logger.debug("Debug message")
|
||||
|
||||
return ("ok")
|
||||
|
||||
|
@ -92,6 +102,18 @@ def shutdown_server():
|
|||
raise RuntimeError('Not running with the Werkzeug Server')
|
||||
func()
|
||||
|
||||
def configure_logger(logger,logfile):
|
||||
|
||||
formatter = logging.Formatter(
|
||||
'%(asctime)s :: %(levelname)s :: %(message)s'
|
||||
)
|
||||
file_handler = RotatingFileHandler(logfile, 'a', 1000000, 1)
|
||||
|
||||
# Add logger to file
|
||||
file_handler.setLevel(logging.DEBUG)
|
||||
file_handler.setFormatter(formatter)
|
||||
logger.addHandler(file_handler)
|
||||
|
||||
|
||||
class Alexandria(object):
|
||||
def __init__(self):
|
||||
|
@ -122,9 +144,11 @@ class Alexandria(object):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Vars
|
||||
# Vars
|
||||
app_logfile = "/var/log/alexandria/alexandria.log"
|
||||
|
||||
global alexandria
|
||||
|
||||
|
||||
alexandria = Alexandria()
|
||||
|
||||
# Define a PrettyPrinter for debugging.
|
||||
|
@ -133,6 +157,9 @@ if __name__ == "__main__":
|
|||
# Define a structure to handle ci
|
||||
alexandria_cis = {}
|
||||
|
||||
# Configure Flask logger
|
||||
configure_logger(app.logger, app_logfile)
|
||||
|
||||
|
||||
# Debugging stuff to remove later.
|
||||
print alexandria.model.reference_items
|
||||
|
@ -141,6 +168,8 @@ if __name__ == "__main__":
|
|||
print alexandria.drivers.itop.driver_type
|
||||
#pp.pprint(models.EthernetInterface) # debugging example.
|
||||
#pp.pprint(models.Manager) # debugging example.
|
||||
app.logger.info("Starting Alexandria...")
|
||||
app.run(port=int(alexandria.conf_file.get_alexandria_port()))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue