176 lines
5.8 KiB
Python
176 lines
5.8 KiB
Python
"""
|
|
|
|
AUTHOR:
|
|
|
|
Khushal P Soonderji
|
|
|
|
DATE:
|
|
|
|
Wednesday, 25th Dec., 2024.
|
|
|
|
OBJECTIVE:
|
|
|
|
To provide a structure to work with enlisting servers and maintaining their status.
|
|
|
|
REFERENCES:
|
|
|
|
N/A
|
|
|
|
DOWNLOADS:
|
|
|
|
N/A
|
|
|
|
"""
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** IMPORT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# To make sibling directories accessible for imports:
|
|
import sys
|
|
sys.path.append(".")
|
|
sys.path.append("..")
|
|
|
|
# For making data behaviour_models:
|
|
from pydantic import BaseModel, Field, field_validator, PastDatetime, model_validator, AwareDatetime, computed_field
|
|
from typing import Optional, Literal, Union
|
|
|
|
# My utils:
|
|
from utils_v2.string import json
|
|
from utils_v2.string import regex
|
|
from utils_v2.date_time import date_time
|
|
|
|
# To work with MongoDB:
|
|
from bson import ObjectId
|
|
|
|
# To work with date and time:
|
|
import datetime
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MACROS / ONE-TIME INIT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** VARIABLES ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** FUNCTIONS ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
class RegisterServerRequestData(BaseModel):
|
|
|
|
hostname: str = Field(
|
|
description = "the hostname to identify the server",
|
|
frozen = True
|
|
)
|
|
|
|
os: str = Field(
|
|
description = "the os the server is running",
|
|
frozen = True
|
|
)
|
|
|
|
cpu: str = Field(
|
|
description = "the cpu that the server has in it",
|
|
frozen = True
|
|
)
|
|
|
|
pid: str | int = Field(
|
|
description = "the process id that registered the details of this server",
|
|
frozen = True
|
|
)
|
|
|
|
ppid: str | int = Field(
|
|
description = "the parent process id that registered the details of this server",
|
|
frozen = True
|
|
)
|
|
|
|
ipAddr: str | None = Field(
|
|
description = "the ip address of the server",
|
|
frozen = True
|
|
)
|
|
|
|
portNo: int = Field(
|
|
description = "the port no. that this service is running on",
|
|
default = None,
|
|
frozen = True
|
|
)
|
|
|
|
project: str = Field(
|
|
description = "the name of the project that this server is running",
|
|
frozen = True
|
|
)
|
|
|
|
service: str = Field(
|
|
description = "the service in the said project that this server is running",
|
|
frozen = True
|
|
)
|
|
|
|
description: str = Field(
|
|
description = "a brief description about this service",
|
|
max_length = 350,
|
|
frozen = True
|
|
)
|
|
|
|
healthCheckUrl: str = Field(
|
|
description = "a get request will be sent to this url to see if the server is up",
|
|
frozen = True
|
|
)
|
|
|
|
healthCheckInterval: int = Field(
|
|
description = "the seconds after which to check for the service being up",
|
|
ge = 30,
|
|
frozen = True
|
|
)
|
|
|
|
healthAlertUrl: str = Field(
|
|
description = "a get request will be sent to this url when the server goes offline",
|
|
frozen = True
|
|
)
|
|
|
|
# ┏┓ ┏•
|
|
# ┃ ┏┓┏┓╋┓┏┓
|
|
# ┗┛┗┛┛┗┛┗┗┫
|
|
# ┛
|
|
|
|
class Config:
|
|
extra = "forbid"
|
|
|
|
# ┓┏ ┓• ┓ •
|
|
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
|
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
|
|
|
pass
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MAIN PROGRAM ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pass
|