Commit 96e96eaf authored by Joanne Hugé's avatar Joanne Hugé

Clean up lopcomm RRH stats script

parent c7be7a3a
...@@ -24,7 +24,7 @@ md5sum = 6e0a052bd0ca08cc0c7b4880d3deffcc ...@@ -24,7 +24,7 @@ md5sum = 6e0a052bd0ca08cc0c7b4880d3deffcc
[lopcomm-rrh-stats.jinja2.py] [lopcomm-rrh-stats.jinja2.py]
_update_hash_filename_ = lopcomm-rrh-stats.jinja2.py _update_hash_filename_ = lopcomm-rrh-stats.jinja2.py
md5sum = e75be302ba6782c8d6c9fab08845331a md5sum = 85d735779c1351f8ad2dcbef3742cf5d
[template-lte-enb-epc] [template-lte-enb-epc]
_update_hash_filename_ = instance-enb-epc.jinja2.cfg _update_hash_filename_ = instance-enb-epc.jinja2.cfg
......
...@@ -14,11 +14,14 @@ class LopcommNetconfClient: ...@@ -14,11 +14,14 @@ class LopcommNetconfClient:
log_file = "{{ log_file }}" log_file = "{{ log_file }}"
self.logger = logging.getLogger('logger') self.logger = logging.getLogger('logger')
self.logger.setLevel(logging.INFO) self.json_logger = logging.getLogger('json_logger')
self.logger.setLevel(logging.DEBUG)
self.json_logger.setLevel(logging.DEBUG)
handler = RotatingFileHandler(log_file, maxBytes=30000, backupCount=2) handler = RotatingFileHandler(log_file, maxBytes=30000, backupCount=2)
formatter = logging.Formatter('{"time": "%(asctime)s", "log_level": "%(levelname)s", "message": "%(message)s", "data": %(data)s}') formatter = logging.Formatter('{"time": "%(asctime)s", "log_level": "%(levelname)s", "message": "%(message)s", "data": %(data)s}')
handler.setFormatter(formatter) handler.setFormatter(formatter)
self.logger.addHandler(handler) self.json_logger.addHandler(handler)
if {{ testing }}: if {{ testing }}:
return return
...@@ -28,6 +31,8 @@ class LopcommNetconfClient: ...@@ -28,6 +31,8 @@ class LopcommNetconfClient:
if {{ testing }}: if {{ testing }}:
return return
logger.info('Connecting to %s, user %s...' % ((host, port), user))
self.conn = manager.connect(host=host, self.conn = manager.connect(host=host,
port=port, port=port,
username=user, username=user,
...@@ -38,17 +43,30 @@ class LopcommNetconfClient: ...@@ -38,17 +43,30 @@ class LopcommNetconfClient:
}, },
hostkey_verify=False) hostkey_verify=False)
logger.info('Connection to %s successful' % ((host, port),))
def subscribe(self):
# Filter not compatible between ncclient and netconf server
#result = self.conn.create_subscription(filter=('xpath', '/o-ran-fm:*')) #result = self.conn.create_subscription(filter=('xpath', '/o-ran-fm:*'))
sub = self.conn.create_subscription() sub = self.conn.create_subscription()
logger.info('Subscription to %s successful' % ((host, port),))
def get_notification(self):
result = None result = None
while result == None: while result == None:
result = self.conn.take_notification(block=True, timeout=60) logger.debug('Waiting for notification from %s...' % ((host, port),))
result_in_xml = result._raw result = self.conn.take_notification(block=True)
data_dict = xmltodict.parse(result_in_xml) if result:
result_in_json = json.dumps(data_dict) logger.debug('Got new notification from %s...' % ((host, port),))
self.logger.info('', extra={'data': result_in_json}) result_in_xml = result._raw
data_dict = xmltodict.parse(result_in_xml)
result_in_json = json.dumps(data_dict)
self.json_logger.info('', extra={'data': result_in_json})
def close(self): def close(self):
# Close not compatible between ncclient and netconf server
#self.conn.close() #self.conn.close()
pass pass
...@@ -57,9 +75,13 @@ if __name__ == '__main__': ...@@ -57,9 +75,13 @@ if __name__ == '__main__':
nc = LopcommNetconfClient() nc = LopcommNetconfClient()
while True: while True:
try: try:
nc.connect("fe80::20a:ff:fe00:1020%slaptap6", 830, "oranuser", "oranpassword") nc.connect("192.168.0.210", 830, "oranuser", "oranpassword")
time.sleep(10) nc.subscribe()
while True:
nc.get_notification()
except Exception as e: except Exception as e:
nc.logger.debug('Got exception, waiting 10 seconds before reconnecting...')
nc.logger.debug(e) nc.logger.debug(e)
time.sleep(10)
finally: finally:
nc.close() nc.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment