From bf1294a10022291349dc502f80f29bc4a5ee8fc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C4=93teris=20Caune?=
Date: Mon, 9 Mar 2020 18:05:21 +0200
Subject: [PATCH] Docs / Shell scripts: add "Auto-provisioning New Checks"
section
---
templates/docs/bash.html | 21 +++++++++++++++++++++
templates/docs/bash.md | 24 ++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/templates/docs/bash.html b/templates/docs/bash.html
index 68594eb7..e06607e2 100644
--- a/templates/docs/bash.html
+++ b/templates/docs/bash.html
@@ -41,4 +41,25 @@ will accept and store first 10KB of the request body.
m=$(/usr/bin/certbot renew 2>&1)
curl -fsS --retry 3 -X POST --data-raw "$m" PING_URL
+
+
+
+Auto-provisioning New Checks
+This example uses SITE_NAME Management API to create a check "on the fly"
+(if it does not already exist) and to retrieve its ping URL.
+Using this technique, you can write services that automatically
+register with SITE_NAME the first time they run.
+#!/bin/bash
+
+API_KEY=your-api-key-here
+
+# Check's parameters. This example uses system's hostname for check's name.
+PAYLOAD='{"name": "'`hostname`'", "timeout": 60, "grace": 60, "unique": ["name"]}'
+
+# Create the check if it does not exist.
+# Grab the ping_url from JSON response using the jq utility:
+URL=`curl -s SITE_ROOT/api/v1/checks/ -H "X-Api-Key: $API_KEY" -d "$PAYLOAD" | jq -r .ping_url`
+
+# Finally, send a ping:
+curl --retry 3 $URL
\ No newline at end of file
diff --git a/templates/docs/bash.md b/templates/docs/bash.md
index a853cf95..d8ae2be8 100644
--- a/templates/docs/bash.md
+++ b/templates/docs/bash.md
@@ -49,3 +49,27 @@ In the below example, certbot's output is captured and submitted via HTTP POST:
m=$(/usr/bin/certbot renew 2>&1)
curl -fsS --retry 3 -X POST --data-raw "$m" PING_URL
```
+
+## Auto-provisioning New Checks
+
+This example uses SITE_NAME [Management API](../api/) to create a check "on the fly"
+(if it does not already exist) and to retrieve its ping URL.
+Using this technique, you can write services that automatically
+register with SITE_NAME the first time they run.
+
+
+```bash
+#!/bin/bash
+
+API_KEY=your-api-key-here
+
+# Check's parameters. This example uses system's hostname for check's name.
+PAYLOAD='{"name": "'`hostname`'", "timeout": 60, "grace": 60, "unique": ["name"]}'
+
+# Create the check if it does not exist.
+# Grab the ping_url from JSON response using the jq utility:
+URL=`curl -s SITE_ROOT/api/v1/checks/ -H "X-Api-Key: $API_KEY" -d "$PAYLOAD" | jq -r .ping_url`
+
+# Finally, send a ping:
+curl --retry 3 $URL
+```
\ No newline at end of file