|
@@ -43,8 +43,8 @@ isc.log.init("b10-stats-httpd", buffer=True)
|
|
|
logger = isc.log.Logger("stats-httpd")
|
|
|
|
|
|
# Some constants for debug levels.
|
|
|
-DBG_STATHTTPD_INIT = logger.DBGLVL_START_SHUT
|
|
|
-DBG_STATHTTPD_MESSAGING = logger.DBGLVL_COMMAND
|
|
|
+DBG_STATSHTTPD_INIT = logger.DBGLVL_START_SHUT
|
|
|
+DBG_STATSHTTPD_MESSAGING = logger.DBGLVL_COMMAND
|
|
|
|
|
|
# If B10_FROM_SOURCE is set in the environment, we use data files
|
|
|
# from a directory relative to that, otherwise we use the ones
|
|
@@ -187,11 +187,11 @@ class HttpHandler(http.server.BaseHTTPRequestHandler):
|
|
|
# Couldn't find neither specified module name nor
|
|
|
# specified item name
|
|
|
self.send_error(404)
|
|
|
- logger.error(STATHTTPD_SERVER_DATAERROR, err)
|
|
|
+ logger.error(STATSHTTPD_SERVER_DATAERROR, err)
|
|
|
return None
|
|
|
except Exception as err:
|
|
|
self.send_error(500)
|
|
|
- logger.error(STATHTTPD_SERVER_ERROR, err)
|
|
|
+ logger.error(STATSHTTPD_SERVER_ERROR, err)
|
|
|
return None
|
|
|
else:
|
|
|
self.send_response(200)
|
|
@@ -205,7 +205,7 @@ class HttpHandler(http.server.BaseHTTPRequestHandler):
|
|
|
"""overrides the parent method log_message()
|
|
|
to use the bind10 logging framework.
|
|
|
"""
|
|
|
- logger.debug(DBG_STATHTTPD_MESSAGING, STATHTTPD_HTTPLOG,
|
|
|
+ logger.debug(DBG_STATSHTTPD_MESSAGING, STATSHTTPD_HTTPLOG,
|
|
|
self.address_string(),
|
|
|
format%args)
|
|
|
|
|
@@ -271,7 +271,7 @@ class StatsHttpd:
|
|
|
def open_mccs(self):
|
|
|
"""Opens a ModuleCCSession object"""
|
|
|
# create ModuleCCSession
|
|
|
- logger.debug(DBG_STATHTTPD_INIT, STATHTTPD_STARTING_CC_SESSION)
|
|
|
+ logger.debug(DBG_STATSHTTPD_INIT, STATSHTTPD_STARTING_CC_SESSION)
|
|
|
self.mccs = isc.config.ModuleCCSession(
|
|
|
SPECFILE_LOCATION, self.config_handler, self.command_handler)
|
|
|
self.cc_session = self.mccs._session
|
|
@@ -282,7 +282,7 @@ class StatsHttpd:
|
|
|
return
|
|
|
self.mccs.send_stopping()
|
|
|
|
|
|
- logger.debug(DBG_STATHTTPD_INIT, STATHTTPD_CLOSING_CC_SESSION)
|
|
|
+ logger.debug(DBG_STATSHTTPD_INIT, STATSHTTPD_CLOSING_CC_SESSION)
|
|
|
self.mccs.close()
|
|
|
self.mccs = None
|
|
|
|
|
@@ -325,7 +325,7 @@ class StatsHttpd:
|
|
|
server_address, HttpHandler,
|
|
|
self.xml_handler, self.xsd_handler, self.xsl_handler,
|
|
|
self.write_log)
|
|
|
- logger.info(STATHTTPD_STARTED, server_address[0],
|
|
|
+ logger.info(STATSHTTPD_STARTED, server_address[0],
|
|
|
server_address[1])
|
|
|
return httpd
|
|
|
except (socket.gaierror, socket.error,
|
|
@@ -341,7 +341,7 @@ class StatsHttpd:
|
|
|
"""Closes sockets for HTTP"""
|
|
|
while len(self.httpd)>0:
|
|
|
ht = self.httpd.pop()
|
|
|
- logger.info(STATHTTPD_CLOSING, ht.server_address[0],
|
|
|
+ logger.info(STATSHTTPD_CLOSING, ht.server_address[0],
|
|
|
ht.server_address[1])
|
|
|
ht.server_close()
|
|
|
|
|
@@ -377,7 +377,7 @@ class StatsHttpd:
|
|
|
def stop(self):
|
|
|
"""Stops the running StatsHttpd objects. Closes CC session and
|
|
|
HTTP handling sockets"""
|
|
|
- logger.info(STATHTTPD_SHUTDOWN)
|
|
|
+ logger.info(STATSHTTPD_SHUTDOWN)
|
|
|
self.close_httpd()
|
|
|
self.close_mccs()
|
|
|
self.running = False
|
|
@@ -395,7 +395,7 @@ class StatsHttpd:
|
|
|
def config_handler(self, new_config):
|
|
|
"""Config handler for the ModuleCCSession object. It resets
|
|
|
addresses and ports to listen HTTP requests on."""
|
|
|
- logger.debug(DBG_STATHTTPD_MESSAGING, STATHTTPD_HANDLE_CONFIG,
|
|
|
+ logger.debug(DBG_STATSHTTPD_MESSAGING, STATSHTTPD_HANDLE_CONFIG,
|
|
|
new_config)
|
|
|
errors = []
|
|
|
if not self.mccs.get_module_spec().\
|
|
@@ -413,7 +413,7 @@ class StatsHttpd:
|
|
|
try:
|
|
|
self.open_httpd()
|
|
|
except HttpServerError as err:
|
|
|
- logger.error(STATHTTPD_SERVER_ERROR, err)
|
|
|
+ logger.error(STATSHTTPD_SERVER_ERROR, err)
|
|
|
# restore old config
|
|
|
self.load_config(old_config)
|
|
|
self.open_httpd()
|
|
@@ -425,18 +425,18 @@ class StatsHttpd:
|
|
|
"""Command handler for the ModuleCCSesson object. It handles
|
|
|
"status" and "shutdown" commands."""
|
|
|
if command == "status":
|
|
|
- logger.debug(DBG_STATHTTPD_MESSAGING,
|
|
|
- STATHTTPD_RECEIVED_STATUS_COMMAND)
|
|
|
+ logger.debug(DBG_STATSHTTPD_MESSAGING,
|
|
|
+ STATSHTTPD_RECEIVED_STATUS_COMMAND)
|
|
|
return isc.config.ccsession.create_answer(
|
|
|
0, "Stats Httpd is up. (PID " + str(os.getpid()) + ")")
|
|
|
elif command == "shutdown":
|
|
|
- logger.debug(DBG_STATHTTPD_MESSAGING,
|
|
|
- STATHTTPD_RECEIVED_SHUTDOWN_COMMAND)
|
|
|
+ logger.debug(DBG_STATSHTTPD_MESSAGING,
|
|
|
+ STATSHTTPD_RECEIVED_SHUTDOWN_COMMAND)
|
|
|
self.running = False
|
|
|
return isc.config.ccsession.create_answer(0)
|
|
|
else:
|
|
|
- logger.debug(DBG_STATHTTPD_MESSAGING,
|
|
|
- STATHTTPD_RECEIVED_UNKNOWN_COMMAND, command)
|
|
|
+ logger.debug(DBG_STATSHTTPD_MESSAGING,
|
|
|
+ STATSHTTPD_RECEIVED_UNKNOWN_COMMAND, command)
|
|
|
return isc.config.ccsession.create_answer(
|
|
|
1, "Unknown command: " + str(command))
|
|
|
|
|
@@ -621,13 +621,13 @@ if __name__ == "__main__":
|
|
|
stats_httpd = StatsHttpd()
|
|
|
stats_httpd.start()
|
|
|
except OptionValueError as ove:
|
|
|
- logger.fatal(STATHTTPD_BAD_OPTION_VALUE, ove)
|
|
|
+ logger.fatal(STATSHTTPD_BAD_OPTION_VALUE, ove)
|
|
|
sys.exit(1)
|
|
|
except isc.cc.session.SessionError as se:
|
|
|
- logger.fatal(STATHTTPD_CC_SESSION_ERROR, se)
|
|
|
+ logger.fatal(STATSHTTPD_CC_SESSION_ERROR, se)
|
|
|
sys.exit(1)
|
|
|
except HttpServerError as hse:
|
|
|
- logger.fatal(STATHTTPD_START_SERVER_INIT_ERROR, hse)
|
|
|
+ logger.fatal(STATSHTTPD_START_SERVER_INIT_ERROR, hse)
|
|
|
sys.exit(1)
|
|
|
except KeyboardInterrupt as kie:
|
|
|
- logger.info(STATHTTPD_STOPPED_BY_KEYBOARD)
|
|
|
+ logger.info(STATSHTTPD_STOPPED_BY_KEYBOARD)
|