diff --git a/README.md b/README.md index 2623d50..843d84a 100644 --- a/README.md +++ b/README.md @@ -73,5 +73,5 @@ Run only one application instance per database. Back up SQLite using its backup - `GET /api/targets` — target status and most recent latency - `POST /api/targets` with `{"address":"1.1.1.1"}` — add a target -- `GET /api/targets/{id}/history?range=1h` — aggregated samples and overlapping outages for `1h` (default), `3h`, `8h`, `1d`, `2d`, or `7d`; includes window `start`/`end` (Unix seconds; null latency means a bucket contains failures) +- `GET /api/targets/{id}/history?range=1h` — aggregated samples and overlapping outages for `1h` (default), `3h`, `8h`, `1d`, `2d`, or `7d`; includes window `start`/`end` (Unix seconds; null latency means a bucket contains failures). Alternatively pass `?start=&end=` for a custom window of up to 30 days - `DELETE /api/targets/{id}` — remove a target and its history diff --git a/app.py b/app.py index a7c1d75..7bd1366 100644 --- a/app.py +++ b/app.py @@ -134,14 +134,24 @@ def do_GET(self): target_id = int(match.group(1)) if not db.execute('SELECT id FROM targets WHERE id=?', (target_id,)).fetchone(): return self.respond(404, {'error': 'Target not found'}) - ranges = {'1h': 3600, '3h': 10800, '8h': 28800, '1d': 86400, '2d': 172800, '7d': 604800} - period = parse_qs(urlsplit(self.path).query).get('range', ['1h'])[0] - if period not in ranges: - return self.respond(400, {'error': 'Invalid range'}) - end = time.time() - start = end - ranges[period] + query = parse_qs(urlsplit(self.path).query) + if 'start' in query or 'end' in query: + # Custom window: explicit epoch seconds, at most 30 days wide. + try: + start, end = float(query['start'][0]), float(query['end'][0]) + except (KeyError, ValueError): + return self.respond(400, {'error': 'Invalid range'}) + if not (end > start and end - start <= 30 * 86400): + return self.respond(400, {'error': 'Invalid range'}) + else: + ranges = {'1h': 3600, '3h': 10800, '8h': 28800, '1d': 86400, '2d': 172800, '7d': 604800} + period = query.get('range', ['1h'])[0] + if period not in ranges: + return self.respond(400, {'error': 'Invalid range'}) + end = time.time() + start = end - ranges[period] # At most 1,000 buckets; mixed success/failure buckets remain gaps. - width = ranges[period] / 1000 + width = (end - start) / 1000 samples = db.execute(''' SELECT AVG(timestamp) AS timestamp, CASE WHEN COUNT(latency)=COUNT(*) THEN AVG(latency) END AS latency diff --git a/index.html b/index.html index b14716f..aa36358 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ Ping Check

Ping Check

IP uptime monitor
@@ -12,12 +12,14 @@
Checks every 10s · retries every 1s during outages

Monitored addresses

Select an address to view response times and outage history.

AddressStatusLatencyLast checkedActions

Add an IP address to start monitoring.

- +