当前位置: 首页>>代码示例>>Python>>正文


Python OpServerUtils.messages_data_dict_to_str方法代码示例

本文整理汇总了Python中opserver_util.OpServerUtils.messages_data_dict_to_str方法的典型用法代码示例。如果您正苦于以下问题:Python OpServerUtils.messages_data_dict_to_str方法的具体用法?Python OpServerUtils.messages_data_dict_to_str怎么用?Python OpServerUtils.messages_data_dict_to_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在opserver_util.OpServerUtils的用法示例。


在下文中一共展示了OpServerUtils.messages_data_dict_to_str方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: display

# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import messages_data_dict_to_str [as 别名]
    def display(self, result):
        if result == [] or result is None:
            return
        messages_dict_list = result
        # Setup logger and syslog handler
        if self._args.send_syslog:
            logger = logging.getLogger()
            logger.setLevel(logging.DEBUG)
            syslog_handler = logging.handlers.SysLogHandler(
                address = (self._args.syslog_server, self._args.syslog_port))
            contrail_formatter = logging.Formatter('contrail: %(message)s')
            syslog_handler.setFormatter(contrail_formatter)
            logger.addHandler(syslog_handler)
            self._logger = logger

        # For json we will be outputting list of dicts so open the list here
        if self._args.json:
            first = True
            self.output('[', SandeshLevel.INVALID)
        for messages_dict in messages_dict_list:

            if VizConstants.TIMESTAMP in messages_dict:
                message_dt = datetime.datetime.fromtimestamp(
                    int(messages_dict[VizConstants.TIMESTAMP]) /
                    OpServerUtils.USECS_IN_SEC)
                message_dt += datetime.timedelta(
                    microseconds=
                    (int(messages_dict[VizConstants.TIMESTAMP]) %
                     OpServerUtils.USECS_IN_SEC))
                message_ts = message_dt.strftime(OpServerUtils.TIME_FORMAT_STR)
            else:
                message_ts = 'Time: NA'
            messages_dict[VizConstants.TIMESTAMP] = message_ts
            if VizConstants.SOURCE in messages_dict:
                source = messages_dict[VizConstants.SOURCE]
            else:
                source = 'Source: NA'
            if VizConstants.NODE_TYPE in messages_dict:
                node_type = messages_dict[VizConstants.NODE_TYPE]
            else:
                node_type = ''
            if VizConstants.MODULE in messages_dict:
                module = messages_dict[VizConstants.MODULE]
            else:
                module = 'Module: NA'
            if VizConstants.INSTANCE_ID in messages_dict:
                instance_id = messages_dict[VizConstants.INSTANCE_ID]
            else:
                instance_id = ''
            if VizConstants.MESSAGE_TYPE in messages_dict:
                message_type = messages_dict[VizConstants.MESSAGE_TYPE]
            else:
                message_type = 'Message Type: NA'
            if VizConstants.SANDESH_TYPE in messages_dict:
                sandesh_type = messages_dict[VizConstants.SANDESH_TYPE]
            else:
                sandesh_type = SandeshType.INVALID
            # By default SYS_DEBUG
            sandesh_level = SandeshLevel.SYS_DEBUG
            if self._args.object_type is None:
                if VizConstants.CATEGORY in messages_dict:
                    category = messages_dict[VizConstants.CATEGORY]
                else:
                    category = 'Category: NA'
                if VizConstants.LEVEL in messages_dict:
                    sandesh_level = messages_dict[VizConstants.LEVEL]
                    level = SandeshLevel._VALUES_TO_NAMES[sandesh_level]
                else:
                    level = 'Level: NA'
                messages_dict[VizConstants.LEVEL] = level
                if VizConstants.SEQUENCE_NUM in messages_dict:
                    seq_num = messages_dict[VizConstants.SEQUENCE_NUM]
                else:
                    seq_num = 'Sequence Number: NA'
                if VizConstants.DATA in messages_dict:
                    # Convert XML data to dict
                    if self._args.raw:
                        data_str = messages_dict[VizConstants.DATA]
                    else:
                        OpServerUtils.messages_xml_data_to_dict(
                            messages_dict, VizConstants.DATA)
                        if isinstance(messages_dict[VizConstants.DATA], dict):
                            data_dict = messages_dict[VizConstants.DATA]
                            data_str = OpServerUtils.messages_data_dict_to_str(
                                data_dict, message_type, sandesh_type)
                        else:
                            data_str = messages_dict[VizConstants.DATA]
                else:
                    data_str = 'Data not present'
                if self._args.json:
                    if not first:
                        self.output(", ", sandesh_level)
                    else:
                        first = False
                    OpServerUtils.messages_dict_scrub(messages_dict)
                    self.output(messages_dict, sandesh_level)
                else:
                    if self._args.trace is not None:
                        trace_str = '{0} {1}:{2} {3}'.format(
                            message_ts, message_type, seq_num, data_str)
#.........这里部分代码省略.........
开发者ID:bokuden,项目名称:contrail-controller,代码行数:103,代码来源:log.py


注:本文中的opserver_util.OpServerUtils.messages_data_dict_to_str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。