[GH-ISSUE #298] Feature Request: API to manage Projects #224

Closed
opened 2026-02-25 23:41:40 +03:00 by kerem · 1 comment
Owner

Originally created by @gganeshan on GitHub (Nov 4, 2019).
Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/298

@cuu508 finally I was able to self-host this amazing tool and integrate it with my on-prem LDAP as documented in #198 and #232 .

I am running the app inside a docker container and I wanted an idempotent way to create/update/list Projects via the API. This will avoid creating Projects manually, and promote automation.

From the documentation, I can see that the APIs can only be used to manage checks.

Originally created by @gganeshan on GitHub (Nov 4, 2019). Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/298 @cuu508 finally I was able to self-host this amazing tool and integrate it with my on-prem LDAP as documented in #198 and #232 . I am running the app inside a docker container and I wanted an idempotent way to create/update/list Projects via the API. This will avoid creating Projects manually, and promote automation. From the documentation, I can see that the APIs can only be used to manage checks.
kerem closed this issue 2026-02-25 23:41:40 +03:00
Author
Owner

@gganeshan commented on GitHub (Nov 19, 2019):

Fyi - I was able to setup a yaml based auto-provision process at app startup using the following setup.

provision.yaml

---
# project name:
#   - members:
#     - List of DL or email address or All (gives acces to all users)
#     - if list provided no users get access
#   - badge_key: if no value provided, project name is used as badge key
#   - api_key: if no value provided, project name is used as api_key
ProjectA:
  - badge_key: "KeyA"
  - api_key: "KeyB"
  - members:
      - "*"

hc/accounts/management/commands/createproject.py

import os
import yaml
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from hc.accounts.models import Project
from hc.accounts.memberassignment import get_project_attr_from_file

class Command(BaseCommand):
    help = "Automated Project Creation"

    def handle(self, *args, **options):
        superuser_name = os.getenv("SUPERUSER_NAME", "superuser")
        superuser = User.objects.get(username=superuser_name)

        config_file = "provision.yaml"
        for project, project_attrs in yaml.load(open(config_file), Loader=yaml.FullLoader).items():
            project_name = project
            project_api_key = get_project_attr_from_file(project_attrs, "api_key")
            project_badge_key = get_project_attr_from_file(project_attrs, "badge_key")
            # default attributes to project name if not supplied
            if not project_badge_key:
                project_badge_key = project_name
            if not project_api_key:
                project_api_key = project_name

            self.create_project(superuser, project_name, project_api_key, project_badge_key)

    def create_project(self, superuser, project_name, project_api_key, project_badge_key):
        if not Project.objects.filter(name=project_name):
            self.project = Project(owner=superuser, api_key=project_api_key)
            self.project.name = project_name
            self.project.badge_key = project_badge_key
            self.project.save()

I auto-create superuser and call the createproject.py via uwsgi as a pre-app hook.

[uwsgi]
http-socket = :8000
enable-threads
plugin = python3
module = hc.wsgi:application
static-map = /static=static-collected
static-gzip-dir = static-collected/CACHE
hook-pre-app = exec:/usr/bin/python3 ./manage.py migrate
hook-pre-app = exec:/usr/bin/python3 ./manage.py createsuperuser --noinput --username ${SUPERUSER_NAME} --email ${SUPERUSER_EMAIL}
hook-pre-app = exec:/usr/bin/python3 ./manage.py createproject

SUPERUSER_NAME and SUPERUSER_EMAIL are supplied as environment variables.

<!-- gh-comment-id:555531787 --> @gganeshan commented on GitHub (Nov 19, 2019): Fyi - I was able to setup a yaml based auto-provision process at app startup using the following setup. `provision.yaml` ```yaml --- # project name: # - members: # - List of DL or email address or All (gives acces to all users) # - if list provided no users get access # - badge_key: if no value provided, project name is used as badge key # - api_key: if no value provided, project name is used as api_key ProjectA: - badge_key: "KeyA" - api_key: "KeyB" - members: - "*" ``` `hc/accounts/management/commands/createproject.py` ```python import os import yaml from django.core.management.base import BaseCommand from django.contrib.auth.models import User from hc.accounts.models import Project from hc.accounts.memberassignment import get_project_attr_from_file class Command(BaseCommand): help = "Automated Project Creation" def handle(self, *args, **options): superuser_name = os.getenv("SUPERUSER_NAME", "superuser") superuser = User.objects.get(username=superuser_name) config_file = "provision.yaml" for project, project_attrs in yaml.load(open(config_file), Loader=yaml.FullLoader).items(): project_name = project project_api_key = get_project_attr_from_file(project_attrs, "api_key") project_badge_key = get_project_attr_from_file(project_attrs, "badge_key") # default attributes to project name if not supplied if not project_badge_key: project_badge_key = project_name if not project_api_key: project_api_key = project_name self.create_project(superuser, project_name, project_api_key, project_badge_key) def create_project(self, superuser, project_name, project_api_key, project_badge_key): if not Project.objects.filter(name=project_name): self.project = Project(owner=superuser, api_key=project_api_key) self.project.name = project_name self.project.badge_key = project_badge_key self.project.save() ``` I auto-create superuser and call the `createproject.py` via uwsgi as a pre-app hook. ``` [uwsgi] http-socket = :8000 enable-threads plugin = python3 module = hc.wsgi:application static-map = /static=static-collected static-gzip-dir = static-collected/CACHE hook-pre-app = exec:/usr/bin/python3 ./manage.py migrate hook-pre-app = exec:/usr/bin/python3 ./manage.py createsuperuser --noinput --username ${SUPERUSER_NAME} --email ${SUPERUSER_EMAIL} hook-pre-app = exec:/usr/bin/python3 ./manage.py createproject ``` `SUPERUSER_NAME` and `SUPERUSER_EMAIL` are supplied as environment variables.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/healthchecks#224
No description provided.