Ejemplo n.º 1
0
def MemoryMsg():
    memory = x.MemoryUsage()
    percent = memory['percent']
    warn = cf.yamls['memory']['warning']
    crit = cf.yamls['memory']['critical']
    memory_q = db.db.search(db.query['memory'])
    if len(memory_q) < 1:
        record = db.DB('memory', 'percent', percent, 'False')
        db.db.insert(record)
    else:
        memory_q = (memory_q[-1])
        p = memory_q['memory']['percent']
        f = memory_q['memory']['flag']
        if p >= crit:
            danger = msg.MemoryPercent(memory['percent'], hostname)[2]
            alert.Slack(danger, 'Alarm', 'danger', 'high', str(date))
            record = db.DB('memory', 'percent', percent, 'True')
            db.db.insert(record)
        if p >= warn and p < crit:
            warning = msg.MemoryPercent(memory['percent'], hostname)[1]
            alert.Slack(warning, 'Alarm', 'warning', 'medium', str(date))
            record = db.DB('memory', 'percent', percent, 'True')
            db.db.insert(record)
        if p < warn and f == db.flag:
            normal = msg.MemoryPercent(memory['percent'], hostname)[0]
            alert.Slack(normal, 'Alarm', 'good', 'low', str(date))
            record = db.DB('memory', 'percent', percent, 'False')
            db.db.insert(record)
        if p < warn and f != db.flag:
            nothing = "Will do nothing"
Ejemplo n.º 2
0
def CpuMsg():
    average = GetCpuAvg()
    warn = cf.yamls['cpu']['warning']
    crit = cf.yamls['cpu']['critical']
    cpu_q = db.db.search(db.query['cpu'])
    if len(cpu_q) < 1:
        record = db.DB('cpu', 'average', average, 'False')
        db.db.insert(record)
    else:
        cpu_q = (cpu_q[-1])
        p = cpu_q['cpu']['average']
        f = cpu_q['cpu']['flag']
        if p >= crit:
            danger = msg.CpuLoadAvg(str(average), hostname)[2]
            alert.Slack(danger, 'Alarm', 'danger', 'high', str(date))
            record = db.DB('cpu', 'average', average, 'True')
            db.db.insert(record)
        if p >= warn and p < crit:
            warning = msg.CpuLoadAvg(str(avarage), hostname)[1]
            alert.Slack(warning, 'Alarm', 'warning', 'medium', str(date))
            record = db.DB('cpu', 'average', average, 'True')
            db.db.insert(record)
        if p < warn and f == db.flag:
            normal = msg.CpuLoadAvg(str(average), hostname)[0]
            alert.Slack(normal, 'Alarm', 'good', 'low', str(date))
            record = db.DB('cpu', 'average', average, 'False')
            db.db.insert(record)
        if p < warn and f != db.flag:
            nothing = "Will do nothing"
Ejemplo n.º 3
0
def SslValidate():
    domains = GetDomains('ssl')
    norm = cf.yamls['ssl_validate']['normal']
    warn = cf.yamls['ssl_validate']['warning']
    for domain in domains:
        expire_date = do.ssl_check(domain)
        remaining = expire_date - today
        ssl_query = db.db.search(db.query[domain])
        if len(ssl_query) < 1:
            record = db.DB(domain, 'remaining', remaining.days, 'False')
            db.db.insert(record)
        else:
            ssl_query = (ssl_query[-1])
            f = ssl_query[domain]['flag']
            if remaining.days < warn:
                warning = msg.SslChek(domain, remaining.days)[1]
                alert.Slack(warning, 'Alarm', 'danger', 'high', str(date))
                record = db.DB(domain, 'remaining', remaining.days, 'True')
                db.db.insert(record)
            if remaining.days > norm and f == db.flag:
                normal = msg.SslChek(domain, remaining.days)[0]
                alert.Slack(normal, 'Alarm', 'good', 'normal', str(date))
                record = db.DB(domain, 'remaining', remaining.days, 'False')
                db.db.insert(record)
            if remaining.days > norm and f != db.flag:
                nothing = "Will do nothing"
Ejemplo n.º 4
0
def DomainUptime():
    domains = GetDomains('uptime')
    for domain in domains:
        dom = db.db.search(db.query[domain])
        if len(dom) < 1:
            record = db.DB(domain, 'status', 'up', 'False')
            db.db.insert(record)
        else:
            dom = (dom[-1])
            f = dom[domain]['flag']
            try:
                health = do.url_uptime(domain)
                if health == 502 or health == 503 or health == 504:
                    down = msg.UrlUp(domain)[1]
                    alert.Slack(down, 'Alarm', 'danger', 'high', str(date))
                    record = db.DB(domain, 'status', 'down', 'True')
                    db.db.insert(record)
                if health in range(200, 399) and f == db.flag:
                    up = msg.UrlUp(domain)[0]
                    alert.Slack(up, 'Alarm', 'good', 'normal', str(date))
                    record = db.DB(domain, 'status', 'up', 'False')
                    db.db.insert(record)
                if health in range(200, 399) and f != db.flag:
                    nothing = "Will do nothing"
            except do.requests.exceptions.ConnectionError:
                notvalid = msg.UrlUp(domain)[2]
                alert.Slack(notvalid, 'Alarm', 'warning', 'medium', str(date))
