Skip to content

Commit

Permalink
Merge pull request #160 from AutiCodes/add-status-page
Browse files Browse the repository at this point in the history
Added uptime kuma status page
  • Loading branch information
AeroBytesNL authored Dec 14, 2024
2 parents 1dbd260 + de72266 commit c13c8af
Showing 1 changed file with 62 additions and 2 deletions.
64 changes: 62 additions & 2 deletions cogs/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from disnake.ext import commands
import requests
from env import Status as StatusEnv
from uptime_kuma_api import UptimeKumaApi

class Status(commands.Cog):
def __init__(self, bot: commands.Bot):
Expand All @@ -24,10 +25,9 @@ async def alldaybot(self, inter):
embed = disnake.Embed(
title="AllDayBot",
description="uptime en resource informatie",
color=disnake.Colour.green(),
color=0xdf8cfe,
url="https://uptime.auticodes.nl"
)

embed.add_field(
name="Online",
value=online,
Expand Down Expand Up @@ -67,6 +67,66 @@ async def alldaybot(self, inter):
)
await inter.response.send_message(embed=embed)

@status.sub_command(description="Zie de infrastructuur status")
async def pagina(self, inter):
try:
embed = disnake.Embed(
title="Uptime pagina",
description="AllDayTechAndGaming",
color=0xdf8cfe,
url="https://uptime.auticodes.nl/status/main"
)
embed.add_field(
name="Website",
value=f"Uptime in de laatste 24 uur: `{round(Status.get_kuma_monitor_uptime_precentage(self, monitor_id=4, hours=24), 2)}`%.\n Huidige status: `{Status.get_kuma_monitor_current_status(monitor_id=4)}`.",
inline=False
)
embed.add_field(
name="AllDayBot",
value=f"Uptime in de laatste 24 uur: `{round(Status.get_kuma_monitor_uptime_precentage(self, monitor_id=11, hours=24), 2)}`%.\n Huidige status: `{Status.get_kuma_monitor_current_status(monitor_id=11)}`.",
inline=False
)

await inter.response.send_message(embed=embed)
except Exception as error:
await inter.response.send_message(f"Er ging iets mis! Fout: `{error}`\n<@632677231113666601> ga eens aan het werk joh!")

def get_kuma_monitor_current_status(monitor_id):
uptime_kuma = UptimeKumaApi(url=StatusEnv.KUMA_URL)
uptime_kuma.login(
StatusEnv.KUMA_USERNAME,
StatusEnv.KUMA_PASSWORD
)

monitor = uptime_kuma.get_monitor_beats(
monitor_id,
1
)

if monitor[-1]["status"] == 1:
return 'Online'

return 'Offline'

def get_kuma_monitor_uptime_precentage(self, monitor_id, hours):
uptime_kuma = UptimeKumaApi(url=StatusEnv.KUMA_URL)
uptime_kuma.login(
StatusEnv.KUMA_USERNAME,
StatusEnv.KUMA_PASSWORD
)

monitor = uptime_kuma.get_monitor_beats(
monitor_id,
hours
)

down_count = sum(1 for record in monitor if record["status"] != 1)

if len(monitor) > 0:
return float(100 - ((down_count / len(monitor)) * 100))

return float(0)

def bytes_to_mb(bytes):
return int(bytes) / (1024 * 1024)

Expand Down

0 comments on commit c13c8af

Please sign in to comment.