예제 #1
0
import os
import sys
import time

sys.path.insert(
    0, os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + "/../"))
from Monitor import Monitor  # noqa: E402, pylint: disable=C0413

M = Monitor()

dbs = [
    ('RC_edit', 600),
    ('RC_log_abuselog', 3600),
    ('rc_newusers_autocreate', 3600),
]

timestamp = int(time.time())

for db in dbs:
    M.db_execute(
        f"""SELECT `timestamp` FROM {db[0]} ORDER BY `timestamp` DESC LIMIT 1"""
    )
    row = M.db_fetchone()
    timediff = timestamp - row[0]
    print(db[0], timediff)
    if timediff > db[1]:
        msg = '{}已有{}秒未收到訊息'.format(db[0], timediff)
        M.sendmessage(msg, chat_id=M.admin_chat_id, nolog=True)
    level=args.loglevel,
    format=
    '%(asctime)s {: <15} [%(filename)20s:%(lineno)4s] %(levelname)7s %(message)s'
    .format(args.wiki))

M = Monitor()

logging.getLogger().addHandler(MonitorLogHandler(M, args.wiki))

os.environ['TZ'] = 'UTC'

M = Monitor()

M.db_execute("""SELECT `server_name` FROM `RC_wiki` WHERE `wiki` = %s""",
             (args.wiki))
domain = M.db_fetchone()
if domain is None:
    logging.error('Cannot get domain')
    exit()
else:
    domain = domain[0]
    logging.debug('domain is {}'.format(domain))

M.change_wiki_and_domain(args.wiki, domain)

api = 'https://{}/w/api.php'.format(domain)

if args.user:
    M.wp_user = args.user
    M.wp_pass = ''