diff --git a/components/splunk_http_event_collector/actions/check-health/check-health.mjs b/components/splunk_http_event_collector/actions/check-health/check-health.mjs new file mode 100644 index 0000000000000..addffeedaaabb --- /dev/null +++ b/components/splunk_http_event_collector/actions/check-health/check-health.mjs @@ -0,0 +1,24 @@ +import splunk from "../../splunk_http_event_collector.app.mjs"; + +export default { + key: "splunk_http_event_collector-check-health", + name: "Check Splunk HTTP Event Collector Health", + description: "Checks the health status of the Splunk HTTP Event Collector to ensure it is available and ready to receive events. [See the documentation](https://docs.splunk.com/Documentation/Splunk/8.2.0/RESTREF/RESTinput#services.2Fcollector.2Fhealth)", + version: "0.0.1", + type: "action", + props: { + splunk, + }, + async run({ $ }) { + try { + const response = await this.splunk.checkHealth({ + $, + }); + $.export("$summary", `Splunk HTTP Event Collector health status: "${response.text}"`); + return response; + } catch (error) { + $.export("$summary", `Failed to check Splunk HTTP Event Collector health: ${error.message}`); + throw new Error(`Health check failed: ${error.message}`); + } + }, +}; diff --git a/components/splunk_http_event_collector/actions/send-batch-events/send-batch-events.mjs b/components/splunk_http_event_collector/actions/send-batch-events/send-batch-events.mjs new file mode 100644 index 0000000000000..5384bf91ac7e4 --- /dev/null +++ b/components/splunk_http_event_collector/actions/send-batch-events/send-batch-events.mjs @@ -0,0 +1,57 @@ +import splunk from "../../splunk_http_event_collector.app.mjs"; +import { parseJson } from "../../common/utils.mjs"; + +export default { + key: "splunk_http_event_collector-send-batch-events", + name: "Send Batch Events", + description: "Sends multiple events in a single request to the Splunk HTTP Event Collector. [See the documentation](https://docs.splunk.com/Documentation/Splunk/8.2.0/RESTREF/RESTinput#services.2Fcollector.2Fraw)", + version: "0.0.1", + type: "action", + props: { + splunk, + batchEvents: { + type: "string[]", + label: "Batch Events", + description: "A batch of event data to send to Splunk", + }, + channel: { + propDefinition: [ + splunk, + "channel", + ], + }, + sourcetype: { + propDefinition: [ + splunk, + "sourcetype", + ], + }, + index: { + propDefinition: [ + splunk, + "index", + ], + }, + host: { + propDefinition: [ + splunk, + "host", + ], + }, + }, + async run({ $ }) { + const response = await this.splunk.sendMultipleEvents({ + $, + params: { + channel: this.channel, + sourcetype: this.sourcetype, + index: this.index, + host: this.host, + }, + data: parseJson(this.batchEvents), + }); + + $.export("$summary", `Successfully sent ${this.batchEvents.length} events to Splunk.`); + return response; + }, +}; diff --git a/components/splunk_http_event_collector/actions/send-event/send-event.mjs b/components/splunk_http_event_collector/actions/send-event/send-event.mjs new file mode 100644 index 0000000000000..6512c3605b354 --- /dev/null +++ b/components/splunk_http_event_collector/actions/send-event/send-event.mjs @@ -0,0 +1,58 @@ +import splunk from "../../splunk_http_event_collector.app.mjs"; +import { parseJson } from "../../common/utils.mjs"; + +export default { + key: "splunk_http_event_collector-send-event", + name: "Send Event", + description: "Sends an event to Splunk HTTP Event Collector. [See the documentation](https://docs.splunk.com/Documentation/Splunk/8.2.0/RESTREF/RESTinput#services.2Fcollector.2Fevent)", + version: "0.0.1", + type: "action", + props: { + splunk, + eventData: { + type: "string", + label: "Event Data", + description: "The event data to send to Splunk", + }, + channel: { + propDefinition: [ + splunk, + "channel", + ], + }, + sourcetype: { + propDefinition: [ + splunk, + "sourcetype", + ], + }, + index: { + propDefinition: [ + splunk, + "index", + ], + }, + host: { + propDefinition: [ + splunk, + "host", + ], + }, + }, + async run({ $ }) { + const response = await this.splunk.sendEvent({ + $, + params: { + channel: this.channel, + }, + data: { + event: parseJson(this.eventData), + sourcetype: this.sourcetype, + index: this.index, + host: this.host, + }, + }); + $.export("$summary", "Successfully sent event to Splunk HTTP Event Collector"); + return response; + }, +}; diff --git a/components/splunk_http_event_collector/common/utils.mjs b/components/splunk_http_event_collector/common/utils.mjs new file mode 100644 index 0000000000000..9db43f123c0af --- /dev/null +++ b/components/splunk_http_event_collector/common/utils.mjs @@ -0,0 +1,32 @@ +function parseJson(obj) { + if (!obj) { + return undefined; + } + + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch { + return obj; + } + } + + if (Array.isArray(obj)) { + return obj.map((o) => { + if (typeof o === "string") { + try { + return JSON.parse(o); + } catch { + return o; + } + } + return o; + }); + } + + return obj; +} + +export { + parseJson, +}; diff --git a/components/splunk_http_event_collector/package.json b/components/splunk_http_event_collector/package.json index 05e9dd559fa26..4f285d0a96b0f 100644 --- a/components/splunk_http_event_collector/package.json +++ b/components/splunk_http_event_collector/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/splunk_http_event_collector", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Splunk HTTP Event Collector Components", "main": "splunk_http_event_collector.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/components/splunk_http_event_collector/splunk_http_event_collector.app.mjs b/components/splunk_http_event_collector/splunk_http_event_collector.app.mjs index 4f24a925ecbc5..fab97d78eaf20 100644 --- a/components/splunk_http_event_collector/splunk_http_event_collector.app.mjs +++ b/components/splunk_http_event_collector/splunk_http_event_collector.app.mjs @@ -1,11 +1,68 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "splunk_http_event_collector", - propDefinitions: {}, + propDefinitions: { + channel: { + type: "string", + label: "Channel", + description: "Channel GUID to differentiate data from different clients", + }, + sourcetype: { + type: "string", + label: "Sourcetype", + description: "The sourcetype of the event", + }, + index: { + type: "string", + label: "Index", + description: "The index to send the event to", + optional: true, + }, + host: { + type: "string", + label: "Host", + description: "The host sending the event", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `${this.$auth.api_url}:${this.$auth.port}`; + }, + _makeRequest({ + $ = this, + path, + ...otherOpts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + "Authorization": `Splunk ${this.$auth.api_token}`, + }, + ...otherOpts, + }); + }, + checkHealth(opts = {}) { + return this._makeRequest({ + path: "/services/collector/health", + ...opts, + }); + }, + sendEvent(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/services/collector", + ...opts, + }); + }, + sendMultipleEvents(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/services/collector/raw", + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 637e1ddfd0500..94a88437889fa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12097,7 +12097,11 @@ importers: components/splunk: {} - components/splunk_http_event_collector: {} + components/splunk_http_event_collector: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/splynx: dependencies: @@ -34346,6 +34350,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: