Stat API
Query for statistics
Statistic query format
NO
KEY
TYPE
REQUIRED
DESC
1
resource_type
string
âś…
Main resource type to select with grouping
2
query
dict
âś…
Aggregate for grouping and its specification
3
join
list
❌
Joining resource which implements
4
formulas
list
❌
calculation for formula which stands
Full specification of Stat query
{
    "resource_type": ...,
    "query": {...},
    "join": [...],
    "formulas": [...]
}{
    "resource_type": "identity.ServiceAccount",
    "query": {
        "aggregate": {
            "group": {
                "keys": [
                    {
                        "key": "provider",
                        "name": "provider"
                    },
                    {
                        "key": "service_account_id",
                        "name": "service_account_id"
                    },
                    {
                        "key": "name",
                        "name": "service_account_name"
                    }
                ]
            }
        },
        "sort": {
            "name": "resource_count",
            "desc": true
        },
        "limit": 5
    } 
}query specification : (type: dict)
NO
KEY
TYPE
REQUIRED
DESC
1
resource_type
string
âś…
Main resource type to select with grouping
2
query
dict
âś…
query for grouping statistic main select item
{
    "resource_type": ...,
    "query": ...,
    "join": [
        {
            "keys": [
                "service_account_id"   
            ],
            "resource_type": "inventory.Server",
            "query": {
                "aggregate": {
                    "unwind": [
                        {
                            "path": "collection_info.service_accounts"
                        }
                    ],
                    "group": {
                        "keys": [
                            {
                                "key": "service_account_id",
                                "name": "service_account_id"
                            }
                        ],
                        "fields": [
                            {
                                "operator": "count",
                                "name": "server_count"
                            }
                        ]
                    }
                }
            }
        },
        {
            "keys": [
                "service_account_id"
            ],
            "type": "RIGHT",
            "resource_type": "inventory.CloudService",
            "query": {
                "aggregate": {
                    "unwind": [
                        {
                            "path": "collection_info.service_accounts"
                        }
                    ],
                    "group": {
                        "keys": [
                            {
                                "key": "service_account_id",
                                "name": "service_account_id"
                            }
                        ],
                        "fields": [
                            {
                                "operator": "count",
                                "name": "cloud_service_count"
                            }
                        ]
                    }
                }
            }
        },
        {
            "keys": [
                "service_account_id"
            ],
            "type": "RIGHT",
            "resource_type": "secret.Secret",
            "query": {
                "aggregate": {
                    "group": {
                        "keys": [
                            {
                                "key": "service_account_id",
                                "name": "service_account_id"
                            }
                        ],
                        "fields": [
                            {
                                "operator": "count",
                                "name": "secret_count"
                            }
                        ]
                    }
                }
            }
        }
    ],
    "formulas": ...
}Note: join has a dependencies on main resource_type, and query must pair with resource_type & query
join specification ( type: list )
NO
KEY
TYPE
REQUIRED
DESC
1
keys
list
❌
Primary columns or keys to join with main resource of query and index join will be performed if keys hasn't given
2
type
string
❌
Type of join in SQL
LEFT (default)
RIGHT
INNER
OUTER
3
resource_type
string
âś…
Resource type to join with
4
query
dict
âś…
Select query for joining with primary resources

{
    "resource_type": ...,
    "query": ...,
    "join": ...,
    "formulas": [
        {
            "name": "resource_count",
            "formula": "server_count + cloud_service_count"
        }
    ]
}Note: formulas has a dependencies on main resource_type, and query must pair with resource_type & query and join(if needed)
formula specification : ( type: list )
NO
KEY
TYPE
REQUIRED
DESC
1
name
string
âś…
name of variable that stores performed formula
2
formula
string
âś…
algebraic formulas to calculate given form
3
operator
string
❌
optional values in EVAL(default), QUERY
formula use case
{
    "resource_type": ...,
    "query": ...,
    "join": ...,
    "formulas": [
        {
            "name": "total",
            "formula": "server_count + cloud_service_count"
        },
        { 
            "formula": "total > 0",
            "operator": "QUERY"
        }
    ]
}Last updated
Was this helpful?