tockward 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ node_modules/
2
+ dist/
3
+ __pycache__/
4
+ *.egg-info/
5
+ .venv/
6
+ *.tgz
tockward-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tockward
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.5
2
+ Name: tockward
3
+ Version: 0.1.0
4
+ Summary: Heartbeat client for Tockward: know when your cron jobs, scripts and devices go silent.
5
+ Project-URL: Homepage, https://tockward.com
6
+ Project-URL: Source, https://github.com/tockward/tockward-cli
7
+ Project-URL: Issues, https://github.com/tockward/tockward-cli/issues
8
+ Author-email: Tockward <support@tockward.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: alerting,cron,cronjob,dead-mans-switch,heartbeat,monitoring
12
+ Classifier: Environment :: Console
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: System :: Monitoring
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+
19
+ # tockward
20
+
21
+ Heartbeat client for **[Tockward](https://tockward.com)**: know when your cron jobs, scripts and devices go silent.
22
+
23
+ Your job reports in each time it runs. If a report doesn't arrive on time, Tockward alerts you by email or Telegram.
24
+
25
+ ## Install
26
+
27
+ ```sh
28
+ npm install -g tockward # Node 18+
29
+ pip install tockward # Python 3.8+
30
+ ```
31
+
32
+ Both give you the same `tockward` command. No dependencies.
33
+
34
+ ## Command line
35
+
36
+ ```sh
37
+ tockward ping <token> # report a successful run
38
+ tockward fail <token> # report a failed run
39
+ tockward run <token> -- ./backup.sh # run a command, then report success or failure
40
+ ```
41
+
42
+ `tockward run` passes the command's output through, sends its duration along, and exits
43
+ with the command's own exit code, so it drops straight into a crontab:
44
+
45
+ ```cron
46
+ 0 3 * * * tockward run abc123 -- /usr/local/bin/backup.sh
47
+ ```
48
+
49
+ `<token>` is the monitor's token, or its full ping URL copied from the dashboard.
50
+
51
+ ## In code
52
+
53
+ ```js
54
+ const tockward = require('tockward');
55
+ await tockward.ping('abc123');
56
+ await tockward.fail('abc123');
57
+ ```
58
+
59
+ ```python
60
+ import tockward
61
+ tockward.ping("abc123")
62
+ tockward.fail("abc123")
63
+ ```
64
+
65
+ Delivery is retried twice with a 10-second timeout per attempt; an unknown token fails at once.
66
+
67
+ ## Without this package
68
+
69
+ It's just an HTTP request, so `curl` works too:
70
+
71
+ ```sh
72
+ curl -fsS https://ping.tockward.com/v1/beat/<token> # success
73
+ curl -fsS https://ping.tockward.com/v1/beat/<token>/fail # failure
74
+ ```
75
+
76
+ ## Settings
77
+
78
+ | Variable | Default | Meaning |
79
+ |---|---|---|
80
+ | `TOCKWARD_URL` | `https://ping.tockward.com` | server to report to |
81
+
82
+ ## License
83
+
84
+ MIT. Questions: support@tockward.com
@@ -0,0 +1,66 @@
1
+ # tockward
2
+
3
+ Heartbeat client for **[Tockward](https://tockward.com)**: know when your cron jobs, scripts and devices go silent.
4
+
5
+ Your job reports in each time it runs. If a report doesn't arrive on time, Tockward alerts you by email or Telegram.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install -g tockward # Node 18+
11
+ pip install tockward # Python 3.8+
12
+ ```
13
+
14
+ Both give you the same `tockward` command. No dependencies.
15
+
16
+ ## Command line
17
+
18
+ ```sh
19
+ tockward ping <token> # report a successful run
20
+ tockward fail <token> # report a failed run
21
+ tockward run <token> -- ./backup.sh # run a command, then report success or failure
22
+ ```
23
+
24
+ `tockward run` passes the command's output through, sends its duration along, and exits
25
+ with the command's own exit code, so it drops straight into a crontab:
26
+
27
+ ```cron
28
+ 0 3 * * * tockward run abc123 -- /usr/local/bin/backup.sh
29
+ ```
30
+
31
+ `<token>` is the monitor's token, or its full ping URL copied from the dashboard.
32
+
33
+ ## In code
34
+
35
+ ```js
36
+ const tockward = require('tockward');
37
+ await tockward.ping('abc123');
38
+ await tockward.fail('abc123');
39
+ ```
40
+
41
+ ```python
42
+ import tockward
43
+ tockward.ping("abc123")
44
+ tockward.fail("abc123")
45
+ ```
46
+
47
+ Delivery is retried twice with a 10-second timeout per attempt; an unknown token fails at once.
48
+
49
+ ## Without this package
50
+
51
+ It's just an HTTP request, so `curl` works too:
52
+
53
+ ```sh
54
+ curl -fsS https://ping.tockward.com/v1/beat/<token> # success
55
+ curl -fsS https://ping.tockward.com/v1/beat/<token>/fail # failure
56
+ ```
57
+
58
+ ## Settings
59
+
60
+ | Variable | Default | Meaning |
61
+ |---|---|---|
62
+ | `TOCKWARD_URL` | `https://ping.tockward.com` | server to report to |
63
+
64
+ ## License
65
+
66
+ MIT. Questions: support@tockward.com
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "tockward"
7
+ version = "0.1.0"
8
+ description = "Heartbeat client for Tockward: know when your cron jobs, scripts and devices go silent."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.8"
13
+ authors = [{ name = "Tockward", email = "support@tockward.com" }]
14
+ keywords = ["cron", "monitoring", "heartbeat", "dead-mans-switch", "cronjob", "alerting"]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Operating System :: OS Independent",
18
+ "Topic :: System :: Monitoring",
19
+ "Environment :: Console",
20
+ ]
21
+
22
+ [project.urls]
23
+ Homepage = "https://tockward.com"
24
+ Source = "https://github.com/tockward/tockward-cli"
25
+ Issues = "https://github.com/tockward/tockward-cli/issues"
26
+
27
+ [project.scripts]
28
+ tockward = "tockward.__main__:main"
@@ -0,0 +1,71 @@
1
+ """Tockward heartbeat client. No dependencies.
2
+
3
+ import tockward
4
+ tockward.ping("abc123") # "I ran"
5
+ tockward.fail("abc123") # "I failed"
6
+ tockward.ping("abc123", ms=4200) # with the run's duration
7
+
8
+ A token can also be a full ping URL (https://.../v1/beat/<token>), so URLs
9
+ copied from the dashboard work as they are. TOCKWARD_URL overrides the base.
10
+ """
11
+
12
+ import os
13
+ import re
14
+ import time
15
+ import urllib.error
16
+ import urllib.parse
17
+ import urllib.request
18
+
19
+ __version__ = "0.1.0"
20
+ __all__ = ["ping", "fail", "beat_url", "TockwardError"]
21
+
22
+ DEFAULT_BASE = "https://ping.tockward.com"
23
+
24
+
25
+ class TockwardError(Exception):
26
+ """The heartbeat could not be delivered."""
27
+
28
+
29
+ def beat_url(token, ok=True, ms=None):
30
+ if not token or not isinstance(token, str):
31
+ raise ValueError("missing token")
32
+ if re.match(r"^https?://", token, re.I):
33
+ url = re.sub(r"/fail$", "", token.rstrip("/"))
34
+ else:
35
+ base = os.environ.get("TOCKWARD_URL", DEFAULT_BASE).rstrip("/")
36
+ url = f"{base}/v1/beat/{urllib.parse.quote(token, safe='')}"
37
+ if not ok:
38
+ url += "/fail"
39
+ if ms is not None:
40
+ url += f"?ms={max(0, round(ms))}"
41
+ return url
42
+
43
+
44
+ def _send(token, ok, ms=None, timeout=10, retries=2):
45
+ url = beat_url(token, ok, ms)
46
+ last = None
47
+ for attempt in range(retries + 1):
48
+ if attempt:
49
+ time.sleep(attempt)
50
+ try:
51
+ req = urllib.request.Request(url, data=b"", method="POST",
52
+ headers={"User-Agent": f"tockward-python/{__version__}"})
53
+ with urllib.request.urlopen(req, timeout=timeout):
54
+ return True
55
+ except urllib.error.HTTPError as err:
56
+ if err.code == 404:
57
+ raise TockwardError("unknown monitor (check the token)") from None
58
+ last = TockwardError(f"HTTP {err.code}")
59
+ except (urllib.error.URLError, OSError) as err:
60
+ last = TockwardError(str(getattr(err, "reason", err)))
61
+ raise last
62
+
63
+
64
+ def ping(token, ms=None, timeout=10, retries=2):
65
+ """Report a successful run."""
66
+ return _send(token, True, ms, timeout, retries)
67
+
68
+
69
+ def fail(token, ms=None, timeout=10, retries=2):
70
+ """Report a failed run."""
71
+ return _send(token, False, ms, timeout, retries)
@@ -0,0 +1,73 @@
1
+ import subprocess
2
+ import sys
3
+ import time
4
+
5
+ from . import TockwardError, __version__, fail, ping
6
+
7
+ USAGE = """Tockward: know when your cron jobs, scripts and devices go silent.
8
+
9
+ Usage:
10
+ tockward ping <token> report a successful run
11
+ tockward fail <token> report a failed run
12
+ tockward run <token> -- <command> run a command, then report success or
13
+ failure (with its duration); exits with
14
+ the command's exit code
15
+
16
+ <token> is the monitor's token or its full ping URL.
17
+ Set TOCKWARD_URL to use another server. https://tockward.com"""
18
+
19
+
20
+ def warn(msg):
21
+ print(f"tockward: {msg}", file=sys.stderr)
22
+
23
+
24
+ def main(argv=None):
25
+ args = list(sys.argv[1:] if argv is None else argv)
26
+ if not args or args[0] in ("-h", "--help", "help"):
27
+ print(USAGE)
28
+ return 0
29
+ if args[0] in ("-v", "--version"):
30
+ print(__version__)
31
+ return 0
32
+ cmd, rest = args[0], args[1:]
33
+ if not rest:
34
+ warn("missing token")
35
+ print(USAGE, file=sys.stderr)
36
+ return 2
37
+ token, rest = rest[0], rest[1:]
38
+
39
+ if cmd in ("ping", "fail"):
40
+ try:
41
+ (ping if cmd == "ping" else fail)(token)
42
+ return 0
43
+ except (TockwardError, ValueError) as err:
44
+ warn(f"could not report: {err}")
45
+ return 1
46
+
47
+ if cmd == "run":
48
+ command = rest[1:] if rest[:1] == ["--"] else rest
49
+ if not command:
50
+ warn("nothing to run; use: tockward run <token> -- <command>")
51
+ return 2
52
+ started = time.monotonic()
53
+ try:
54
+ code = subprocess.call(command)
55
+ except OSError as err:
56
+ warn(f"could not start {command[0]}: {err}")
57
+ code = 127
58
+ if code < 0:
59
+ code = 128 - code
60
+ ms = (time.monotonic() - started) * 1000
61
+ try:
62
+ (ping if code == 0 else fail)(token, ms=ms)
63
+ except (TockwardError, ValueError) as err:
64
+ warn(f"could not report: {err}")
65
+ return code
66
+
67
+ warn(f"unknown command: {cmd}")
68
+ print(USAGE, file=sys.stderr)
69
+ return 2
70
+
71
+
72
+ if __name__ == "__main__":
73
+ sys.exit(main())