• Zenoss4.2.3对中文事件的部分支持修改


    Zenoss4.2.3貌似无法支持收集中文事件,修改了部分代码可满足部分收集中文事件的需求。

    注意,这不是完美或架构上完全正确解决方案,旨在解决以下部分问题:

    • 界面增加事件,dervice和summary包含的中文会丢失
    • 外部插入中文事件失败
    • window产生的中文日志无法收集

    有任何建议或问题欢迎讨论。


    背景

    Zenoss版本:zenoss_core-4.2.3-x86_64.vmware


    读代码准备

    曾经花了很大精力安装centos、eclipse搭建开发环境,资料收集能力问题,最终也只能读和修改一下代码,不是必须条件。

    实际上直接看、修改代码再看日志输出就可以了,准备:

    VS2010+Python Tools for Visual Studio:结合zenoss源代码包查看代码(文件间引用只能搜索查找),修改代码,查看日志。

    zenoss虚拟机:同于输出日志(安装ftp(vsftpd)方便传出日志查看)和查看实际运行结果。

    MySQL Workbench:查看zenoss的mysql数据库内容。


    总解决思路:

    zenoss运行环境python的defaultencoding是utf-8,数据库的大部分编码也为utf8,应该是考虑到编码问题要对英文外语言的支持。

    事件收集后通过rabbitMQ(不确定是这个名字)缓冲在插入到数据库,这个中间层暂时主要支持unicode。

    经测试,在使用这个中间层传输内容前,把中文或者(所有python字符串)转换为unicode格式可顺利传输,并且中文或英文格式内容可插到数据库内。

    经测试,数据库中插入的中文界面可直接显示。


    具体解决:

    界面增加事件,dervice和summary包含的中文会丢失

    问题所在:

    \Products\Zuul\facades\zepfacade.py内
    args = dict(evid=occurrence_uuid, summary=summary, severity=severity, device=device)”
    summary和device处理后被转换为utf8编码,中间层传输时过滤掉了,应在dict内使用unicode编码。
    解决方法:
    改为“args = dict(evid=occurrence_uuid, summary=summary.decode(), severity=severity, device=device.decode())”。

    外部插入中文事件失败

    问题所在:
    /Products/ZenEvents/events2/processing.py
    “eventContext.eventProxy.dedupid = '|'.join(dedupIdList)”报错,主要是编码问题。
    这是由于 dedupIdList存在加工语句
    “dedupIdList = [str(getattr(eventContext.eventProxy, field, '')) for
                               field in dedupFields]”
    summary由原来的unicode编码 处理后 被转换为utf8
    解决方法:
    改为“dedupIdList = []
                for field in dedupFields:
                    eachattr = getattr(eventContext.eventProxy, field, '')
                    if isinstance(eachattr, unicode):
                        dedupIdList.append(eachattr)
                    else:
                        dedupIdList.append(str(eachattr))”
    python字符串原来是unicode的字段不使用python内建函数str()处理。


    window产生的中文日志无法收集

    问题所在:
    zeneventlog.py内“evt = dict(
                device=self._devId,
                eventClassKey=evtkey,
                eventGroup=lrec.logfile,
                component=lrec.sourcename,
                ntevid=lrec.eventcode,
                summary=event_message,
                agent='zeneventlog',
                severity=sev,
                monitor=self._preferences.options.monitor,
                user=lrec.user,
                categorystring=lrec.categorystring,
                originaltime=ts,
                computername=lrec.computername,
                eventidentifier=lrec.eventidentifier,
                )”处理后summary等多个字段 被转换为utf8
    解决方法:
    改为
    “logfile = lrec.logfile
            if logfile and isinstance(logfile, str):
                logfile = logfile.decode()
            euser = lrec.user
            if euser and isinstance(euser, str):
                euser = euser.decode()
            ecategorystring = lrec.categorystring
            if ecategorystring and isinstance(ecategorystring, str):
                ecategorystring = ecategorystring.decode()


            evt = dict(
                device=self._devId.decode(),
                eventClassKey=evtkey.decode(),
                eventGroup=logfile,
                component=lrec.sourcename.decode(),
                ntevid=lrec.eventcode,
                summary=event_message.decode(),
                agent='zeneventlog',
                severity=sev,
                monitor=self._preferences.options.monitor,
                user=euser,
                categorystring=ecategorystring,
                originaltime=ts,
                computername=lrec.computername.decode(),
                eventidentifier=lrec.eventidentifier,
                )”凡是可能涉及中文的处理为unicode字符串。



  • 相关阅读:
    mybatis Column 'XXX' in where clause is ambiguous 错误
    IDEA 代码提示不区分大小写
    接口安全问题
    spring 事务问题
    js问题: is not a function
    Uncaught TypeError: form.attr is not a function 解决办法
    springmvc 跳转页面或者返回json
    ajax 跳转页面时添加header
    maven工程 添加本地jar依赖
    mysql 创建备份表
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/2992023.html
Copyright © 2020-2023  润新知