Fixed some typos.

Fixed formatting (force of habit...).
This commit is contained in:
Ivaylo Novakov 2020-11-20 21:45:19 +01:00
parent 05cd1bfb32
commit 801597ccde
No known key found for this signature in database
GPG Key ID: 06B9354AB08BE9C6
1 changed files with 29 additions and 14 deletions

View File

@ -1,7 +1,16 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import asyncio, json, os, re, sys, traceback, discord, requests, time import asyncio
import json
import os
import re
import sys
import time
import traceback
from datetime import datetime, timedelta from datetime import datetime, timedelta
import discord
import requests
from bot_utils import setup, send_msg from bot_utils import setup, send_msg
""" """
@ -124,6 +133,7 @@ async def check_disk():
async def check_health(): async def check_health():
print("\nChecking portal health status...") print("\nChecking portal health status...")
try: try:
res_check = requests.get("http://localhost/health-check", verify=False) res_check = requests.get("http://localhost/health-check", verify=False)
json_check = res_check.json() json_check = res_check.json()
@ -224,15 +234,18 @@ async def check_health():
def contains_string(string_to_check, string_to_find): def contains_string(string_to_check, string_to_find):
return string_to_find in string_to_check return string_to_find in string_to_check
# check_alerts checks the alerts returned from siad's daemon/alerts API # check_alerts checks the alerts returned from siad's daemon/alerts API
async def check_alerts(): async def check_alerts():
print("\nChecking portal siad alerts...") print("\nChecking portal siad alerts...")
CONTAINER_NAME = "sia"
if len(sys.argv) > 2:
CONTAINER_NAME = sys.argv[2]
# Execute siac alerts and read the response # Execute siac alerts and read the response
# TODO: is the container name always `sia` for production servers? Is it cmd_string = "docker exec {} siac alerts".format(CONTAINER_NAME)
# only changed to the server name when it it is moved to Maintenance? Will
# this just never check the alerts on the maintenance servers?
cmd_string = "docker exec sia siac alert"
siac_alert_output = os.popen(cmd_string).read().strip() siac_alert_output = os.popen(cmd_string).read().strip()
# Initialize variables # Initialize variables
@ -252,18 +265,18 @@ async def check_alerts():
# Split the output by line and check for type of alert and siafile alerts # Split the output by line and check for type of alert and siafile alerts
for line in siac_alert_output.split("\n"): for line in siac_alert_output.split("\n"):
# Check for the type of alert # Check for the type of alert
if contains_string(lin, critical): if contains_string(line, critical):
num_critical_alerts++ num_critical_alerts += 1
if contains_string(lin, error): if contains_string(line, error):
num_error_alerts++ num_error_alerts += 1
if contains_string(lin, warning): if contains_string(line, warning):
num_warning_alerts++ num_warning_alerts += 1
# Check for siafile alerts in alerts. This is so that the alert # Check for siafile alerts in alerts. This is so that the alert
# severity can change and this doesn't need to be updated # severity can change and this doesn't need to be updated
if contains_string(line, siafile_alert_message): if contains_string(line, siafile_alert_message):
num_siafile_alerts++ num_siafile_alerts += 1
if contains_string(line, health_of) if contains_string(line, health_of):
siafile_alerts.append(line) siafile_alerts.append(line)
################################################################################ ################################################################################
@ -290,6 +303,7 @@ async def check_alerts():
client, message, file=siac_alert_output, force_notify=force_notify client, message, file=siac_alert_output, force_notify=force_notify
) )
# check_portal_size checks the number of files that the portal is managing to # check_portal_size checks the number of files that the portal is managing to
# determine if it is time to rotate it out # determine if it is time to rotate it out
async def check_portal_size(): async def check_portal_size():
@ -332,4 +346,5 @@ async def check_portal_size():
client, message, force_notify=force_notify client, message, force_notify=force_notify
) )
client.run(bot_token) client.run(bot_token)