db.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:zabbix-alert 作者: annProg 项目源码 文件源码
def updateDB(file_db, msg):
    db = init_DB(file_db)
    if not db:
        data = msg
    else:
        namelist = db['??'].split(",")
        if msg['??'] not in namelist:
            namelist.append(msg['??'])
        db['??'] = ",".join(namelist)
        try:
            db['eventid'] = db['eventid'] + "," + msg['eventid']
        except:
            pass
#       if db['??'] != msg['??']:
#           db['??'] = db['??'] + "," + msg['??']
        if "IP" in msg and "IP" in db:
            if db['IP'] != msg['IP']:
                db['IP'] = db['IP'] + "," + msg['IP']
        db['??'] = db['??'] + msg['??']
        data = db

    with open(file_db, 'w') as f:
        fcntl.flock(f, fcntl.LOCK_EX)
        json.dump(data, f, ensure_ascii=False)
        fcntl.flock(f, fcntl.LOCK_UN)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号