pulseping-lite 0.1.0__py3-none-any.whl
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.
- pulseping_lite-0.1.0.dist-info/METADATA +183 -0
- pulseping_lite-0.1.0.dist-info/RECORD +7 -0
- pulseping_lite-0.1.0.dist-info/WHEEL +5 -0
- pulseping_lite-0.1.0.dist-info/entry_points.txt +2 -0
- pulseping_lite-0.1.0.dist-info/licenses/LICENSE +21 -0
- pulseping_lite-0.1.0.dist-info/top_level.txt +1 -0
- pulseping_lite.py +154 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pulseping-lite
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Uptime monitor and TLS certificate expiry check in one stdlib-only Python CLI.
|
|
5
|
+
Author: Alessio Auretto
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/alessio1999xx-debug/pulseping-lite
|
|
8
|
+
Project-URL: Pro version, https://py-forge.com/products/pulseping-cli
|
|
9
|
+
Keywords: uptime,monitoring,tls,ssl,certificate,healthcheck,cli,stdlib
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: System :: Monitoring
|
|
22
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
23
|
+
Classifier: Topic :: Utilities
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# pulseping-lite: uptime monitor and TLS certificate expiry check in one Python file
|
|
30
|
+
|
|
31
|
+
pulseping-lite helps with quick uptime and TLS certificate expiry checks for one URL or `host:port`, from cron or CI, without running a monitoring server. Python stdlib only (3.9+), plain text or `--json` output, and exit codes 0/1/2 so cron or CI can act on the result.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
**Free · MIT · one file · stdlib only.** One target per run; no dashboard, history or built-in alerts.
|
|
35
|
+
|
|
36
|
+
Need multi-monitor workflows? **[PulsePing CLI](https://py-forge.com/products/pulseping-cli?utm_source=github&utm_medium=readme&utm_campaign=pulseping-lite)** · **[PyForge All-Access Pass](https://py-forge.com/pass?utm_source=github&utm_medium=readme&utm_campaign=pulseping-lite)**
|
|
37
|
+
|
|
38
|
+
## Demo
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
Recorded on November 10, 2026 with asciinema + agg; real commands and output, no simulated results. The file is already downloaded when the demo starts. Public endpoint latency and certificate lifetime will change.
|
|
43
|
+
|
|
44
|
+
```console
|
|
45
|
+
$ python3 pulseping_lite.py https://example.com
|
|
46
|
+
UP https://example.com status=200 172.5 ms cert expires in 45 days
|
|
47
|
+
$ python3 pulseping_lite.py https://example.com --warn-days 365
|
|
48
|
+
DOWN https://example.com status=200 200.0 ms cert expires in 45 days
|
|
49
|
+
certificate expires in 45 days (warn at 365)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The first check exits `0`; the deliberately larger warning window exits `1` even though HTTP is up. [Recording source](docs/demo.cast) · [Capture script](docs/record-demo.py).
|
|
53
|
+
|
|
54
|
+
## Install
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install pulseping-lite
|
|
58
|
+
pulseping-lite https://example.com
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or download the single file (Python 3.9+, stdlib only, no extra packages):
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
curl -fsSLO https://raw.githubusercontent.com/alessio1999xx-debug/pulseping-lite/main/pulseping_lite.py && python3 pulseping_lite.py https://example.com
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Requires Python 3.9+. No config file and no state. Flags: `--warn-days`, `--timeout`, `--tls`, `--insecure`, `--json`, `--version`. After `pip install`, use `pulseping-lite` in place of `python3 pulseping_lite.py`.
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
### HTTP(S) health check for a URL
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
python3 pulseping_lite.py https://example.com/health
|
|
75
|
+
python3 pulseping_lite.py http://127.0.0.1:8080/ready --timeout 3
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
An HTTP status below 400 counts as up. `--timeout` is in seconds (default 5).
|
|
79
|
+
|
|
80
|
+
### TCP check for host:port
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
python3 pulseping_lite.py db.local:5432 --timeout 2
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Without `--tls`, a `host:port` target is only a TCP connect check (databases, SSH, …).
|
|
87
|
+
|
|
88
|
+
### TLS certificate expiry (days left)
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
python3 pulseping_lite.py https://example.com --warn-days 14
|
|
92
|
+
python3 pulseping_lite.py example.com:443 --tls --warn-days 14
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
For `https://` URLs the certificate is read from the same connection; for `host:port` add `--tls`. The check fails when the certificate expires in fewer than `--warn-days` days (default 14).
|
|
96
|
+
|
|
97
|
+
`--insecure` skips certificate verification. Use it only for self-signed or internal certs you already trust; certificate expiry can be unavailable in this mode (`null` in JSON).
|
|
98
|
+
|
|
99
|
+
### JSON output
|
|
100
|
+
|
|
101
|
+
Real output captured November 10, 2026 (network-dependent values vary):
|
|
102
|
+
|
|
103
|
+
```console
|
|
104
|
+
$ python3 pulseping_lite.py https://example.com --json
|
|
105
|
+
{
|
|
106
|
+
"target": "https://example.com",
|
|
107
|
+
"up": true,
|
|
108
|
+
"status_code": 200,
|
|
109
|
+
"tls_days_left": 45,
|
|
110
|
+
"issuer": null,
|
|
111
|
+
"latency_ms": 172.1,
|
|
112
|
+
"error": null
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Exit codes
|
|
117
|
+
|
|
118
|
+
| Code | Meaning |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| `0` | Target is up, and the TLS certificate (if read) is not within `--warn-days` of expiry |
|
|
121
|
+
| `1` | Target is down (HTTP ≥ 400, connect failure, timeout, TLS error) **or** the certificate is expired / fewer than `--warn-days` days left |
|
|
122
|
+
| `2` | Bad arguments (e.g. a target that is neither a URL nor `host:port`) |
|
|
123
|
+
|
|
124
|
+
There is no separate "warning" code: an expiring certificate is a failure (`1`).
|
|
125
|
+
|
|
126
|
+
## Cron example
|
|
127
|
+
|
|
128
|
+
```cron
|
|
129
|
+
# every 5 minutes: mail me if the site is down or the cert expires within 14 days
|
|
130
|
+
*/5 * * * * python3 /opt/pulseping_lite.py https://example.com/health --warn-days 14 || echo "example.com check failed" | mail -s "uptime" you@example.com
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
pulseping-lite does not send alerts and checks one target per run: it exits non-zero and you decide what happens next (mail, a script, a failed CI job).
|
|
134
|
+
|
|
135
|
+
## Measured footprint: lite CLI vs Blackbox Exporter
|
|
136
|
+
|
|
137
|
+
A one-shot check and a persistent monitoring exporter solve different jobs. This is a small, reproducible footprint check, **not a full monitoring-stack shootout**.
|
|
138
|
+
|
|
139
|
+
| Metric | pulseping-lite 0.1.0 | [Prometheus Blackbox Exporter 0.29.1](https://github.com/prometheus/blackbox_exporter/releases/tag/v0.29.1) |
|
|
140
|
+
| --- | ---: | ---: |
|
|
141
|
+
| Installed payload, excluding shared runtime | 6,511 bytes (one Python file) | 35,573,925 bytes (binary + minimal YAML) |
|
|
142
|
+
| Fresh-process start → first successful local HTTP result, median of 5 | 64.2 ms | 12.7 ms |
|
|
143
|
+
| Third-party code dependencies shipped/required | 0 Python modules | 40 Go modules embedded in binary |
|
|
144
|
+
|
|
145
|
+
**Method and machine.** Measured November 10, 2026, Europe/Rome, on this shared Linux box: kernel 6.12.113+, x86_64 KVM, 8 vCPUs (Intel Xeon), 16,002 MiB RAM, Python 3.13.5; exporter official linux-amd64 release built with Go 1.27.3. Five alternating fresh-process runs per tool, no warm-up, no filesystem-cache flush, no CPU/memory isolation. Both check the same local HTTP server returning 200 and `OK`; no DNS, public network or TLS in this benchmark.
|
|
146
|
+
|
|
147
|
+
Timing starts before process launch. For lite it ends after successful CLI exit. For the exporter it includes readiness polling (1 ms retry interval), one `/probe` request, and validation of `probe_success 1`, but excludes shutdown. It is **fresh-process**, not cold-disk timing or steady-state probe latency. Blackbox Exporter was faster in this test; lite's advantage here is its smaller payload and lack of third-party Python packages, not a blanket performance claim.
|
|
148
|
+
|
|
149
|
+
Payload uses exact file byte counts, not compressed downloads or filesystem blocks. Python, its stdlib, CA certificates and OS libraries are excluded; Go dependencies are compiled into the exporter, not packages the user installs. The dependency counts have different packaging meanings and do not estimate security or maintenance burden. No Prometheus server, dashboard, history or alerting stack was installed for either side.
|
|
150
|
+
|
|
151
|
+
**Not measured:** reliable peak RSS, TLS performance, Uptime Kuma, or the size/memory of a complete monitoring stack. No memory or Uptime Kuma numbers are claimed.
|
|
152
|
+
|
|
153
|
+
[Raw runs + release build metadata](docs/benchmark-results.json) · [Reproduction script](docs/benchmark.py) · [Setup and exact scope](docs/BENCHMARK.md).
|
|
154
|
+
|
|
155
|
+
## What it does not do
|
|
156
|
+
|
|
157
|
+
- One target per invocation; no scheduler, persistent service, history or dashboard.
|
|
158
|
+
- No built-in alert delivery. Cron, CI or your wrapper decides what to do with exit codes.
|
|
159
|
+
- HTTP status / TCP connectivity and TLS expiry only; it is not a full replacement for Blackbox Exporter or Uptime Kuma.
|
|
160
|
+
- `--timeout` bounds individual network operations, not the entire process wall time; redirects are not followed.
|
|
161
|
+
|
|
162
|
+
## Need more?
|
|
163
|
+
|
|
164
|
+
The full **[PulsePing CLI](https://py-forge.com/products/pulseping-cli?utm_source=github&utm_medium=readme&utm_campaign=pulseping-lite)** helps with:
|
|
165
|
+
|
|
166
|
+
- many monitors in one config file (HTTP with expected status and keyword, TCP, DNS, certificate expiry, gRPC health)
|
|
167
|
+
- consecutive-failure thresholds, so a single blip does not become an alert
|
|
168
|
+
- alerts to Telegram, Discord, Slack, PagerDuty or a webhook, with recovery notices
|
|
169
|
+
- a static, zero-JavaScript status page
|
|
170
|
+
|
|
171
|
+
One-time payment, no subscription. Every PyForge tool is also in the [All-Access Pass](https://py-forge.com/pass?utm_source=github&utm_medium=readme&utm_campaign=pulseping-lite).
|
|
172
|
+
|
|
173
|
+
## Tests
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
python3 test_pulseping_lite.py
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The tests use only a local server.
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT (this lite version). The full PulsePing CLI is sold separately under its own license.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
pulseping_lite.py,sha256=L15_PCDTzzKiYUlS6v-cfDY78dkaOONf8b0KHmTfWTo,6508
|
|
2
|
+
pulseping_lite-0.1.0.dist-info/licenses/LICENSE,sha256=UogbiChOs5hJVxEarcfEGO-mtfsJmsPtvoSAB493trg,1082
|
|
3
|
+
pulseping_lite-0.1.0.dist-info/METADATA,sha256=wOAGA2fAJWi5Z3su5RGKx9s-R9Kz3S3be5BfVxD_QZQ,9218
|
|
4
|
+
pulseping_lite-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
5
|
+
pulseping_lite-0.1.0.dist-info/entry_points.txt,sha256=17E3hllran9HTgSie9u6-R99gqxyLfQC3yYVhAlrTJo,55
|
|
6
|
+
pulseping_lite-0.1.0.dist-info/top_level.txt,sha256=FLkaqtxNQfoAtCNa2cD5UyqNmEelJpNZ0Q8ISYeHZ8I,15
|
|
7
|
+
pulseping_lite-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alessio Auretto (PyForge)
|
|
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 @@
|
|
|
1
|
+
pulseping_lite
|
pulseping_lite.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""pulseping-lite: check one URL or host:port and its TLS certificate expiry.
|
|
3
|
+
|
|
4
|
+
Free, MIT-licensed, reduced version of PulsePing CLI (https://py-forge.com).
|
|
5
|
+
Standard library only. Python 3.9+.
|
|
6
|
+
|
|
7
|
+
Exit codes: 0 = up (and certificate not close to expiry), 1 = down or certificate
|
|
8
|
+
expired / expiring within --warn-days, 2 = bad arguments.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import http.client
|
|
15
|
+
import json
|
|
16
|
+
import socket
|
|
17
|
+
import ssl
|
|
18
|
+
import sys
|
|
19
|
+
import time
|
|
20
|
+
import urllib.parse
|
|
21
|
+
from typing import Any, Dict, Optional, Tuple
|
|
22
|
+
|
|
23
|
+
VERSION = "0.1.0"
|
|
24
|
+
USER_AGENT = f"pulseping-lite/{VERSION}"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def parse_target(target: str) -> Tuple[str, str, int, str]:
|
|
28
|
+
"""Return (kind, host, port, path). kind is 'http', 'https' or 'tcp'."""
|
|
29
|
+
target = target.strip()
|
|
30
|
+
if "://" in target:
|
|
31
|
+
parts = urllib.parse.urlsplit(target)
|
|
32
|
+
if parts.scheme not in ("http", "https") or not parts.hostname:
|
|
33
|
+
raise ValueError(f"unsupported target {target!r}: use http(s)://host or host:port")
|
|
34
|
+
port = parts.port or (443 if parts.scheme == "https" else 80)
|
|
35
|
+
path = parts.path or "/"
|
|
36
|
+
if parts.query:
|
|
37
|
+
path += "?" + parts.query
|
|
38
|
+
return parts.scheme, parts.hostname, port, path
|
|
39
|
+
if target.startswith("["): # [ipv6]:port
|
|
40
|
+
host, _, rest = target[1:].partition("]")
|
|
41
|
+
port_s = rest.lstrip(":")
|
|
42
|
+
elif target.count(":") == 1:
|
|
43
|
+
host, port_s = target.split(":")
|
|
44
|
+
else:
|
|
45
|
+
host, port_s = target, ""
|
|
46
|
+
if not host or not port_s:
|
|
47
|
+
raise ValueError(f"target {target!r} must be a URL or host:port")
|
|
48
|
+
return "tcp", host, int(port_s), "/"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def days_left(cert: Dict[str, Any]) -> Optional[int]:
|
|
52
|
+
not_after = cert.get("notAfter") if cert else None
|
|
53
|
+
if not not_after:
|
|
54
|
+
return None
|
|
55
|
+
return int((ssl.cert_time_to_seconds(not_after) - time.time()) // 86400)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def tls_days(host: str, port: int, timeout: float, verify: bool) -> Tuple[Optional[int], str]:
|
|
59
|
+
ctx = ssl.create_default_context()
|
|
60
|
+
if not verify:
|
|
61
|
+
ctx.check_hostname = False
|
|
62
|
+
ctx.verify_mode = ssl.CERT_NONE
|
|
63
|
+
with socket.create_connection((host, port), timeout=timeout) as sock:
|
|
64
|
+
with ctx.wrap_socket(sock, server_hostname=host) as tls:
|
|
65
|
+
cert = tls.getpeercert()
|
|
66
|
+
issuer = ", ".join(v for rdn in cert.get("issuer", ()) for k, v in rdn if k in ("organizationName", "commonName"))
|
|
67
|
+
return days_left(cert), issuer
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def check(target: str, timeout: float = 5.0, warn_days: int = 14, verify: bool = True,
|
|
71
|
+
tls: bool = False) -> Dict[str, Any]:
|
|
72
|
+
"""Run one check and return a result dict."""
|
|
73
|
+
started = time.perf_counter()
|
|
74
|
+
res: Dict[str, Any] = {"target": target, "up": False, "status_code": None,
|
|
75
|
+
"tls_days_left": None, "issuer": None, "latency_ms": None, "error": None}
|
|
76
|
+
try:
|
|
77
|
+
kind, host, port, path = parse_target(target)
|
|
78
|
+
if kind in ("http", "https"):
|
|
79
|
+
if kind == "https":
|
|
80
|
+
conn: http.client.HTTPConnection = http.client.HTTPSConnection(
|
|
81
|
+
host, port, timeout=timeout,
|
|
82
|
+
context=ssl._create_unverified_context() if not verify else ssl.create_default_context())
|
|
83
|
+
else:
|
|
84
|
+
conn = http.client.HTTPConnection(host, port, timeout=timeout)
|
|
85
|
+
try:
|
|
86
|
+
conn.request("GET", path, headers={"User-Agent": USER_AGENT, "Accept": "*/*"})
|
|
87
|
+
if kind == "https" and conn.sock is not None:
|
|
88
|
+
res["tls_days_left"] = days_left(conn.sock.getpeercert())
|
|
89
|
+
resp = conn.getresponse()
|
|
90
|
+
resp.read(1024)
|
|
91
|
+
res["status_code"] = resp.status
|
|
92
|
+
finally:
|
|
93
|
+
conn.close()
|
|
94
|
+
res["up"] = resp.status < 400
|
|
95
|
+
if not res["up"]:
|
|
96
|
+
res["error"] = f"HTTP status {resp.status}"
|
|
97
|
+
else:
|
|
98
|
+
with socket.create_connection((host, port), timeout=timeout):
|
|
99
|
+
pass
|
|
100
|
+
res["up"] = True
|
|
101
|
+
if tls:
|
|
102
|
+
res["tls_days_left"], res["issuer"] = tls_days(host, port, timeout, verify)
|
|
103
|
+
res["latency_ms"] = round((time.perf_counter() - started) * 1000.0, 1)
|
|
104
|
+
days = res["tls_days_left"]
|
|
105
|
+
if days is not None and days < warn_days:
|
|
106
|
+
res["up"] = False
|
|
107
|
+
res["error"] = "certificate expired" if days < 0 else f"certificate expires in {days} days (warn at {warn_days})"
|
|
108
|
+
except Exception as exc: # network errors, TLS errors, timeouts
|
|
109
|
+
res["latency_ms"] = round((time.perf_counter() - started) * 1000.0, 1)
|
|
110
|
+
res["error"] = f"{type(exc).__name__}: {exc}"
|
|
111
|
+
return res
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
115
|
+
p = argparse.ArgumentParser(
|
|
116
|
+
prog="pulseping-lite",
|
|
117
|
+
description="Check one URL or host:port, and report days until its TLS certificate expires.")
|
|
118
|
+
p.add_argument("target", help="https://example.com/health, http://host:8080, or host:port")
|
|
119
|
+
p.add_argument("--warn-days", type=int, default=14, help="fail when the certificate expires sooner (default 14)")
|
|
120
|
+
p.add_argument("--timeout", type=float, default=5.0, help="seconds (default 5)")
|
|
121
|
+
p.add_argument("--tls", action="store_true", help="for a host:port target, also read the TLS certificate (e.g. host:443)")
|
|
122
|
+
p.add_argument("--insecure", action="store_true", help="do not verify the certificate chain")
|
|
123
|
+
p.add_argument("--json", action="store_true", help="print the result as JSON")
|
|
124
|
+
p.add_argument("--version", action="version", version=f"pulseping-lite {VERSION}")
|
|
125
|
+
return p
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def main(argv: Optional[list] = None) -> int:
|
|
129
|
+
args = build_parser().parse_args(argv)
|
|
130
|
+
try:
|
|
131
|
+
parse_target(args.target)
|
|
132
|
+
except ValueError as exc:
|
|
133
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
134
|
+
return 2
|
|
135
|
+
res = check(args.target, args.timeout, args.warn_days, not args.insecure, args.tls)
|
|
136
|
+
if args.json:
|
|
137
|
+
print(json.dumps(res, indent=2))
|
|
138
|
+
else:
|
|
139
|
+
state = "UP " if res["up"] else "DOWN"
|
|
140
|
+
line = f"{state} {res['target']}"
|
|
141
|
+
if res["status_code"] is not None:
|
|
142
|
+
line += f" status={res['status_code']}"
|
|
143
|
+
if res["latency_ms"] is not None:
|
|
144
|
+
line += f" {res['latency_ms']} ms"
|
|
145
|
+
if res["tls_days_left"] is not None:
|
|
146
|
+
line += f" cert expires in {res['tls_days_left']} days"
|
|
147
|
+
print(line)
|
|
148
|
+
if res["error"]:
|
|
149
|
+
print(f" {res['error']}")
|
|
150
|
+
return 0 if res["up"] else 1
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
if __name__ == "__main__":
|
|
154
|
+
sys.exit(main())
|