Closed r2evans closed 8 months ago
Hi @r2evans
This looks very interesting, of course this helps. Databases are not so much my expertise, so every input is appreciated, thanks for that.
I try to use it and to better my script.
Is this started in sqlite3 or part of script?
Regards Ingo
I wanted to remind you that sqlite3
takes a .mode
argument that changes its output format, making it much easier to use. For instance, while it doesn't support XML, it does support json
, which is very easy to consume in most languages:
[{"login_user":"bob","host_name":"host1","time_start":null,"time_end":null,"hours":"","transferred":null,"speed":null,"result":"unk","device_id":3,"result_id":null,"rn":1},
{"login_user":"bob","host_name":"host2","time_start":"2024-01-23 09:40:18","time_end":"2024-01-23 09:46:44","hours":"0.1h","transferred":"12.42 GB","speed":"30.00 MB/s","result":"completed","device_id":4,"result_id":1412,"rn":1},
{"login_user":"jack","host_name":"somewhere","time_start":"2024-01-24 04:03:56","time_end":"2024-01-24 04:05:47","hours":"0.0h","transferred":"1.55 GB","speed":"13.00 MB/s","result":"completed","device_id":5,"result_id":1415,"rn":1},
{"login_user":"bob","host_name":"host3","time_start":"2024-01-13 15:24:34","time_end":"2024-01-13 15:35:42","hours":"0.2h","transferred":"10.09 GB","speed":"14.00 MB/s","result":"completed","device_id":6,"result_id":1382,"rn":1},
{"login_user":"sarah","host_name":"otherhost","time_start":null,"time_end":null,"hours":"","transferred":null,"speed":null,"result":"unk","device_id":7,"result_id":null,"rn":1},
{"login_user":"sarah","host_name":"somehost","time_start":"2024-01-23 08:43:39","time_end":"2024-01-23 08:55:05","hours":"0.2h","transferred":"4.95 GB","speed":"6.00 MB/s","result":"completed","device_id":8,"result_id":1411,"rn":1},
{"login_user":"bob","host_name":"host1","time_start":null,"time_end":null,"hours":"","transferred":null,"speed":null,"result":"unk","device_id":9,"result_id":null,"rn":1}]
It's true json (a complete list), not ndjson (newline-delimited json).
Again, thanks for your input...
Already played with it. But it will be a little time for me to get it running, but I'm already working on it...
In work
Hi,
thanks again for your help.
I've just published my new PRTG script. I could also used most of your query.
This doesn't produce XML, but I was inspired by your repo to form my own single-query for much of the same information. When connected to the
config.db
file, we can attach theactivity.db
(assuming current-directory here) to get to the other tables in the same command.This saves repeated calls to
sqlite3
, and while repeated calls is likely performant enough, I thought it might be good (and/or useful) to unify it into a singleselect
statement.Output (de-PII-ized):
While my use is for a simple ssh console output, the method could easily be adapted to produce XML instead of the above tabular format.
rdt.log_type='1111'
relates to thelt.log_type
formats I added here; most of thatcase when
onlt.log_type
may never be used, but I keep it as built-in documentation. (I found the meanings by comparing the timestamps with my Syno ABB log output. Imperfect.)jq
).rt.task_config
conditional a bit more specific, guarding against false-joins on pattern matching.rn
is simply to return the last few rows for eachdevice_id
, I wanted a simple history/trend.left join
versusinner join
gives us the empty rows where ABB is showing "nothing recent". (ABB Portal may still offer restoration options for those.)I started mapping out the databases so that I could better understand the joins.
This is far from complete and would benefit from completing the links of foreign keys (and it does not attempt to differentiate between
config.db
-vs-activity.db
, they appear to be "all the same db" after theattach database...
above.This can be "played with" using https://sql.toad.cz, clicking on "Save / Load", pasting the below text into the "Input/Output" text-input, then clicking "LOAD XML".
schema xml
```Offered solely as a "hope it helps".