Skip to content

Commit

Permalink
[master] Audit summary per day (2600hz#5822)
Browse files Browse the repository at this point in the history
* wip break

* fixes

* use created_from,to

* make a contract

* add doc+samples
  • Loading branch information
icehess authored and mark2600 committed Jul 25, 2019
1 parent 5aa8754 commit 2ab5682
Show file tree
Hide file tree
Showing 8 changed files with 543 additions and 24 deletions.
20 changes: 20 additions & 0 deletions applications/crossbar/doc/ref/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ curl -v -X POST \

## Fetch

> GET /v2/accounts/{ACCOUNT_ID}/services/audit_summary
```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/services/audit_summary
```

## Fetch

> GET /v2/accounts/{ACCOUNT_ID}/services/audit
```shell
Expand Down Expand Up @@ -188,6 +198,16 @@ curl -v -X GET \

## Fetch

> GET /v2/accounts/{ACCOUNT_ID}/services/audit_summary/{SOURCE_SERVICE}
```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/services/audit_summary/{SOURCE_SERVICE}
```

## Fetch

> GET /v2/accounts/{ACCOUNT_ID}/services/audit/{AUDIT_ID}
```shell
Expand Down
206 changes: 206 additions & 0 deletions applications/crossbar/doc/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,212 @@ curl -v -X GET \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/services/audit/{AUDIT_ID}
```

## Get service changes summary per day

Using this API you can a list of services changes (additions/removal/usage) summary per day.

> GET /v2/accounts/{ACCOUNT_ID}/services/audit_summary
```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/services/audit_summary
```

### Example

**Request:**


```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/services/audit_summary?created_from=63721540230&created_to=63722160516
```

**Response:**

```json
{
"data": {
"per-minute-voip": [
{
"2019-04-03": {
"last_timestamp": 63721549284,
"quantity": 300,
"sum_quantity": true,
"unit": "sec"
}
},
{
"2019-04-08": {
"last_timestamp": 63721972845,
"quantity": 60,
"sum_quantity": true,
"unit": "sec"
}
},
{
"2019-04-09": {
"last_timestamp": 63722073234,
"quantity": 780,
"sum_quantity": true,
"unit": "sec"
}
},
{
"2019-04-10": {
"last_timestamp": 63722156725,
"quantity": 1500,
"sum_quantity": true,
"unit": "sec"
}
},
{
"2019-04-11": {
"last_timestamp": 63722239192,
"quantity": 960,
"sum_quantity": true,
"unit": "sec"
}
}
],
"phone_number": [
{
"2019-04-04": {
"addition": 1,
"last_timestamp": 63721611287,
"quantity": 53,
"removal": 0,
"sum_quantity": false
}
}
],
"sip_device": [
{
"2019-04-09": {
"addition": 2,
"last_timestamp": 63722066155,
"quantity": 42,
"removal": 2,
"sum_quantity": false
}
},
{
"2019-04-10": {
"addition": 1,
"last_timestamp": 63722076464,
"quantity": 43,
"removal": 0,
"sum_quantity": false
}
}
],
"user": [
{
"2019-04-03": {
"addition": 1,
"last_timestamp": 63721540230,
"quantity": 84,
"removal": 0,
"sum_quantity": false
}
},
{
"2019-04-09": {
"addition": 1,
"last_timestamp": 63722056079,
"quantity": 85,
"removal": 0,
"sum_quantity": false
}
},
{
"2019-04-11": {
"addition": 1,
"last_timestamp": 63722160516,
"quantity": 85,
"removal": 1,
"sum_quantity": false
}
}
]
},
"revision": "{REVISION}",
"timestamp": "{TIMESTAMP}",
"version": "{VERSION}",
"node": "{NODE_HASH}",
"request_id": "{REQUEST_ID}",
"status": "success",
"auth_token": "{AUTH_TOKEN}"
}
```

## Get changes summary per day for a single service category

Using this API you can a list of changes (additions/removal/usage) summary per day for a single service category.

> GET /v2/accounts/{ACCOUNT_ID}/services/audit_summary/{SOURCE_SERVICE}
```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/services/audit_summary/{SOURCE_SERVICE}
```

### Example

**Request:**


```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/services/audit_summary/user?created_from=63721540230&created_to=63722160516
```

**Response:**

```json
{
"data": [
{
"2019-04-11": {
"addition": 1,
"last_timestamp": 63722160516,
"quantity": 85,
"removal": 1,
"sum_quantity": false
}
},
{
"2019-04-09": {
"addition": 1,
"last_timestamp": 63722056079,
"quantity": 85,
"removal": 0,
"sum_quantity": false
}
},
{
"2019-04-03": {
"addition": 1,
"last_timestamp": 63721540230,
"quantity": 84,
"removal": 0,
"sum_quantity": false
}
}
],
"revision": "{REVISION}",
"timestamp": "{TIMESTAMP}",
"version": "{VERSION}",
"node": "{NODE_HASH}",
"request_id": "{REQUEST_ID}",
"status": "success",
"auth_token": "{AUTH_TOKEN}"
}
```

## Change

Expand Down
37 changes: 37 additions & 0 deletions applications/crossbar/priv/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -45049,6 +45049,43 @@
}
}
},
"/accounts/{ACCOUNT_ID}/services/audit_summary": {
"get": {
"parameters": [
{
"$ref": "#/parameters/auth_token_header"
},
{
"$ref": "#/parameters/ACCOUNT_ID"
}
],
"responses": {
"200": {
"description": "request succeeded"
}
}
}
},
"/accounts/{ACCOUNT_ID}/services/audit_summary/{SOURCE_SERVICE}": {
"get": {
"parameters": [
{
"$ref": "#/parameters/auth_token_header"
},
{
"$ref": "#/parameters/SOURCE_SERVICE"
},
{
"$ref": "#/parameters/ACCOUNT_ID"
}
],
"responses": {
"200": {
"description": "request succeeded"
}
}
}
},
"/accounts/{ACCOUNT_ID}/services/available": {
"get": {
"parameters": [
Expand Down
20 changes: 2 additions & 18 deletions applications/crossbar/src/modules/cb_ledgers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ validate(Context, SourceService) ->

-spec validate(cb_context:context(), path_token(), path_token()) -> cb_context:context().
validate(Context, ?SUMMARY, ModbSuffix) ->
case get_modb_suffix(ModbSuffix) of
case kazoo_modb_util:get_modb_suffix(ModbSuffix) of
{'undefined', 'undefined'} ->
crossbar_util:response_bad_identifier(ModbSuffix, Context);
{Year, Month} ->
Expand Down Expand Up @@ -298,7 +298,7 @@ fetch_summary(Context, View, Options) ->
ViewOptions = [{'group', 'true'}
,{'reduce', 'true'}
,{'unchunkable', 'true'}
,{'nofilter', 'true'}
,{'no_filter', 'true'}
,{'should_paginate', 'false'}
| Options
],
Expand Down Expand Up @@ -446,22 +446,6 @@ build_success_response(AccountId, Ledger) ->
]
).

%%------------------------------------------------------------------------------
%% @doc
%% @end
%%------------------------------------------------------------------------------
-spec get_modb_suffix(kz_term:ne_binary()) -> {kz_term:api_integer(), kz_term:api_integer()}.
get_modb_suffix(<<YearBin:4/binary, MonthBin:2/binary>>) ->
{kz_term:safe_cast(YearBin, 'undefined', fun kz_term:to_integer/1)
,kz_term:safe_cast(MonthBin, 'undefined', fun kz_term:to_integer/1)
};
get_modb_suffix(<<YearBin:4/binary, MonthBin:1/binary>>) ->
{kz_term:safe_cast(YearBin, 'undefined', fun kz_term:to_integer/1)
,kz_term:safe_cast(MonthBin, 'undefined', fun kz_term:to_integer/1)
};
get_modb_suffix(_) ->
{'undefined', 'undefined'}.

%%------------------------------------------------------------------------------
%% @doc
%% @end
Expand Down
Loading

0 comments on commit 2ab5682

Please sign in to comment.