import base64 import datetime import hmac import json import os import time from hashlib import sha256 import yaml import pymysql import requests def process_staging_environments(): users = ['dev', 'staging', 'louis2', 'yinliang3', 'gweber', 'slowquery', 'xuyifan02', 'jyzdev10', 'rajeshwer', 'hanlins'] usersDB = { "dev": "dev_central", "staging": "staging_central", "louis2": "louis2_central", "topsql": "topsql_central", } host = 'tidb.e23bdccc.cb17aaf2.us-west-2.prod.aws.tidbcloud.com' alertTidbs = [] for user in users: id = '' created_at = datetime.datetime.now() name = '' tenant_id = '' status = '' tenant_name = 'unknown' tenant_email = 'unknown' creator = 'unknown' try: db = pymysql.connect(host=host, port=4000, user='root', password=os.getenv('passwd'), db=user + "_central", charset='utf8') cursor = db.cursor() cursor.execute("select * from clusters where status='normal' and cluster_profile_id not in (select id from cluster_profiles where name like '%dev');") results = cursor.fetchall() for row in results: id = row[0] created_at = row[1] name = row[4] tenant_id = row[5] status = row[12] creator_id = row[6] cursor.execute("select * from tenants where id = {}".format(tenant_id)) results = cursor.fetchall() if len(results) == 0: continue tenant_name = results[0][3] tenant_email = results[0][5] creator = "" cursor.execute("select * from users where id = {}".format(creator_id)) results = cursor.fetchall() if len(results) == 0: continue creator = "{} {}".format(results[0][6], results[0][5]) alertTidbs.append({ 'tenantName': tenant_name, 'tenantEmail': tenant_email, 'id': str(id), 'created_at': str(created_at), 'name': name, 'status': status, 'tenant_id': str(tenant_id), 'creator': creator, "env": user, }) except Exception as e: print("longlivecluster meets: ", user, e) return alertTidbs def find_more_than_eight_hours_clusters(): stagingClusters = process_staging_environments() print("metadb clusters", stagingClusters ) return stagingClusters