forked from DGNum/stateless-uptime-kuma
feat: add host, password and username handling
This commit is contained in:
parent
ae50084fcb
commit
456f923905
2 changed files with 32 additions and 5 deletions
|
@ -14,6 +14,10 @@ in
|
||||||
json = lib.mkOption { type = lib.types.package; };
|
json = lib.mkOption { type = lib.types.package; };
|
||||||
script = lib.mkOption { type = lib.types.package; };
|
script = lib.mkOption { type = lib.types.package; };
|
||||||
};
|
};
|
||||||
|
host = lib.mkOption {
|
||||||
|
default = null;
|
||||||
|
type = with lib.types; nullOr str;
|
||||||
|
};
|
||||||
extraFlags = lib.mkOption {
|
extraFlags = lib.mkOption {
|
||||||
default = [ ];
|
default = [ ];
|
||||||
example = [ "--scrape-http-keywords" ];
|
example = [ "--scrape-http-keywords" ];
|
||||||
|
@ -40,13 +44,15 @@ in
|
||||||
};
|
};
|
||||||
config.statelessUptimeKuma = {
|
config.statelessUptimeKuma = {
|
||||||
lib = import ../lib { inherit lib; };
|
lib = import ../lib { inherit lib; };
|
||||||
|
extraFlags = lib.optional (cfg.host != null) "--host ${cfg.host}";
|
||||||
build = {
|
build = {
|
||||||
json = probesFormat.generate "probes.json" cfg.probesConfig;
|
json = probesFormat.generate "probes.json" cfg.probesConfig;
|
||||||
script = pkgs.writeShellApplication {
|
script = pkgs.writeShellApplication {
|
||||||
name = "deploy-uptime-kuma-probes";
|
name = "deploy-uptime-kuma-probes";
|
||||||
runtimeInputs = [ pkgs.statelessUptimeKuma ];
|
runtimeInputs = [ pkgs.statelessUptimeKuma ];
|
||||||
text = ''
|
text = ''
|
||||||
stateless-uptime-kuma apply-json -f ${cfg.build.json} ${builtins.concatStringsSep " " cfg.extraFlags}
|
args=("$@")
|
||||||
|
stateless-uptime-kuma apply-json -f ${cfg.build.json} ${builtins.concatStringsSep " " cfg.extraFlags} "''${args[@]}"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,14 +47,35 @@ def cli():
|
||||||
help="Don't automatically create tags if not in tags section of input",
|
help="Don't automatically create tags if not in tags section of input",
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
def apply_json(file, scrape_http_keywords, no_autocreate_tags, keywords_fallback):
|
@click.option(
|
||||||
|
"--username",
|
||||||
|
prompt=True,
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--host",
|
||||||
|
prompt=True,
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--password",
|
||||||
|
prompt=True,
|
||||||
|
hide_input=True,
|
||||||
|
)
|
||||||
|
def apply_json(
|
||||||
|
file,
|
||||||
|
scrape_http_keywords,
|
||||||
|
no_autocreate_tags,
|
||||||
|
keywords_fallback,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
host,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Apply json probes
|
Apply json probes
|
||||||
"""
|
"""
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Flags value:\n - scrape_http_keywords: {scrape_http_keywords}\n - no_autocreate_tags: {no_autocreate_tags}\n - keywords_fallback: {keywords_fallback}"
|
f"Flags value:\n - scrape_http_keywords: {scrape_http_keywords}\n - no_autocreate_tags: {no_autocreate_tags}\n - keywords_fallback: {keywords_fallback}"
|
||||||
)
|
)
|
||||||
with UptimeKumaApi("http://localhost:3001") as api:
|
with UptimeKumaApi(host) as api:
|
||||||
logging.debug("Reading json")
|
logging.debug("Reading json")
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
logging.debug("Parsing json")
|
logging.debug("Parsing json")
|
||||||
|
@ -62,9 +83,9 @@ def apply_json(file, scrape_http_keywords, no_autocreate_tags, keywords_fallback
|
||||||
if scrape_http_keywords:
|
if scrape_http_keywords:
|
||||||
hydrate_http_probes(tree)
|
hydrate_http_probes(tree)
|
||||||
logging.debug("Sync probes")
|
logging.debug("Sync probes")
|
||||||
api.login("admin", "123456789a")
|
api.login(username, password)
|
||||||
Manager(api, tree).process()
|
Manager(api, tree).process()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
cli(auto_envvar_prefix="STATELESS_UPTIME_KUMA")
|
||||||
|
|
Loading…
Reference in a new issue