一个删除zabbix历史数据的小脚本

好久之前写的一个小脚本,现在看来是没用了,放到博客,做个记录。

cat purge_history.py

#!/usr/bin/env python
#coding: utf-8
#Refrence:http://leek2006.blog.163.com/blog/static/89085615201261210055637/

import time
import torndb

DB = torndb.Connection(host="/tmp/mysql.sock",database="zabbix",user="root",password="password")

def purge():
    while True:
        nt = time.time() - 7*86400
        lt = DB.get("select * from history_uint limit 1")
        if lt['clock'] < nt :
            DB.execute("delete from history_uint limit 10000")
        else:
            break

if __name__ == "__main__":
    purge()

参考资料:

删除zabbix 历史数据:http://leek2006.blog.163.com/blog/static/89085615201261210055637/