1 # -------------------------------------------------------------------------
2 # Copyright (c) 2019 AT&T Intellectual Property
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
23 from onaplogging.mdcContext import MDC
26 def default_server_info():
27 # If not set or purposely set = None, then set default
28 if MDC.get('server') is None:
30 server = socket.getfqdn()
31 except Exception as err:
33 server = socket.gethostname()
34 except Exception as err:
36 MDC.put('server', server)
37 if MDC.get('serverIPAddress') is None:
39 server_ip_address = socket.gethostbyname(self._fields['server'])
41 server_ip_address = ""
42 MDC.put('serverIPAddress', server_ip_address)
46 MDC.put('instanceUUID', uuid.uuid1())
47 MDC.put('serviceName', 'OOF_OSDF')
48 MDC.put('threadID', threading.currentThread().getName())
50 MDC.put('requestID', 'N/A')
51 MDC.put('partnerName', 'N/A')
54 def mdc_from_json(request_json):
56 MDC.put('requestID', request_json['requestInfo']['requestId'])
57 MDC.put('partnerName', request_json['requestInfo']['sourceId'])