Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for retrieving leases #50

Open
muja opened this issue Feb 26, 2024 · 5 comments
Open

API for retrieving leases #50

muja opened this issue Feb 26, 2024 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@muja
Copy link

muja commented Feb 26, 2024

There already seems to be an API for metrics/health etc.
An API to show the current active leases would be awesome. Specifically, I need to communicate the leases to my DNS server for internal hostname resolution

@leshow leshow added the enhancement New feature or request label Mar 1, 2024
@leshow
Copy link
Collaborator

leshow commented Mar 1, 2024

Noted! The workaround right now is by talking to the sqlite database directly, but I agree a API in dora would be nice

@muja
Copy link
Author

muja commented Mar 14, 2024

I looked inside the DB and couldn't find that info?

@leshow
Copy link
Collaborator

leshow commented Mar 20, 2024

it should be there if you have any leases? for example:

Enter ".help" for usage hints.
sqlite> select * from leases;
3232236802|�k|1|1710915902|3232236800|0
3232236803|��~Ǔ]|1|1710915922|3232236800|0
3232236804|��@�|1|1710915926|3232236800|0
3232236805|�m���|1|1710915928|3232236800|0

and the table is in migrations/ for reference

CREATE TABLE IF NOT EXISTS leases(
    ip INTEGER NOT NULL,
    client_id BLOB,
    leased BOOLEAN NOT NULL DEFAULT 0,
    expires_at INTEGER NOT NULL,
    network INTEGER NOT NULL,
    probation BOOLEAN NOT NULL DEFAULT 0,
    PRIMARY KEY(ip)
);
CREATE INDEX idx_ip_expires on leases (ip, expires_at);

if you needed to find say, all the leases where the expiry time was great than now, you could do:

sqlite> select * from leases where leased = true and expires_at > strftime('%s', 'now');
3232236802|�k|1|1710915902|3232236800|0
3232236803|��~Ǔ]|1|1710915922|3232236800|0
3232236804|��@�|1|1710915926|3232236800|0
3232236805|�m���|1|1710915928|3232236800|0

However, I agree this is not an ideal way to get the information, I think something like this should be added

@leshow leshow added the good first issue Good for newcomers label Mar 20, 2024
@muja
Copy link
Author

muja commented Mar 20, 2024

You're talking about the client_id? The hostnames I'm dealing with are ASCII but the client_id is some binary gibberish

@leshow
Copy link
Collaborator

leshow commented Apr 4, 2024

Oh, you can change that to different formats in your query:

sqlite> select hex(client_id) from leases;
9C6B00123DAF
85FF7EC7935D
12F4AA15408C
856DFFA710E7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants