fix: some exception
This commit is contained in:
parent
65beca5067
commit
77b51204af
60
main.py
60
main.py
@ -11,7 +11,7 @@ DEBUG_MODE = False
|
|||||||
URL = 'https://www.cmlab.csie.ntu.edu.tw/status-gpu/'
|
URL = 'https://www.cmlab.csie.ntu.edu.tw/status-gpu/'
|
||||||
GPU_LIMIT = 2
|
GPU_LIMIT = 2
|
||||||
GOOGLE_CODE = os.environ['GOOGLE_CODE']
|
GOOGLE_CODE = os.environ['GOOGLE_CODE']
|
||||||
MAIL_CD_HOUR = 6
|
MAIL_CD_HOUR = 12
|
||||||
MAIL_MESSAGE = '''
|
MAIL_MESSAGE = '''
|
||||||
Hi, {}<br>
|
Hi, {}<br>
|
||||||
<br>
|
<br>
|
||||||
@ -76,38 +76,40 @@ def get_server_gpu_status() -> list:
|
|||||||
for box in boxes[:-1]:
|
for box in boxes[:-1]:
|
||||||
soup = BeautifulSoup(box, 'html.parser')
|
soup = BeautifulSoup(box, 'html.parser')
|
||||||
# get server name
|
# get server name
|
||||||
server_name = soup.find('span', class_='f7').text.replace(' ', '')
|
server = soup.find('span', class_='f7')
|
||||||
gpu_names = []
|
if server:
|
||||||
|
server_name = server.text.replace(' ', '')
|
||||||
|
gpu_names = []
|
||||||
|
|
||||||
users = []
|
users = []
|
||||||
gpus = box.split('\n')
|
gpus = box.split('\n')
|
||||||
for i in gpus[:]:
|
for i in gpus[:]:
|
||||||
if 'f6' in i: # if this line is for a single GPU informations
|
if 'f6' in i: # if this line is for a single GPU informations
|
||||||
soup = BeautifulSoup(i, 'html.parser')
|
soup = BeautifulSoup(i, 'html.parser')
|
||||||
|
|
||||||
# get all users who is using this server's GPU resources.
|
# get all users who is using this server's GPU resources.
|
||||||
user_objs = soup.findAll('span', class_='f0')
|
user_objs = soup.findAll('span', class_='f0')
|
||||||
user_in_this_gpu = set()
|
user_in_this_gpu = set()
|
||||||
|
|
||||||
# get users on this GPU
|
# get users on this GPU
|
||||||
for user_obj in user_objs:
|
for user_obj in user_objs:
|
||||||
if user_obj != None:
|
if user_obj != None:
|
||||||
username = user_obj.text
|
username = user_obj.text
|
||||||
if username != 'gdm':
|
if username != 'gdm' and username != 'root':
|
||||||
user_in_this_gpu.add(username)
|
user_in_this_gpu.add(username)
|
||||||
|
|
||||||
# get gpu names
|
# get gpu names
|
||||||
gpu_name = soup.find('span', class_='f4').text.replace(' ', '')
|
gpu_name = soup.find('span', class_='f4').text.replace(' ', '')
|
||||||
|
|
||||||
# log gpu name & users on this GPU
|
# log gpu name & users on this GPU
|
||||||
gpu_names.append(gpu_name)
|
gpu_names.append(gpu_name)
|
||||||
users.append(list(user_in_this_gpu))
|
users.append(list(user_in_this_gpu))
|
||||||
|
|
||||||
servers.append({
|
servers.append({
|
||||||
'name': server_name,
|
'name': server_name,
|
||||||
'users': users,
|
'users': users,
|
||||||
'gpus': gpu_names
|
'gpus': gpu_names
|
||||||
})
|
})
|
||||||
return servers
|
return servers
|
||||||
|
|
||||||
def filter(server_status: list, limit: int = 2) -> list:
|
def filter(server_status: list, limit: int = 2) -> list:
|
||||||
@ -197,7 +199,7 @@ def mail_notify(violators: list) -> None:
|
|||||||
msg['Subject'] = f'[網管通知] 提醒您已經超過 CMLab GPU 使用限制!({username})'
|
msg['Subject'] = f'[網管通知] 提醒您已經超過 CMLab GPU 使用限制!({username})'
|
||||||
msg['From'] = 'unix_manager@cmlab.csie.ntu.edu.tw'
|
msg['From'] = 'unix_manager@cmlab.csie.ntu.edu.tw'
|
||||||
msg['To'] = f'{username}@cmlab.csie.ntu.edu.tw' if not DEBUG_MODE else 'snsd0805@cmlab.csie.ntu.edu.tw'
|
msg['To'] = f'{username}@cmlab.csie.ntu.edu.tw' if not DEBUG_MODE else 'snsd0805@cmlab.csie.ntu.edu.tw'
|
||||||
msg['Cc'] = 'unix_manager@cmlab.csie.ntu.edu.tw' if not DEBUG_MODE else 'snsd0805@cmlab.csie.ntu.edu.tw'
|
# msg['Cc'] = 'unix_manager@cmlab.csie.ntu.edu.tw' if not DEBUG_MODE else 'snsd0805@cmlab.csie.ntu.edu.tw'
|
||||||
|
|
||||||
smtp = smtplib.SMTP('smtp.gmail.com', 587)
|
smtp = smtplib.SMTP('smtp.gmail.com', 587)
|
||||||
smtp.ehlo()
|
smtp.ehlo()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user