Python Modifying SQLite3 Database

There are a number of places inside the F5 Dashboard project where the database needs to be modified. A good example of this is from the F5 info gathering page.

The F5 info page is displaying some columns from a database table.
There are a few things going on here so I will start at the top with the refresh button.

Refresh Button

This is what starts the entire process off. This will run a python script that runs a few info gathering GET requests to all the F5s. This is executed sequentially in the order of the F5s.

Once the JSON output is returned from the API’s that is then parsed and we look for certain things as you can see in the table.
This is then saved to the database along with the time it was performed.

The HMTL page will display the database table, and in the top left will grab one of the columns that has the last updated date/time in and display that. I think I am using the last entry in the table for this.

The Process

The user will go to the /info view. This will query the database table called F5Info and pass that to the HTML template to render. there is some JavaScript to make the table look neater.

The refresh F5 info button may then be pressed to perform the function view called /bg_get_info.
This is what will run through can send the API GET requests to each F5. The return JSON is parsed and then the the database table data is deleted and new data added.

Database Calls

The below code is partial calling another python file that contains all of the database modification commands.

It is doing three things; deleting all data in the F5Info table, then adding new data and finally closing the connection

In all the below I have added the class to make it easier to refer back to. In reality these functions are all part of the same DBcontroller class.

Deleting F5Info Table Data

Adding New F5Info Table Data

Close Database Connection

Final Part – Get Last Update Time/Date

Leave a Comment

Your email address will not be published. Required fields are marked *