📕
API Reference
  • SpaceOne APIs
  • Common V1
    • Search Query
      • Filter Operators
    • Statistics Query
      • Ex.1 case: Project
  • Statistics V1
    • Stat API
      • Ex.1 case: Service Account
      • Ex.2 case: Project
Powered by GitBook
On this page

Was this helpful?

  1. Statistics V1

Stat API

Query for statistics

PreviousEx.1 case: ProjectNextEx.1 case: Service Account

Last updated 4 years ago

Was this helpful?

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)

query:

{
    "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 )

join_key:

refer to below images for each type's concept

query:

{
    "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 )

formula use case

{
    "resource_type": ...,
    "query": ...,
    "join": ...,
    "formulas": [
        {
            "name": "total",
            "formula": "server_count + cloud_service_count"
        },
        { 
            "formula": "total > 0",
            "operator": "QUERY"
        }
    ]
}

Operator is OPTIONAL; Value EVAL(default) will be automatically set if there's no operator has not specifically declared in formula parameters.

Value Query has to be set to perform selective result as above within formulas.

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 : "<service>.<resource>" identity.Project inventory.Server

refer to

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

refer to

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

Refers to - -

👉
👉
pandas.eval
pandas.DataFrame.query
✅
✅
❌
❌
✅
✅
❌
❌
✅
✅
✅
✅
❌
statistic query specification
statistic query specification