// tslint:disable /** * Copyright 2022 Splunk, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"): you may * not use this file except in compliance with the License. You may obtain * a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * * Ingest API * Use the Ingest service in Splunk Cloud Services to send event and metrics data, or upload a static file, to Splunk Cloud Services. * * OpenAPI spec version: v1beta2.32 (recommended default) * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ import FormData from 'form-data'; import { createReadStream } from "fs"; import { Event, HECTokenAccessResponse, HECTokenCreateRequest, HECTokenCreateResponse, HECTokenUpdateRequest, HTTPResponse, MetricEvent, UploadSuccessResponse, } from '../models'; import BaseApiService from "../../../../baseapiservice"; import { IngestServiceExtensions } from "../../../../service_extensions/ingest"; import { SplunkError, RequestStatus } from '../../../../client'; export const INGEST_SERVICE_PREFIX: string = '/ingest/v1beta2'; export const INGEST_SERVICE_CLUSTER: string = 'api'; /** * Ingest API * Version: v1beta2.32 * Use the Ingest service in Splunk Cloud Services to send event and metrics data, or upload a static file, to Splunk Cloud Services. */ export class GeneratedIngestService extends BaseApiService { getServiceCluster() : string { return INGEST_SERVICE_CLUSTER } getServicePrefix() : string { return INGEST_SERVICE_PREFIX; } /** * Delete All dsphec tokens for a given tenant. * @param args parameters to be sent with the request * @param requestStatusCallback callback function to listen to the status of a request * @return { [key: string]: any; } */ public deleteAllCollectorTokens = (args?: object, requestStatusCallback?: (requestStatus: RequestStatus) => void): Promise<{ [key: string]: any; }> => { const path = `/ingest/v1beta2/collector/tokens`; return this.client.delete(INGEST_SERVICE_CLUSTER, this.client.buildPath('', path.split('/').slice(1)), { query: args, statusCallback: requestStatusCallback}) .then(response => response.body as { [key: string]: any; }); } /** * Delete dsphec token by name. * @param tokenName * @param args parameters to be sent with the request * @param requestStatusCallback callback function to listen to the status of a request * @return { [key: string]: any; } */ public deleteCollectorToken = (tokenName: string, args?: object, requestStatusCallback?: (requestStatus: RequestStatus) => void): Promise<{ [key: string]: any; }> => { const path_params = { tokenName: tokenName }; const path = this.template`/ingest/v1beta2/collector/tokens/${'tokenName'}`(path_params); return this.client.delete(INGEST_SERVICE_CLUSTER, this.client.buildPath('', path.split('/').slice(1)), { query: args, statusCallback: requestStatusCallback}) .then(response => response.body as { [key: string]: any; }); } /** * Get the metadata of a dsphec token by name. * @param tokenName * @param args parameters to be sent with the request * @param requestStatusCallback callback function to listen to the status of a request * @return HECTokenAccessResponse */ public getCollectorToken = (tokenName: string, args?: object, requestStatusCallback?: (requestStatus: RequestStatus) => void): Promise => { const path_params = { tokenName: tokenName }; const path = this.template`/ingest/v1beta2/collector/tokens/${'tokenName'}`(path_params); return this.client.get(INGEST_SERVICE_CLUSTER, this.client.buildPath('', path.split('/').slice(1)), { query: args, statusCallback: requestStatusCallback}) .then(response => response.body as HECTokenAccessResponse); } /** * List dsphec tokens for a tenant. * @param args parameters to be sent with the request * @param args.limit * @param args.offset * @param requestStatusCallback callback function to listen to the status of a request * @return Array */ public listCollectorTokens = (args?: { limit?: number, offset?: number, [key: string]: any }, requestStatusCallback?: (requestStatus: RequestStatus) => void): Promise> => { const path = `/ingest/v1beta2/collector/tokens`; return this.client.get(INGEST_SERVICE_CLUSTER, this.client.buildPath('', path.split('/').slice(1)), { query: args, statusCallback: requestStatusCallback}) .then(response => response.body as Array); } /** * Creates dsphec tokens. * @param hECTokenCreateRequest The API request schema for the token. * @param args parameters to be sent with the request * @param requestStatusCallback callback function to listen to the status of a request * @return HECTokenCreateResponse */ public postCollectorTokens = (hECTokenCreateRequest: HECTokenCreateRequest, args?: object, requestStatusCallback?: (requestStatus: RequestStatus) => void): Promise => { const path = `/ingest/v1beta2/collector/tokens`; return this.client.post(INGEST_SERVICE_CLUSTER, this.client.buildPath('', path.split('/').slice(1)), hECTokenCreateRequest, { query: args, statusCallback: requestStatusCallback}) .then(response => response.body as HECTokenCreateResponse); } /** * Sends events. * @param event * @param args parameters to be sent with the request * @param requestStatusCallback callback function to listen to the status of a request * @return HTTPResponse */ public postEvents = (event?: Array, args?: object, requestStatusCallback?: (requestStatus: RequestStatus) => void): Promise => { if (!event) { throw new SplunkError({ message: `Bad Request: event is empty or undefined` }); } const path = `/ingest/v1beta2/events`; return this.client.post(INGEST_SERVICE_CLUSTER, this.client.buildPath('', path.split('/').slice(1)), event, { query: args, statusCallback: requestStatusCallback}) .then(response => response.body as HTTPResponse); } /** * Sends metric events. * @param metricEvent * @param args parameters to be sent with the request * @param requestStatusCallback callback function to listen to the status of a request * @return HTTPResponse */ public postMetrics = (metricEvent?: Array, args?: object, requestStatusCallback?: (requestStatus: RequestStatus) => void): Promise => { if (!metricEvent) { throw new SplunkError({ message: `Bad Request: metricEvent is empty or undefined` }); } const path = `/ingest/v1beta2/metrics`; return this.client.post(INGEST_SERVICE_CLUSTER, this.client.buildPath('', path.split('/').slice(1)), metricEvent, { query: args, statusCallback: requestStatusCallback}) .then(response => response.body as HTTPResponse); } /** * Update the metadata of a dsphec token by name. * @param tokenName * @param hECTokenUpdateRequest The API request schema for the token. * @param args parameters to be sent with the request * @param requestStatusCallback callback function to listen to the status of a request * @return HECTokenAccessResponse */ public putCollectorToken = (tokenName: string, hECTokenUpdateRequest: HECTokenUpdateRequest, args?: object, requestStatusCallback?: (requestStatus: RequestStatus) => void): Promise => { const path_params = { tokenName: tokenName }; const path = this.template`/ingest/v1beta2/collector/tokens/${'tokenName'}`(path_params); return this.client.put(INGEST_SERVICE_CLUSTER, this.client.buildPath('', path.split('/').slice(1)), hECTokenUpdateRequest, { query: args, statusCallback: requestStatusCallback}) .then(response => response.body as HECTokenAccessResponse); } /** * Upload a CSV or text file that contains events. The file limit is 1MB or an error is returned. * @param fileName file to be uploaded * @param args parameters to be sent with the request * @param requestStatusCallback callback function to listen to the status of a request * @return UploadSuccessResponse */ public uploadFiles = (fileName: string, args?: object, requestStatusCallback?: (requestStatus: RequestStatus) => void): Promise => { const path = `/ingest/v1beta2/files`; var formData = new FormData(); const readStream = createReadStream(fileName); formData.append("upfile", readStream); const formHeaders = formData.getHeaders(); return this.client.post(INGEST_SERVICE_CLUSTER, this.client.buildPath('', path.split('/').slice(1)), formData, { query: args, headers: formHeaders, statusCallback: requestStatusCallback}) .then(response => response.body as UploadSuccessResponse); } } export type IngestService = GeneratedIngestService & IngestServiceExtensions; export const IngestService = IngestServiceExtensions(GeneratedIngestService);