Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added uptime kuma status page #160

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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