Code driven monitoring checks for Checkmk
Project description
Watchpost – code-driven monitoring checks for Checkmk
Watchpost is a small framework for writing monitoring checks as Python code and integrating them with Checkmk. It helps you configure checks through a simple function decorator, handles running checks across and against multiple environments, and supports you in gathering data from external systems.
Example
Install Watchpost in your project:
pip install 'watchpost[cli]'
You can now write a basic Watchpost application like this:
import urllib.error
import urllib.request
from watchpost import EnvironmentRegistry, Watchpost, check, crit, ok
ENVIRONMENTS = EnvironmentRegistry()
PRODUCTION = ENVIRONMENTS.new("production")
@check( # (1)
name="example.com HTTP status",
service_labels={},
environments=[PRODUCTION],
cache_for="5m",
)
async def example_com_http_status():
try:
with urllib.request.urlopen("https://www.example.com") as response:
status_code = response.status
except urllib.error.HTTPError as e:
status_code = e.code
if status_code != 200:
return crit( # (2)
"example.com returned an error",
details=f"Expected status: 200\nActual status: {status_code}\n",
)
return ok("example.com is up") # (3)
app = Watchpost(
checks=[
example_com_http_status, # (4)
],
execution_environment=PRODUCTION,
)
-
Use the
@checkdecorator to define your check:- A human-friendly name that will appear as the service name in Checkmk.
- Optional service labels to attach to the Checkmk service.
- The environments this check targets.
- A cache duration that controls how long a result is kept before the check runs again.
-
If the check fails, return
crit(...). The details will be shown in the Checkmk service to help troubleshooting. -
If everything is fine, return
ok(...). -
Register the check with the application.
Assuming this is saved as example.py, you can run it locally as such using the watchpost CLI:
$ watchpost --app example:app run-checks
Check Execution Results
┏━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓
┃ State ┃ Environment ┃ Service Name ┃ Summary ┃
┡━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩
│ OK │ production │ example.com HTTP status │ example.com is up │
└───────┴─────────────┴─────────────────────────┴───────────────────┘
The Checkmk integration makes use of HTTP to retrieve the check results from the Watchpost application. To support this, Watchpost is a valid ASGI web application which you can run with any ASGI server, for example uvicorn:
$ pip install uvicorn
$ uvicorn example:app
INFO: Started server process [12345]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Capabilities at a glance
- Checks and results
@checkdecorator, multiple result modes (single, multiple, yielded, builder)- Result helpers:
ok,warn,crit,unknown, metrics, thresholds
- Environments and scheduling
- Target vs. execution environments, pluggable scheduling strategies with validation
- Datasources
- Simple base class (
Datasource) and factory pattern to share configuration
- Simple base class (
- Execution and streaming
- Key‑aware executor, error aggregation, Checkmk output generation
- Caching
- In‑memory, disk, and optional Redis backends; memoization helper
- ASGI / HTTP
- Starlette app; routes:
/,/healthcheck,/executor/statistics,/executor/errored
- Starlette app; routes:
Documentation
See ./docs for more information.
License
Watchpost is licensed under the Apache License, Version 2.0, (see LICENSE or https://www.apache.org/licenses/LICENSE-2.0).
Watchpost internally makes use of various open-source projects. You can find a full list of these projects and their licenses in THIRD_PARTY_LICENSES.md.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Watchpost by you, as defined in the Apache-2.0 license, shall be licensed under the Apache License, Version 2.0, without any additional terms or conditions.
We make use of Lefthook for pre-commit and pre-push hooks that verify your code is valid.
To set up the hooks, run uv run lefthook install.
Affiliation
This project has no official affiliation with Checkmk GmbH or any of its affiliates. "Checkmk" is a trademark of Checkmk GmbH.
History
This project is a fork of takkt-ag/watchpost.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file watchpost-0.1.4.tar.gz.
File metadata
- Download URL: watchpost-0.1.4.tar.gz
- Upload date:
- Size: 52.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2756cfa3aef5d3632ea072e3c2bb8f47af6240016680f4f31c35be108e5a553a
|
|
| MD5 |
d797ced9c9bb3fd57cd9a956c246349b
|
|
| BLAKE2b-256 |
b06fa003a95dc84a6f8eb83820b2b2fc529e527bbe9ade79989b7a9e5d205218
|
Provenance
The following attestation bundles were made for watchpost-0.1.4.tar.gz:
Publisher:
release.yml on pitkley/watchpost
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
watchpost-0.1.4.tar.gz -
Subject digest:
2756cfa3aef5d3632ea072e3c2bb8f47af6240016680f4f31c35be108e5a553a - Sigstore transparency entry: 983213414
- Sigstore integration time:
-
Permalink:
pitkley/watchpost@87dacea718e6b8c1476044bd40e3cd6eff9ab56e -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/pitkley
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@87dacea718e6b8c1476044bd40e3cd6eff9ab56e -
Trigger Event:
push
-
Statement type:
File details
Details for the file watchpost-0.1.4-py3-none-any.whl.
File metadata
- Download URL: watchpost-0.1.4-py3-none-any.whl
- Upload date:
- Size: 66.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0eea36208bef6a69acda392f3bee504e5e33f53a64104d7362e6d3c1012c1bfb
|
|
| MD5 |
d9771b72f172fd3cdd47d9903adf9d3f
|
|
| BLAKE2b-256 |
9eb3ac17ae69ca43fd511cd97e5744fdf1a95611894f6445cf4ae98421efdd40
|
Provenance
The following attestation bundles were made for watchpost-0.1.4-py3-none-any.whl:
Publisher:
release.yml on pitkley/watchpost
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
watchpost-0.1.4-py3-none-any.whl -
Subject digest:
0eea36208bef6a69acda392f3bee504e5e33f53a64104d7362e6d3c1012c1bfb - Sigstore transparency entry: 983213437
- Sigstore integration time:
-
Permalink:
pitkley/watchpost@87dacea718e6b8c1476044bd40e3cd6eff9ab56e -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/pitkley
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@87dacea718e6b8c1476044bd40e3cd6eff9ab56e -
Trigger Event:
push
-
Statement type: