Skip to content

Commit

Permalink
Add GET /api/stats/summary -> .gravity.last_update timestamp exposing…
Browse files Browse the repository at this point in the history
… the last gravity update via the API

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Sep 2, 2024
1 parent 9afc12e commit 0fa865a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api/docs/content/specs/stats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ components:
type: integer
description: Number of domain on your Pi-hole's gravity list
example: 104756
last_update:
type: integer
description: Unix timestamp of last gravity update (may be `0` if unknown)
example: 1725194639
upstreams:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions src/api/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ int api_stats_summary(struct ftl_conn *api)

cJSON *gravity = JSON_NEW_OBJECT();
JSON_ADD_NUMBER_TO_OBJECT(gravity, "domains_being_blocked", num_gravity);
JSON_ADD_NUMBER_TO_OBJECT(gravity, "last_update", gravity_last_updated());

cJSON *json = JSON_NEW_OBJECT();
JSON_ADD_ITEM_TO_OBJECT(json, "queries", queries);
Expand Down
5 changes: 5 additions & 0 deletions src/database/gravity-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -2796,3 +2796,8 @@ bool gravity_updated(void)

return changed;
}

time_t __attribute__((pure)) gravity_last_updated(void)
{
return last_updated > 0 ? (time_t)last_updated : 0;
}
2 changes: 2 additions & 0 deletions src/database/gravity-db.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ bool gravityDB_delFromTable(const enum gravity_list_type listtype, const cJSON*
bool gravityDB_edit_groups(const enum gravity_list_type listtype, cJSON *groups,
const tablerow *row, const char **message);

time_t gravity_last_updated(void) __attribute__((pure));

#endif //GRAVITY_H

0 comments on commit 0fa865a

Please sign in to comment.