troglobit / inadyn

In-a-Dyn is a dynamic DNS client with multiple SSL/TLS library support
https://troglobit.com/projects/inadyn/
GNU General Public License v2.0
962 stars 139 forks source link

Proposal: Add --show-status and extend cache to store more information about last update #457

Open fdcastel opened 1 year ago

fdcastel commented 1 year ago

Following #455. I propose:

1) To add a --status / --show-status parameter to Inadyn.

This will do a "dry run" (run queries/collect information but don't change/update anything) and, for each configured hostname, output a result like:

```
hostname     : MY_DOMAIN.COM

update status: ok / outdated / error
error message: (only when in "error" state)
last run     : Mon Sep 25 10:10:51 2023

current ip   : XXX.XXX.215.113
last updated : Mon Sep 25 10:10:51 2023

ip source    : eth0 / command / ifconfig.me
actual ip    : XXX.XXX.215.113l
```

The `-j` / `--json` modifier could be used to output the above information in JSON format.

2) Extend the informations stored in Inadyn cache files.

Currently the `cache` file stores only the last ip address updated by `inadyn`.

Unfortunately, some other useful information are lost like:
- Timestamp of last (successful) update
- Result of last run (ok? error? which one?)
- Timestamp of last run

The cache format would need to be changed, of course. But (being a cache) this has a relatively minor impact. After a version upgrade, any attempt to read a cache file from older versions would simply be discarded (as if no cache file exists).

Opinions?

If approved, I would be glad to start working on a PR for this in the next week.

acolomb commented 1 year ago

I think that would be a great addition.

Just to be pedantic, your three examples of information are actually (partly) present now, albeit not obvious.

Not 100 % sure if that's correct, but anyway your suggestion is way more useful :-)

troglobit commented 1 year ago

Looks good to me, please go ahead! :-)

@acolomb: yeah we discussed this a bit in the other issue, I mentioned mtime there, but I didn't consider atime could be used as well. That's clever.

acolomb commented 1 year ago

Adding the info to the file's content is the better and more extensible idea anyway. I guess it's common on Linux distros nowadays to mount some system volumes with noatime, so not really reliable.

troglobit commented 1 year ago

Agreed 👍 very true.

fdcastel commented 1 year ago

Just to be pedantic, your three examples of information are actually (partly) present now, albeit not obvious.

You, sir, have eagle eyes. Nicely noted!

However, albeit clever:

1) this still leaves out where we could store the last error message if one occurred in the last run; and

2) as you already noted

> Adding the info to the file's content is the better and more extensible idea anyway. I guess it's common on Linux distros nowadays to mount some system volumes with `noatime`, so not really reliable.

Precisely! I have in my own home a small server with a ZFS filesystem mounted with `atime=off` (not that I'm planning to run Inaydn on it 😄).

Also, Inadyn could run in so many different systems (*) that the reliance of filesystem timestamps could be a flaky solution, at best.

_(*) I discovered this project when I found it running inside one of my routers._

I'm planning to attack this only in the next week so we still have time for more ideas and brainstorming.

For now, I leave you guys with a humble suggestion for the next cache file format (blatantly inspired on ddclient format)

# inadyn 2.x.x cache file - do not modify
hostname=MY_DOMAIN.COM
ip=XXX.XXX.215.113
updatedAt=1695647451    # Mon Sep 25 10:11:56 2023
updateError=    # None
lastRun=1695647451    # Mon Sep 25 10:11:56 2023
troglobit commented 1 year ago

That looks very nice. And possible to source from a shell script, I like it!