import {z} from 'zod' export type Configv1LogFieldPath = {selector?: string | undefined}; export type LogIngestConfigStringNormalization = {default_value?: string | undefined, sanitize_patterns?: Array | undefined, source?: Array | undefined, value_map?: {[key: string]: string} | undefined}; export type LogIngestConfigNamedStringNormalization = {normalization?: LogIngestConfigStringNormalization | undefined, target?: string | undefined}; export type LogIngestConfigTimestampNormalization = {source?: Array | undefined}; export type LogIngestConfigFieldNormalization = {custom_field_normalization?: Array | undefined, message?: LogIngestConfigStringNormalization | undefined, service?: LogIngestConfigStringNormalization | undefined, severity?: LogIngestConfigStringNormalization | undefined, timestamp?: LogIngestConfigTimestampNormalization | undefined}; export type LogIngestConfigLogFieldParserMode = 'ENABLED' | 'DISABLED'; export type LogParserGrokParser = {pattern?: string | undefined}; export type LogParserKeyValueParser = {delimiter: string, pair_separator: string, trim_set?: string | undefined}; export type LogParserParserType = 'JSON' | 'REGEX' | 'KEY_VALUE' | 'GROK'; export type LogParserRegexParser = {regex?: string | undefined}; export type LogIngestConfigLogParser = {grok_parser?: LogParserGrokParser | undefined, key_value_parser?: LogParserKeyValueParser | undefined, parser_type?: LogParserParserType | undefined, regex_parser?: LogParserRegexParser | undefined}; export type LogIngestConfigLogFieldParser = {destination?: Configv1LogFieldPath | undefined, mode?: LogIngestConfigLogFieldParserMode | undefined, parser?: LogIngestConfigLogParser | undefined, source?: Configv1LogFieldPath | undefined}; export type LogIngestConfigPlaintextParserMode = 'ENABLED' | 'DISABLED'; export type LogIngestConfigPlaintextParser = {keep_original?: boolean | undefined, mode?: LogIngestConfigPlaintextParserMode | undefined, name?: string | undefined, parser?: LogIngestConfigLogParser | undefined}; export type Configv1LogIngestConfig = {created_at?: string | undefined, field_normalization?: LogIngestConfigFieldNormalization | undefined, field_parsers?: Array | undefined, plaintext_parsers?: Array | undefined, updated_at?: string | undefined}; export type Configv1UpdateLogIngestConfigRequest = {create_if_missing?: boolean | undefined, dry_run?: boolean | undefined, log_ingest_config?: Configv1LogIngestConfig | undefined}; export type UpdateApiApiV1ConfigLogIngestConfigArgs = {body: Configv1UpdateLogIngestConfigRequest}; export type UpdateApiApiV1ConfigLogIngestConfigOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const configv1LogFieldPath = z.object({selector: z.string().optional()}); export const logIngestConfigStringNormalization = z.object({default_value: z.string().optional(), sanitize_patterns: z.array(z.string()).optional(), source: z.array(configv1LogFieldPath).optional(), value_map: z.record(z.string(), z.string()).optional()}); export const logIngestConfigNamedStringNormalization = z.object({normalization: logIngestConfigStringNormalization.optional(), target: z.string().optional()}); export const logIngestConfigTimestampNormalization = z.object({source: z.array(configv1LogFieldPath).optional()}); export const logIngestConfigFieldNormalization = z.object({custom_field_normalization: z.array(logIngestConfigNamedStringNormalization).optional(), message: logIngestConfigStringNormalization.optional(), service: logIngestConfigStringNormalization.optional(), severity: logIngestConfigStringNormalization.optional(), timestamp: logIngestConfigTimestampNormalization.optional()}); export const logIngestConfigLogFieldParserMode = z.enum(["ENABLED", "DISABLED"]); export const logParserGrokParser = z.object({pattern: z.string().optional()}); export const logParserKeyValueParser = z.object({delimiter: z.string(), pair_separator: z.string(), trim_set: z.string().optional()}); export const logParserParserType = z.enum(["JSON", "REGEX", "KEY_VALUE", "GROK"]); export const logParserRegexParser = z.object({regex: z.string().optional()}); export const logIngestConfigLogParser = z.object({grok_parser: logParserGrokParser.optional(), key_value_parser: logParserKeyValueParser.optional(), parser_type: logParserParserType.optional(), regex_parser: logParserRegexParser.optional()}); export const logIngestConfigLogFieldParser = z.object({destination: configv1LogFieldPath.optional(), mode: logIngestConfigLogFieldParserMode.optional(), parser: logIngestConfigLogParser.optional(), source: configv1LogFieldPath.optional()}); export const logIngestConfigPlaintextParserMode = z.enum(["ENABLED", "DISABLED"]); export const logIngestConfigPlaintextParser = z.object({keep_original: z.boolean().optional(), mode: logIngestConfigPlaintextParserMode.optional(), name: z.string().optional(), parser: logIngestConfigLogParser.optional()}); export const configv1LogIngestConfig = z.object({created_at: z.string().optional(), field_normalization: logIngestConfigFieldNormalization.optional(), field_parsers: z.array(logIngestConfigLogFieldParser).optional(), plaintext_parsers: z.array(logIngestConfigPlaintextParser).optional(), updated_at: z.string().optional()}); export const configv1UpdateLogIngestConfigResponse = z.object({log_ingest_config: configv1LogIngestConfig.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * PUT /api/v1/config/log-ingest-config */ export const updateApiApiV1ConfigLogIngestConfig = async (args: UpdateApiApiV1ConfigLogIngestConfigArgs, options?: UpdateApiApiV1ConfigLogIngestConfigOptions) => { const {baseUrl = "https://tenant.chronosphere.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("API-Token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/config/log-ingest-config${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(configv1UpdateLogIngestConfigResponse, await res.json()) };