Add current dir keyword

This commit is contained in:
askiiart 2024-02-20 12:04:52 -06:00
parent 219bcf8a12
commit caba45a27f
Signed by untrusted user who does not match committer: askiiart
GPG key ID: BC3800E55FB54D67
4 changed files with 16 additions and 3 deletions

View file

@ -48,7 +48,8 @@ Docs are in the `./docs/` folder, but here's a quick overview on how to use this
- Add maintenance windows (optionally recurring)
- Add groups
- Add ability for checkers to have preferred alerts and logging extensions - will print a warning if the preferred extension(s) are not used
- Add "keywords" to be replaced in the config (for current directory, service name, maybe some others)
- Add "keywords" to be replaced in the config (for ~~current directory~~, service name, maybe some others)
- Current directory done - `%dir%`
---

View file

@ -62,6 +62,12 @@ Optional arguments:
- `name`: A human-friendly name for the service; currently unused.
#### Keywords
Keywords get replaced with their value.
- `%dir%`: The directory Updog is located in.
---
This example uses the template extensions, [askiiart/updog-checker_template](https://git.askiiart.net/askiiart/updog-checker_template), [askiiart/updog-logging_template](https://git.askiiart.net/askiiart/updog-logging_template), and [askiiart/updog-alerts_template](https://git.askiiart.net/askiiart/updog-alerts_template), so the arguments for them are mostly irrelevant. For each extension, check its docs for what arguments to use.

View file

@ -10,13 +10,13 @@
"checker-args": {
"url": "https://askiiart.net"
},
"rate": 1,
"rate": 5,
"alerts-args": {
"url": "https://example.com/webhook-url-or-whatever-goes-here",
"lol": "irrelevant, AlertsTemplate ignores these options lol"
},
"logging-args": {
"file": "/home/askiiart/Documents/updog/logs/site-log"
"file": "%dir%/logs/site-log"
}
}
}

View file

@ -71,8 +71,14 @@ elif 'services-example.json' in os.listdir(path):
config_filename = f'{path}/services-example.json'
with open(config_filename, 'rt') as config_file:
config_text = ''.join(config_file.readlines())
# Replace static keywords in config
keywords = {'%dir%': path}
for key in keywords:
config_text = config_text.replace(key, keywords[key])
config = json.loads(''.join(config_file.readlines()))
instances = create_instances(config, checkers, alerts, logging)
timers = {}