예제 #1
0
def alert(to_email, reason):
    smtp_server = config.smtp_server
    smtp_user   = config.smtp_user
    smtp_pass   = config.smtp_pass
    from_email  = config.from_email
    subject     = config.subject
    if not DEBUG:
        bpomail.sendMail(smtp_server, smtp_user, smtp_pass, from_email, to_email, subject, reason)
예제 #2
0
def main():
    now = datetime.datetime.now()
    hours = hourlist(now)

    checkcmd = 'ls ' + os.path.join(config.dirname, now.strftime('%Y%m%d'))

    oss_missing = checkoss(hours, now)
    host_missing = checkhost(config.target, checkcmd, hours)

    #check the oss_missing
    if oss_missing:
        print "@OSS, missing: ", oss_missing
    else:
        print "@OSS, No missing."

    #check the host_missing
    if isinstance(host_missing, str):
        print "Could not connect to the instance: %s !" % config.target
        sys.exit(0)

    elif host_missing:
        print "@source host, missing: ", host_missing, oss_missing
    else:
        print "@source host, NO missing."
        sys.exit(0)

    if oss_missing and not DEBUG:
        remote_source = bporemote.Remote()
        remote_source.add_host(config.source)
        remote_target= bporemote.Remote()
        remote_target.add_host(config.target)

        for h in oss_missing:
            f = "%s.%s.log" %(config.prefix, h)
            sfile = os.path.join(config.dirname, h[:8], f)
            ossfile = os.path.join(config.oss_pre, h[:4], h[4:6], h[6:8], f+'.gz')
            try:
                cmd = 'gzip -f %s' % sfile
                remote_source.run_once(cmd)
            except:
                pass
            cmd = 'osscmd put %s  %s' %(sfile+'.gz', ossfile)
            remote_source.run_once(cmd)

            cmd = 'osscmd get %s %s' %(ossfile, sfile+'.gz')
            remote_target.run_once(cmd)
            cmd = 'gunzip -f %s' % sfile
            remote_target.run_once(cmd)

        remote_source.close()
        remote_target.close()

    if host_missing and not DEBUG:
        remote_target= bporemote.Remote()
        remote_target.add_host(config.target)
        for h in host_missing:
            f = "%s.%s.log" %(config.prefix, h)
            sfile = os.path.join(config.dirname, h[:8], f)
            ossfile = os.path.join(config.oss_pre, h[:4], h[4:6], h[6:8], f+'.gz')
            cmd = 'osscmd get %s %s' %(ossfile, sfile+'.gz')
            remote_target.run_once(cmd)
            cmd = 'gunzip -f %s' % sfile
            remote_target.run_once(cmd)
        remote_target.close()

    if host_missing and not DEBUG:
        reason = '@target host: missing %s' %(','.join(host_missing))
        bpomail.sendMail(config.smtp_server, config.smtp_user, config.smtp_pass, config.from_email, config.to_email, config.subject, reason)
    if oss_missing and not DEBUG:
        reason = '@source host: missing %s' %(','.join(host_missing))
        bpomail.sendMail(config.smtp_server, config.smtp_user, config.smtp_pass, config.from_email, config.to_email, config.subject, reason)