Quickstart
This guide walks you through creating your first Watchpost application and running a simple check. The guide also explains how you will integrate your Watchpost application with Checkmk.
This guide uses the uv package manager for commands and examples. You can use pip or another tool if you prefer. If you need to install uv, see the uv installation guide.
Create a Watchpost application
-
Initialize a new Python project:
You can omit
--packageif you prefer a single-file project. Using a package layout is recommended because it keeps your application organized as it grows. -
Add Watchpost to your project:
$ cd my-watchpost $ uv add 'watchpost[cli]' Using CPython 3.13.5 Creating virtual environment at: .venv Resolved 12 packages in 266ms Built my-watchpost @ file:///tmp/my-watchpost Prepared 6 packages in 166ms Installed 11 packages in 25ms + anyio==4.12.1 + click==8.3.1 + idna==3.11 + markdown-it-py==4.0.0 + mdurl==0.1.2 + my-watchpost==0.1.0 (from file:///Users/pit/tmp/mycontent/my-watchpost) + pygments==2.19.2 + rich==14.2.0 + starlette==0.47.3 + timelength==3.0.2 + watchpost==0.1.0We recommend installing Watchpost with the
cliextra. It adds awatchpostcommand that makes it easy to list and run checks during development. -
Edit
my-watchpost/src/my_watchpost/__init__.pyto create a minimal application: -
Verify that the app starts and contains no checks yet
$ uv run watchpost --app my_watchpost:app list-checks # (1) $ uv run watchpost --app my_watchpost:app run-checks Check Execution Results ┏━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━┓ ┃ State ┃ Environment ┃ Service Name ┃ Summary ┃ ┡━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━┩ └───────┴─────────────┴──────────────┴─────────┘- There is no output because the application does not define any checks yet.
Now let’s add a first check that verifies whether https://www.example.com is reachable and returns a 200 OK status code.
-
Add a HTTP client dependency.
We use httpx and its
AsyncClientto demonstrate async checks, but you can use any HTTP client (async or sync) for your own checks. -
Edit
my-watchpost/src/my_watchpost/__init__.pyto:- Add a new datasource that provides the http client.
- Add a check that verifies the status code of https://www.example.com.
- Register the check with the application.
- Register the datasource with the application.
-
Define a datasource that constructs httpx clients. You may wonder why this is a separate class instead of creating the client directly inside the check. In real projects your datasources often encapsulate more context (for example, which environment the client can run in) or wrap an API with domain-specific helpers. Keeping that logic in a datasource makes your checks simpler and easier to test.
-
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.
-
To use a datasource in a check, add a parameter annotated with the datasource type. Watchpost injects the instance automatically when the check runs.
- 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.
- Register the datasource with the application.
-
List and run the check
$ uv run watchpost --app my_watchpost:app list-checks my_watchpost.example_com_http_status(client_factory: my_watchpost.HttpxClientFactory) $ uv run watchpost --app my_watchpost:app run-checks Check Execution Results ┏━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓ ┃ State ┃ Environment ┃ Service Name ┃ Summary ┃ ┡━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩ │ OK │ production │ example.com HTTP status │ example.com is up │ └───────┴─────────────┴─────────────────────────┴───────────────────┘
You have now built your first Watchpost application and check. 🎉
Checkmk integration
TODO
Summary
This example shows how you can codify checks with Watchpost in a clean, testable way. If you can code it, you can check it.