Introduction

When enabled, any available report can be scheduled to be run at certain times.

Hourly, daily, weekly, monthly, or yearly.

The report can be sent as a formatted HTML report to an email address or as a http POST to a URL.

Creating a schedule

Open a report and then click on add schedule. Fill in the form and click submit. The schedule will be created and available for further editing in your profile.

Optional email

Your profile email is by default the recipient of the report. Enter a valid email in the email field to use a different address.

Optional post url

Enter a valid http address that accepts POST methods. A JSON representation of the report results will be posted there, in Pandas orient="record" format.

reference: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_json.html

NOTE: if a URL is specified then any email is not used.

headers

From the profile editing page, headers can be added to the post call by specifying them as follows:

header name: value;another header: value

The value will be split on ; and each header attached separately.

Calling reports by API

Any report can be called by an API to return results as JSON.

The format of the URL of the API call is:

<reporter-host-name>/api/call/report-id/

Any parameters to the report can be provided as URL parameters. Example:

<reporter-host-name>/api/call/report-id/?_field_name=value

Authorization

To call a report you must use a token authorization header to provide credentials to SR. Tokens can be created and viewed in the Admin / Tokens page.

Tokens comprise a username and a token value. The username and token value need to be combined into a Basic Authorization header. This bit of Python code can be used to make a basic header.

def basic_auth(username: str, password: str) -> str:
    """
    encode a basic auth token for an Authorization header
    """
    token = base64.b64encode(f":".encode("utf-8")).decode(
        "ascii"
    )
    return f"Basic "

Authorization example

GET http://localhost:5052/api/call/37/ Authorization: Basic YXBpLnVzZXI6ZGVidWcta2V5 Accept: application/json

Results

Results are JSON. Fields:

field description
message Any error message
ok true when no errors
records list of query results

Each entry in the record list will be composed of the columns from the query and the values for each row.

Results example:

    {
      "message": "",
      "ok": true,
      "records": [
        {
          "current_date": "2023-08-09",
          "current_time": "08:14:54",
          "database_name": "sqllite-all",
          "database_type": "sqlite",
          "datetime(now)": "2023-08-09 08:14:54",
          "now": "2023-08-09 08:14:54",
          "time(now)": "08:14:54"
        },
        {
          "current_date": "2023-08-09",
          "current_time": "8:14:55",
          "database_name": "mysql-all",
          "database_type": "mysql+pymysq",
          "datetime(now)": "2023-08-09 08:14:55",
          "now": "2023-08-09 08:14:55",
          "time(now)": "08 14 55"
        },
      ]
    }