GET Log Usage

You can use the "GET Log Usage" request method to retrieve data usage for a specific log. Note that this API call returns the value of your log usage in bytes.

Authentication

Before you start, make sure that you have an API key with Read/Write privileges.

URL

Use the following URL format for your API call:

1
https://REGION.rest.logs.insight.rapid7.com/usage/organizations/logs/LOG_KEY&from=YYYY-MM-DD&to=YYYY-MM-DD

Use the LOG_KEY as the unique identifier for the log that you want to query.

Change REGION to match the data center for your account, such as us, eu, ca or au.

URL Parameters

Change from and to to match the date range you want to use. Date values must be in ISO 8601 form, such as the following:

  • from = YYYY-MM-DD
  • to = YYYY-MM-DD

You can also leave these parameters blank if you want to retrieve log usage for the last 10 days. You can retrieve data up to the last 24 hours.

Success Response

The success response code for this API call is HTTP 200. The content of the success response looks similar to the following:

1
{
2
"usage": {
3
"daily_usage": [
4
{
5
"usage": "290349",
6
"day": "2018-12-16"
7
},
8
{
9
"usage": "285438",
10
"day": "2018-12-17"
11
},
12
{
13
"usage": "279626",
14
"day": "2018-12-18"
15
}
16
],
17
"id": "<Log Key>",
18
"period": {
19
"to": "2018-12-18",
20
"from": "2018-12-16"
21
}
22
}
23
}

Sample Call

The following is a sample API call for GET Log usage:

1
import requests
2
import json
3
import time
4
5
6
API_KEY = 'Read/Write API key'
7
LOG_KEY = 'Log Key'
8
9
def handle_response(resp):
10
response = resp
11
time.sleep(1)
12
if response.status_code == 200:
13
print json.dumps(resp.json(), indent=4)
14
else:
15
print response.status_code
16
17
def make_request(provided_url=None):
18
headers = {'x-api-key': API_KEY}
19
url = "https://us.rest.logs.insight.rapid7.com/usage/organizations/logs/" + LOG_KEY + "?from=2018-12-10&to=2018-12-12"
20
req = requests.get(url, headers=headers)
21
return req
22
23
24
def get_usage():
25
req = make_request()
26
handle_response(req)
27
28
def start():
29
get_usage()
30
31
32
if __name__ == '__main__':
33
start()