[GH-ISSUE #266] Request: ability to copy all healthchecks from one project to another #198

Closed
opened 2026-02-25 23:41:33 +03:00 by kerem · 6 comments
Owner

Originally created by @caleb15 on GitHub (Jul 11, 2019).
Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/266

At https://www.15five.com we currently have two VPC's, each with their own project but all the healthchecks are the same. When I created the second project I manually copied over all ~60 healthchecks to the other project, which was a pain. In the future we will be expanding to more VPC's so it would be awesome if we could automatically copy all the healthchecks from one project to another.

Originally created by @caleb15 on GitHub (Jul 11, 2019). Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/266 At https://www.15five.com we currently have two VPC's, each with their own project but all the healthchecks are the same. When I created the second project I manually copied over all ~60 healthchecks to the other project, which was a pain. In the future we will be expanding to more VPC's so it would be awesome if we could automatically copy all the healthchecks from one project to another.
kerem closed this issue 2026-02-25 23:41:33 +03:00
Author
Owner

@cuu508 commented on GitHub (Jul 13, 2019):

I think this would be reasonably easy to do using API calls. Here's a quick example, with no error handling, using Python and the requests library:

import requests

API_URL = "https://healthchecks.io/api/v1/checks/"
SOURCE_PROJECT_READONLY_KEY = "..."
TARGET_PROJECT_KEY = "..."

r = requests.get(API_URL, headers={"X-Api-Key": SOURCE_PROJECT_READONLY_KEY})
for check in r.json()["checks"]:
    print("Cloning %s" % check["name"])
    requests.post(API_URL, json=check, headers={"X-Api-Key": TARGET_PROJECT_KEY})

<!-- gh-comment-id:511111866 --> @cuu508 commented on GitHub (Jul 13, 2019): I think this would be reasonably easy to do using API calls. Here's a quick example, with no error handling, using Python and the requests library: ``` import requests API_URL = "https://healthchecks.io/api/v1/checks/" SOURCE_PROJECT_READONLY_KEY = "..." TARGET_PROJECT_KEY = "..." r = requests.get(API_URL, headers={"X-Api-Key": SOURCE_PROJECT_READONLY_KEY}) for check in r.json()["checks"]: print("Cloning %s" % check["name"]) requests.post(API_URL, json=check, headers={"X-Api-Key": TARGET_PROJECT_KEY}) ```
Author
Owner

@ScottBeeson commented on GitHub (Sep 17, 2019):

The other issue was reopened. I have quoted the post below in that issue.

My request (#288) was a bit different than this one. My use case is within the SAME project and applied only to a SINGLE check. But I'm fine with it being here.

I would like to be able to clone or duplicate any given check. I suspect it's extremely common that users have many checks on the same schedule or with the same tags. Duplicating these options over and over is tedious and prone to error. A copy, clone or duplicate feature for individual checks (in my case) would be immensely useful. A separate "Copy Project" function might satisfy OPs need.

The API call above does not fit my use case.

<!-- gh-comment-id:532255762 --> @ScottBeeson commented on GitHub (Sep 17, 2019): The other issue was reopened. I have quoted the post below in that issue. ~~My request (#288) was a bit different than this one. My use case is within the SAME project and applied only to a SINGLE check. But I'm fine with it being here.~~ ~~I would like to be able to clone or duplicate any given check. I suspect it's extremely common that users have many checks on the same schedule or with the same tags. Duplicating these options over and over is tedious and prone to error. A copy, clone or duplicate feature **for individual checks** (in my case) would be immensely useful. A separate "Copy Project" function might satisfy OPs need.~~ ~~The API call above does not fit my use case.~~
Author
Owner

@caleb15 commented on GitHub (Mar 6, 2020):

@cuu508 thanks, that works great :)

<!-- gh-comment-id:596013627 --> @caleb15 commented on GitHub (Mar 6, 2020): @cuu508 thanks, that works great :)
Author
Owner

@caleb15 commented on GitHub (Mar 9, 2020):

I improved the script so it won't add duplicate healthchecks:

import requests

API_URL = "https://healthchecks.io/api/v1/checks/"
SOURCE_PROJECT_READONLY_KEY = "..."
TARGET_PROJECT_KEY = "..."

source_checks = requests.get(API_URL, headers={"X-Api-Key": SOURCE_PROJECT_READONLY_KEY})

target_checks = requests.get(API_URL, headers={"X-Api-Key": TARGET_PROJECT_KEY})
target_check_names = [check["name"] for check in target_checks.json()["checks"]]

for check in source_checks.json()["checks"]:
    if check["name"] in target_check_names:
        print("%s check already present in target" % check["name"])
    else:
        print("Cloning %s" % check["name"])
        requests.post(API_URL, json=check, headers={"X-Api-Key": TARGET_PROJECT_KEY})

It's possible to further improve the script to update the healthcheck if already present using check["update_url"]

I also made a quick script for renaming the healthchecks in bulk:

# you can use below to rename checks en masse
# TARGET_PROJECT_KEY = "..."
# target_checks = requests.get(API_URL, headers={"X-Api-Key": TARGET_PROJECT_KEY})
# target_checks = target_checks.json()["checks"]
# for check in target_checks:
#     check["name"] = check["name"].replace("(cloud5) ", "")
#     print("Updating %s" % check["name"])
#     requests.post(check["update_url"], json=check, headers={"X-Api-Key": TARGET_PROJECT_KEY})
<!-- gh-comment-id:596784824 --> @caleb15 commented on GitHub (Mar 9, 2020): I improved the script so it won't add duplicate healthchecks: ```python import requests API_URL = "https://healthchecks.io/api/v1/checks/" SOURCE_PROJECT_READONLY_KEY = "..." TARGET_PROJECT_KEY = "..." source_checks = requests.get(API_URL, headers={"X-Api-Key": SOURCE_PROJECT_READONLY_KEY}) target_checks = requests.get(API_URL, headers={"X-Api-Key": TARGET_PROJECT_KEY}) target_check_names = [check["name"] for check in target_checks.json()["checks"]] for check in source_checks.json()["checks"]: if check["name"] in target_check_names: print("%s check already present in target" % check["name"]) else: print("Cloning %s" % check["name"]) requests.post(API_URL, json=check, headers={"X-Api-Key": TARGET_PROJECT_KEY}) ``` It's possible to further improve the script to update the healthcheck if already present using `check["update_url"]` I also made a quick script for renaming the healthchecks in bulk: ```python # you can use below to rename checks en masse # TARGET_PROJECT_KEY = "..." # target_checks = requests.get(API_URL, headers={"X-Api-Key": TARGET_PROJECT_KEY}) # target_checks = target_checks.json()["checks"] # for check in target_checks: # check["name"] = check["name"].replace("(cloud5) ", "") # print("Updating %s" % check["name"]) # requests.post(check["update_url"], json=check, headers={"X-Api-Key": TARGET_PROJECT_KEY}) ```
Author
Owner

@caleb15 commented on GitHub (Mar 15, 2020):

Another possibility is to use https://github.com/kristofferahl/terraform-provider-healthchecksio to describe the healthchecks as code. One could write a terraform module with the desired healthchecks, and then call that for each environment, passing in a different API key each time.

<!-- gh-comment-id:599248174 --> @caleb15 commented on GitHub (Mar 15, 2020): Another possibility is to use https://github.com/kristofferahl/terraform-provider-healthchecksio to describe the healthchecks as code. One could write a terraform module with the desired healthchecks, and then call that for each environment, passing in a different API key each time.
Author
Owner

@caleb15 commented on GitHub (Aug 26, 2020):

No longer needed now that we are using https://gist.github.com/caleb15/1a817ef5e58e8a8caf65190cff33806e - closing

<!-- gh-comment-id:680400963 --> @caleb15 commented on GitHub (Aug 26, 2020): No longer needed now that we are using https://gist.github.com/caleb15/1a817ef5e58e8a8caf65190cff33806e - closing
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#198
No description provided.