GET Logs Usage

You can use the "GET Logs Usage" request method to retrieve data usage for all logs in the specified time range. The results will be sorted in ascending order of data received. Note that this API call returns the value of all 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?time_range=Last7Days&interval=day

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

Aggregated usage data is available for the last seven days. Alternatively, you can specify a relative time range using time_range=Last7Days. At this time, only Day is available as a supported interval.

However, if a log has not received data, it will not appear in the results for that day.

Success Response

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

1
{
2
"per_day_usage": {
3
"usage": [
4
{
5
"interval": "2018-12-16",
6
"log_usage": [
7
{
8
"usage": 8267539,
9
"id": "b2f37a6f-"
10
},
11
{
12
"usage": 9289532,
13
"id": "cec3450b-"
14
},
15
{
16
"usage": 12627779,
17
"id": "adc221c6-"
18
}
19
...
20
]
21
},
22
{
23
"interval": "2018-12-17",
24
"log_usage": [
25
{
26
"usage": 7648949,
27
"id": "50499f85-"
28
},
29
{
30
"usage": 7764258,
31
"id": "b2f37a6f-"
32
}
33
...
34
]
35
},
36
{
37
"interval": "2018-12-18",
38
"log_usage": [
39
{
40
"usage": 8388395,
41
"id": "50499f85-"
42
},
43
{
44
"usage": 8596388,
45
"id": "cec3450b-"
46
},
47
{
48
"usage": 12257438,
49
"id": "adc221c6-"
50
}
51
...
52
]
53
}
54
],
55
"period": {
56
"to": "2018-12-18",
57
"from": "2018-12-16"
58
},
59
"usage_units": "bytes",
60
"report_interval": "day"
61
}
62
}

Sample Call

The following is a sample API call for GET Logs Usage:

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