Add pydantic models for config and check info
This commit is contained in:
parent
cc2c0e492b
commit
d9b04b9468
2 changed files with 64 additions and 1 deletions
3
setup.py
3
setup.py
|
@ -1,5 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Setup file for the web stats collector.
|
Setup file for the website checker.
|
||||||
"""
|
"""
|
||||||
from setuptools import setup # type: ignore
|
from setuptools import setup # type: ignore
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ setup(
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'aiokafka==0.6.0',
|
'aiokafka==0.6.0',
|
||||||
'asyncpg==0.21.0',
|
'asyncpg==0.21.0',
|
||||||
|
'pydantic==1.6.1',
|
||||||
'PyYAML==5.3.1',
|
'PyYAML==5.3.1',
|
||||||
'requests==2.24.0',
|
'requests==2.24.0',
|
||||||
],
|
],
|
||||||
|
|
62
src/webstat/models.py
Normal file
62
src/webstat/models.py
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
|
"""
|
||||||
|
Schemas that are used in all modules. This module contains classes for:
|
||||||
|
|
||||||
|
- Configuring the ``chweb.collector.Collector``.
|
||||||
|
- Configuring the ``chweb.consumer.Consumer``.
|
||||||
|
- The schema for the stats being sent in the Kafka topic.
|
||||||
|
"""
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import List, Optional
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class Check(BaseModel):
|
||||||
|
"""
|
||||||
|
Information for a website check request.
|
||||||
|
"""
|
||||||
|
domain: str = ""
|
||||||
|
regex: Optional[str] = None
|
||||||
|
regex_matches: Optional[bool] = None
|
||||||
|
request_time: datetime = datetime.now()
|
||||||
|
response_time: int = 0
|
||||||
|
status: int = 0
|
||||||
|
url: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
class KafkaConfig(BaseModel):
|
||||||
|
"""
|
||||||
|
Kafka broker configuration.
|
||||||
|
"""
|
||||||
|
servers: List[str] = ["localhost:9992"]
|
||||||
|
topic: str = "sample"
|
||||||
|
|
||||||
|
|
||||||
|
class PostgresConfig(BaseModel):
|
||||||
|
"""
|
||||||
|
PostgreSQL server configuration.
|
||||||
|
"""
|
||||||
|
dbhost: str = "localhost"
|
||||||
|
dbport: int = 5432
|
||||||
|
dbname: str = "chweb"
|
||||||
|
dbuser: str = "vladan"
|
||||||
|
dbpass: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
class SiteConfig(BaseModel):
|
||||||
|
"""
|
||||||
|
Single website configuration.
|
||||||
|
"""
|
||||||
|
url: str = "https://example.com"
|
||||||
|
regex: str = "domain"
|
||||||
|
check_interval: int = 5
|
||||||
|
|
||||||
|
|
||||||
|
class Config(BaseModel):
|
||||||
|
"""
|
||||||
|
Main application configuration. Same for the checker and the kafka
|
||||||
|
consumer / postgres writer for simplicity while deploying.
|
||||||
|
"""
|
||||||
|
kafka: KafkaConfig = KafkaConfig()
|
||||||
|
postgres: PostgresConfig = PostgresConfig()
|
||||||
|
sites: List[SiteConfig] = []
|
Loading…
Reference in a new issue