def get_clock(): data = sql.exec_selsql("select clock from zabbix.clock limit 1;", 0) if len(data) > 0: clock = data[0] else: clock = 0 sql.exec_updsql("insert into zabbix.clock value(\'0\');") if clock == 0: data = sql.exec_selsql("select min(clock) from zabbix.statistics;", 0) if len(data)>0 and data[0] != None: clock = data[0] else: clock = f.time2epoch(dt.now()) return clock
def get_history4detect(): startsec = get_clock() strsql = "select i.hostid, h.itemid, h.clock, h.value from zabbix.history as h \ left join zabbix.items as i on h.itemid = i.itemid \ where h.clock>\'%d\' order by i.hostid, h.itemid, h.clock;" % (startsec) return sql.exec_selsql(strsql)
def get_history4stat(): nowt = dt.today() endt = nowt - datetime.timedelta(hours=p.ml_end_hours) startt = endt - datetime.timedelta(days=p.ml_period_days) endsec = f.time2epoch(endt) startsec = f.time2epoch(startt) strsql = "select i.hostid, h.itemid, h.clock, h.value from zabbix.history as h \ join zabbix.items as i on h.itemid = i.itemid \ where h.clock<=\'%d\' and h.clock>=\'%d\' order by i.hostid, h.itemid, h.clock;" % (endsec, startsec) return sql.exec_selsql(strsql)
''' Created on Sep 13, 2015 @author: kot ''' import sys import cfg sys.path.append(cfg.workdir) import plib.sqlrun as sql if __name__ == '__main__': strsql = 'select count(*) from zabbix.history;' data = sql.exec_selsql(strsql); print data
def get_statistics(): strsql = "select hostid, itemid, avg, var from zabbix.statistics order by hostid, itemid;" return sql.exec_selsql(strsql)
def get_stats_accumulated(): strsql = "select hostid, itemid, clock, sample_num, average, variance, sqr_average from monitoring.stats_accumulated order by itemid;" return sql.exec_selsql(strsql)