diff --git a/packages_generated/cockpit/src/v1/api.gen.ts b/packages_generated/cockpit/src/v1/api.gen.ts index 3f7638a8b..4cea0b829 100644 --- a/packages_generated/cockpit/src/v1/api.gen.ts +++ b/packages_generated/cockpit/src/v1/api.gen.ts @@ -32,6 +32,7 @@ import { unmarshalDisableAlertRulesResponse, unmarshalEnableAlertRulesResponse, unmarshalGetConfigResponse, + unmarshalGetRulesCountResponse, unmarshalGrafana, unmarshalGrafanaProductDashboard, unmarshalGrafanaUser, @@ -53,6 +54,7 @@ import type { DisableAlertRulesResponse, EnableAlertRulesResponse, GetConfigResponse, + GetRulesCountResponse, GlobalApiCreateGrafanaUserRequest, GlobalApiDeleteGrafanaUserRequest, GlobalApiGetCurrentPlanRequest, @@ -90,6 +92,7 @@ import type { RegionalApiGetAlertManagerRequest, RegionalApiGetConfigRequest, RegionalApiGetDataSourceRequest, + RegionalApiGetRulesCountRequest, RegionalApiGetTokenRequest, RegionalApiGetUsageOverviewRequest, RegionalApiListAlertsRequest, @@ -690,6 +693,25 @@ The output returned displays a URL to access the Alert manager, and whether the unmarshalAlertManager, ) + /** + * Get a detailed count of enabled rules in the specified Project. Includes preconfigured and custom alerting and recording rules.. Get a detailed count of enabled rules in the specified Project. Includes preconfigured and custom alerting and recording rules. + * + * @param request - The request {@link RegionalApiGetRulesCountRequest} + * @returns A Promise of GetRulesCountResponse + */ + getRulesCount = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/rules/count`, + urlParams: urlParams([ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ]), + }, + unmarshalGetRulesCountResponse, + ) + /** * Create a contact point. Contact points are email addresses associated with the default receiver, that the Alert manager sends alerts to. The source of the alerts are data sources within the same Project and region as the Alert manager. diff --git a/packages_generated/cockpit/src/v1/index.gen.ts b/packages_generated/cockpit/src/v1/index.gen.ts index 34fb919b0..1a1c08c67 100644 --- a/packages_generated/cockpit/src/v1/index.gen.ts +++ b/packages_generated/cockpit/src/v1/index.gen.ts @@ -18,6 +18,7 @@ export type { EnableAlertRulesResponse, GetConfigResponse, GetConfigResponseRetention, + GetRulesCountResponse, GlobalApiCreateGrafanaUserRequest, GlobalApiDeleteGrafanaUserRequest, GlobalApiGetCurrentPlanRequest, @@ -62,6 +63,7 @@ export type { RegionalApiGetAlertManagerRequest, RegionalApiGetConfigRequest, RegionalApiGetDataSourceRequest, + RegionalApiGetRulesCountRequest, RegionalApiGetTokenRequest, RegionalApiGetUsageOverviewRequest, RegionalApiListAlertsRequest, @@ -71,6 +73,7 @@ export type { RegionalApiTriggerTestAlertRequest, RegionalApiUpdateContactPointRequest, RegionalApiUpdateDataSourceRequest, + RulesCount, Token, TokenScope, Usage, diff --git a/packages_generated/cockpit/src/v1/marshalling.gen.ts b/packages_generated/cockpit/src/v1/marshalling.gen.ts index 2c3ab908d..5d3f0209e 100644 --- a/packages_generated/cockpit/src/v1/marshalling.gen.ts +++ b/packages_generated/cockpit/src/v1/marshalling.gen.ts @@ -17,6 +17,7 @@ import type { EnableAlertRulesResponse, GetConfigResponse, GetConfigResponseRetention, + GetRulesCountResponse, GlobalApiCreateGrafanaUserRequest, GlobalApiResetGrafanaUserPasswordRequest, GlobalApiSelectPlanRequest, @@ -46,6 +47,7 @@ import type { RegionalApiTriggerTestAlertRequest, RegionalApiUpdateContactPointRequest, RegionalApiUpdateDataSourceRequest, + RulesCount, Token, Usage, UsageOverview, @@ -257,6 +259,39 @@ export const unmarshalGetConfigResponse = ( } as GetConfigResponse } +const unmarshalRulesCount = (data: unknown): RulesCount => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'RulesCount' failed as data isn't a dictionary.`, + ) + } + + return { + dataSourceId: data.data_source_id, + dataSourceName: data.data_source_name, + rulesCount: data.rules_count, + } as RulesCount +} + +export const unmarshalGetRulesCountResponse = ( + data: unknown, +): GetRulesCountResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'GetRulesCountResponse' failed as data isn't a dictionary.`, + ) + } + + return { + customRulesCount: data.custom_rules_count, + preconfiguredRulesCount: data.preconfigured_rules_count, + rulesCountByDatasource: unmarshalArrayOfObject( + data.rules_count_by_datasource, + unmarshalRulesCount, + ), + } as GetRulesCountResponse +} + export const unmarshalGrafana = (data: unknown): Grafana => { if (!isJSONObject(data)) { throw new TypeError( diff --git a/packages_generated/cockpit/src/v1/types.gen.ts b/packages_generated/cockpit/src/v1/types.gen.ts index 7f049ebeb..63dc576b4 100644 --- a/packages_generated/cockpit/src/v1/types.gen.ts +++ b/packages_generated/cockpit/src/v1/types.gen.ts @@ -84,6 +84,21 @@ export interface GetConfigResponseRetention { defaultDays: number } +export interface RulesCount { + /** + * ID of the data source. + */ + dataSourceId: string + /** + * Name of the data source. + */ + dataSourceName: string + /** + * Total count of rules associated with this data source. + */ + rulesCount: number +} + /** * Structure representing an alert. */ @@ -430,6 +445,21 @@ export interface GetConfigResponse { productLogsRetention?: GetConfigResponseRetention } +export interface GetRulesCountResponse { + /** + * Total count of rules grouped by data source. + */ + rulesCountByDatasource: RulesCount[] + /** + * Total count of preconfigured rules. + */ + preconfiguredRulesCount: number + /** + * Total count of custom rules. + */ + customRulesCount: number +} + /** * Create a Grafana user. */ @@ -953,6 +983,17 @@ export type RegionalApiGetDataSourceRequest = { dataSourceId: string } +export type RegionalApiGetRulesCountRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * ID of the Project to retrieve the rule count for. + */ + projectId?: string +} + /** * Get a token. */