Ejemplo n.º 5
0
def DiskMsg():
    partitions = GetDisks()
    warn = cf.yamls['disk']['warning']
    crit = cf.yamls['disk']['critical']
    for partition in partitions:
        percent = x.MapDiskUsage()[partition][3]
        disk = db.db.search(db.query[partition])
    if len(disk) < 1:
        record = db.DB(partition, 'percent', percent, 'False')
        db.db.insert(record)
    else:
        disk = (disk[-1])
        p = disk[partition]['percent']
        f = disk[partition]['flag']
        if p >= crit:
            danger = msg.DiskPercent(partition, percent, hostname)[2]
            alert.Slack(danger, 'Alarm', 'danger', 'high', str(date))
            record = db.DB(partition, 'percent', percent, 'True')
            db.db.insert(record)
        if p >= warn and p < crit:
            warning = msg.DiskPercent(partition, percent, hostname)[1]
            alert.Slack(warning, 'Alarm', 'warning', 'medium', str(date))
            record = db.DB(partition, 'percent', percent, 'True')
            db.db.insert(record)
        if p < warn and f == db.flag:
            normal = msg.DiskPercent(partition, percent, hostname)[0]
            alert.Slack(normal, 'Alarm', 'good', 'low', str(date))
            record = db.DB(partition, 'percent', percent, 'False')
            db.db.insert(record)
        if p < warn and f != db.flag:
            nothing = "Will do nothing"
Ejemplo n.º 6
0
def SwapMsg():
    swap = x.Swap()
    percent = swap['percent']
    warn = cf.yamls['swap']['warning']
    crit = cf.yamls['swap']['critical']
    swap_q = db.db.search(db.query['swap'])
    if len(swap_q) < 1:
        record = db.DB('swap', 'percent', percent, 'False')
        db.db.insert(record)
    else:
        swap_q = (swap_q[-1])
        p = swap_q['swap']['percent']
        f = swap_q['swap']['flag']
        if p >= crit:
            danger = msg.SwapPercent(swap['percent'], hostname)[2]
            alert.Slack(danger, 'Alarm', 'danger', 'high', str(date))
            record = db.DB('swap', 'percent', percent, 'True')
            db.db.insert(record)
        if p >= warn and p < crit:
            warning = msg.SwapPercent(swap['percent'], hostname)[1]
            alert.Slack(warning, 'Alarm', 'warning', 'medium', str(date))
            record = db.DB('swap', 'percent', percent, 'True')
            db.db.insert(record)
        if p < warn and f == db.flag:
            normal = msg.SwapPercent(swap['percent'], hostname)[0]
            alert.Slack(normal, 'Alarm', 'good', 'low', str(date))
            record = db.DB('swap', 'percent', percent, 'False')
            db.db.insert(record)
        if p < warn and f != db.flag:
            nothing = "Will do nothing"
Ejemplo n.º 7
0
def main():
    dirname = "hq_shfe_k1"
    #dirname = "hq_dce_k1"
    # dirname = "hq_cffex_k1"
    # dirname = "hq_czce_k1"
    # contract = "SR"
    root_dir = os.getcwd()
    fullpath = "%s\\%s" % (root_dir, dirname)
    if not os.path.exists(fullpath):
        os.mkdir(fullpath)

    # db_host = "183.131.76.91"
    # db_user = "******"
    # db_pwd  = "P)O(I*U&Y^"
    # db_dbase= "stock"
    # db_port = 3308
    db_host = "www.5656k.com"
    db_user = "******"
    db_pwd = "P)O(I*U&Y^"
    db_dbase = "stock_realtime"
    db_port = 3308

    database = db.DB(host=db_host,
                     user=db_user,
                     passwd=db_pwd,
                     db=db_dbase,
                     table_name='',
                     port=db_port)

    # sqlStatement = "SELECT DISTINCT InstrumentID AS FileName FROM %s WHERE `InstrumentID` LIKE '%%%s%%'" % (dirname, contract)
    # print sqlStatement
    # database.Execute(sqlStatement)
    # name_info_list = database.FetchAll()

    # contracts = [c[0] for c in name_info_list]
    # contracts = ["ru1509"]
    contracts = ["rb1805"]

    for name in contracts:
        out = open("%s\\%s.txt" % (fullpath, name), "wb")

        sqlStatement = "SELECT Time,OpenPrice,HighestPrice,LowestPrice,ClosePrice,Volume FROM %s WHERE `InstrumentID` = '%s' AND \
                       `Time` > 1705311600 AND `Time` < 1803201600 ORDER BY `Time`" % (
            dirname, name)
        database.Execute(sqlStatement)

        contract_info_list = database.FetchAll()
        for contract_info in contract_info_list:
            time = int(contract_info[0])
            time_str = "%u/%02u/%02u-%02u:%02u" % (
                2000 + int(time / 100000000), int(time / 1000000) % 100,
                int(time / 10000) % 100, int(time / 100) % 100, time % 100)
            open_price = float(contract_info[1])
            high_price = float(contract_info[2])
            low_price = float(contract_info[3])
            close_price = float(contract_info[4])
            volume = float(contract_info[5])

            content = "%s\t%.04f\t%.04f\t%.04f\t%.04f\t%.04f\r\n" % (
                time_str, open_price, high_price, low_price, close_price,
                volume)

            out.write(content)

        out.close()