X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=test%2Fcr%2Fapp%2Fcr.py;h=9e04d5759720badd44638d583c7d8e93fe507a57;hb=c963b73942867f631f9e5708e28025140afcb893;hp=fa42c20478863ec4bbc3c99349096f1b9376928f;hpb=38c1f88849d9b529007ac07daeeca2ca0291793b;p=nonrtric.git diff --git a/test/cr/app/cr.py b/test/cr/app/cr.py index fa42c204..9e04d575 100644 --- a/test/cr/app/cr.py +++ b/test/cr/app/cr.py @@ -23,6 +23,7 @@ from datetime import datetime import json import traceback import logging +import socket # Disable all logging of GET on reading counters and db class AjaxFilter(logging.Filter): @@ -58,6 +59,23 @@ CAUGHT_EXCEPTION="Caught exception: " SERVER_ERROR="Server error :" TIME_STAMP="cr-timestamp" +# Remote host lookup and print host name +def remote_host_logging(request): + + if request.environ.get('HTTP_X_FORWARDED_FOR') is None: + host_ip=str(request.environ['REMOTE_ADDR']) + else: + host_ip=str(request.environ['HTTP_X_FORWARDED_FOR']) + prefix='::ffff:' + if (host_ip.startswith('::ffff:')): + host_ip=host_ip[len(prefix):] + try: + name, alias, addresslist = socket.gethostbyaddr(host_ip) + print("Calling host: "+str(name)) + except Exception: + print("Calling host not possible to retrieve IP: "+str(host_ip)) + + #I'm alive function @app.route('/', methods=['GET']) @@ -131,6 +149,7 @@ def events_write(id): try: print("Received callback for id: "+id +", content-type="+request.content_type) + remote_host_logging(request) try: if (request.content_type == MIME_JSON): data = request.data