Project

General

Profile

Actions

Feature #4366

closed

Implement API access to event database

Added by Jan Mach about 6 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Development - GUI
Target version:
Start date:
10/12/2018
Due date:
% Done:

100%

Estimated time:
To be discussed:

Description

It would be useful for many applications that the event database is be accessible via some kind of HTTPS API. For starters just implement the API_TOKEN authentication mechanism and provide the same interface as in the event search page, but this time returning JSON responses.


Related issues

Related to Mentat - Feature #4235: Hawat: Improve propagation of view metadata into templatesClosedJan Mach07/27/2018

Actions
Related to Mentat - Feature #7578: Create API for reports/dashboardClosedRajmund Hruška04/06/2022

Actions
Actions #1

Updated by Jan Mach about 6 years ago

  • Status changed from New to In Progress
Actions #2

Updated by Jan Mach about 6 years ago

  • % Done changed from 0 to 30
Actions #3

Updated by Jan Mach about 6 years ago

  • Related to Feature #4235: Hawat: Improve propagation of view metadata into templates added
Actions #5

Updated by Radko Krkoš about 6 years ago

I am probably not the one you are asking, but I like it a lot.
I have just one remark.

Jan Mach wrote:

Valid search:
https://mentat-alt.cesnet.cz/mentat/api/events/search?dt_from=2018-10-19+00%3A00%3A00&dt_to=&source_addrs=&source_ports=&submit=Search

The sqlquery is returned as:

"b'SELECT * FROM events WHERE \"detecttime\" >= \\'2018-10-19T00:00:00+00:00\\'::timestamptz ORDER BY \"detecttime\" DESC LIMIT 100'" 

I would prefer a version without all the horrible escaping, like this:

"SELECT * FROM events WHERE detecttime >= '2018-10-19T00:00:00+00:00'::timestamptz ORDER BY detecttime DESC LIMIT 100" 

That version can be used directly for all derived uses I can think of.

Actions #6

Updated by Jan Mach about 6 years ago

Radko Krkoš wrote:

I am probably not the one you are asking, but I like it a lot.
I have just one remark.

Jan Mach wrote:

Valid search:
https://mentat-alt.cesnet.cz/mentat/api/events/search?dt_from=2018-10-19+00%3A00%3A00&dt_to=&source_addrs=&source_ports=&submit=Search

The sqlquery is returned as:
[...]

I would prefer a version without all the horrible escaping, like this:
[...]
That version can be used directly for all derived uses I can think of.

Thank you for the remark. I have fixed it to the following form:

"SELECT * FROM events WHERE \"detecttime\" >= '2018-10-22T00:00:00+00:00'::timestamptz ORDER BY \"detecttime\" DESC LIMIT 100" 

Sadly there is nothing more that can be done with the escaping of " character, because it is a valid SQL syntax for column names as it is printed by psycopg and it being rendered into JSON and then displayed as part of that JSON, so the escaping is necessary. I could of course strip all " characters from that string, but I consider that a bad idea, because it alters the original SQL command. I think, that the main purpose of this feature is to know the exact SQL command that is being executed, not a mangled version.

Actions #7

Updated by Radko Krkoš about 6 years ago

Jan Mach wrote:

Sadly there is nothing more that can be done with the escaping of " character, because it is a valid SQL syntax for column names as it is printed by psycopg and it being rendered into JSON and then displayed as part of that JSON, so the escaping is necessary. I could of course strip all " characters from that string, but I consider that a bad idea, because it alters the original SQL command. I think, that the main purpose of this feature is to know the exact SQL command that is being executed, not a mangled version.

This is more than enough for me. I was also unsure about the column name escaping and I am happy with the solution.

Actions #8

Updated by Jan Mach about 6 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 90 to 100
Actions #9

Updated by Rajmund Hruška over 2 years ago

  • Related to Feature #7578: Create API for reports/dashboard added
Actions

Also available in: Atom PDF