Skip to content

self hosted #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Community Healthchecks.io Release Notes

.. contents:: Topics

### [Unreleased]

### Added

- Support for using a private instance of Healthchecks.io

v1.2.0
======
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ N/A
signal: start
```

### Using a Private Instance of Healthchecks.io

The `api_base_url` variable allows you to specify the custom API URL of your healthchecks.io instance, which can be used to connect to your private instance.

Example Ansible configuration using the `api_base_url` variable:

```yaml
- name: Create a check named "test"
community.healthchecksio.checks:
state: present
api_base_url: {{ api_base_url }}
api_key: "{{ api_key }}"
name: test
unique: ["name"]
```

### Installing the Collection from Ansible Galaxy

Before using this collection, you need to install it with the Ansible Galaxy command-line tool:
Expand Down
25 changes: 22 additions & 3 deletions plugins/module_utils/healthchecksio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import env_fallback
from urllib.parse import urljoin


class Response(object):
Expand Down Expand Up @@ -42,7 +43,12 @@ def status_code(self):
class HealthchecksioHelper:
def __init__(self, module):
self.module = module
self.baseurl = "https://healthchecks.io/api/v1"
api_base_url = module.params.get("api_base_url")
if api_base_url == self.healthchecksio_argument_spec().get("api_base_url").get("default"):
self.ping_api_base_url = "https://hc-ping.com"
else:
self.ping_api_base_url = urljoin(api_base_url, "/ping")
self.baseurl = urljoin(api_base_url, "/api/v1")
self.timeout = module.params.get("timeout", 30)
self.api_token = module.params.get("api_token")
self.headers = {"X-Api-Key": self.api_token}
Expand Down Expand Up @@ -90,7 +96,7 @@ def delete(self, path, data=None):
def head(self, path, data=None):
resp, info = fetch_url(
self.module,
"https://hc-ping.com/{0}".format(path),
"{0}/{1}".format(self.ping_api_base_url, path),
data=data,
headers=self.headers,
method="HEAD",
Expand All @@ -117,6 +123,19 @@ def healthchecksio_argument_spec():
required=True,
no_log=True,
),
api_base_url=dict(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to run black on this file to get the test to pass.

type="str",
fallback=(
env_fallback,
[
"HEALTHCHECKSIO_API_BASE_URL",
"HC_API_BASE_URL"
],
),
required=False,
no_log=True,
default="https://healthchecks.io"
),
)


Expand Down Expand Up @@ -274,7 +293,7 @@ def __init__(self, module):
def get_uuid(self, json_data):
ping_url = json_data.get("ping_url", None)
if ping_url is not None:
uuid = ping_url.split("/")[3]
uuid = ping_url.split("/")[-1]
if len(uuid) > 0:
return uuid
else:
Expand Down