stateless-uptime-kuma/stateless_uptime_kuma/cli.py

56 lines
1.1 KiB
Python
Raw Normal View History

2024-04-16 22:48:52 +02:00
import json
import logging
import sys
import click
import click_log
from uptime_kuma_api import UptimeKumaApi
from .hydratation import hydrate_http_probes
from .tree_gen import from_dict
from .uptime_kuma import Manager
logger = logging.getLogger(__name__)
click_log.basic_config()
@click.group()
def cli():
pass
@cli.command()
@click_log.simple_verbosity_option()
@click.option(
"--file",
"-f",
help="File to import probes data from",
type=click.File("r"),
default=sys.stdin,
)
@click.option(
"--scrape-http-keywords",
"-s",
is_flag=True,
help="Scrape keywords for http probe",
default=False,
)
def apply_json(file, scrape_http_keywords):
"""
Apply json probes
"""
with UptimeKumaApi("http://localhost:3001") as api:
api.login("admin", "123456789a")
logging.debug("Reading json")
data = json.load(file)
logging.debug("Parsing json")
tree = from_dict(api, data)
if scrape_http_keywords:
hydrate_http_probes(tree)
logging.debug("Sync probes")
Manager(api, tree).process()
if __name__ == "__main__":
cli()