Skip to content

Commit 5f6158f

Browse files
authored
Merge pull request #3084 from hpe-dev-incubator/cms/blog/integrating-hpe-greenlake-webhooks-with-splunk
Create Blog “integrating-hpe-greenlake-webhooks-with-splunk”
2 parents 67f6da5 + 9397808 commit 5f6158f

5 files changed

+387
-0
lines changed
Lines changed: 387 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,387 @@
1+
---
2+
title: "Integrating HPE GreenLake webhooks with Splunk "
3+
date: 2025-06-24T11:34:04.977Z
4+
author: Vandewilly Silva
5+
authorimage: https://ca.slack-edge.com/E01LD9FH0JZ-U05UA6N7KH6-6b8619b87acd-512
6+
disable: false
7+
tags:
8+
- hpe_greenlake_cloud
9+
- webhooks
10+
---
11+
<style>
12+
li {
13+
font-size: 27px;
14+
line-height: 33px;
15+
max-width: none;
16+
}
17+
</style>
18+
19+
## Overview
20+
21+
This guide shows you how to connect HPE GreenLake webhooks with [Splunk](https://www.splunk.com/). Splunk is a data platform that collects, indexes, and analyzes machine-generated data to provide insights for various purposes, including security monitoring, IT operations, and business analytics. When the two are connected, you will be able to see your HPE GreenLake events through Splunk for improved data monitoring and analysis.
22+
23+
## What you’ll learn
24+
25+
* How to set up Splunk to receive data from HPE GreenLake
26+
* How to handle HPE GreenLake's security requirements
27+
* How to build a helper app that makes everything work together
28+
* How to test and monitor your setup
29+
30+
## Overview of Splunk HTTP Event Collector (HEC)
31+
32+
The [HTTP Event Collector (HEC)](https://dev.splunk.com/enterprise/docs/devtools/httpeventcollector/) is a Splunk feature that lets you send data and application events to a Splunk deployment over the HTTP and Secure HTTP (HTTPS) protocols. HEC uses a token-based authentication model. You can generate a token and then configure a logging library or HTTP client with the token to send data to HEC in a specific format.
33+
34+
### Key features of HEC
35+
36+
* Token-based authentication: Each token has a unique value, which is a 128-bit number that is represented as a 32-character globally unique identifier (GUID)
37+
* Secure communication: Supports both HTTP and HTTPS protocols for data transmission
38+
* API key support: Provides secure authentication mechanisms that align perfectly with HPE GreenLake's security requirements
39+
* Flexible data formats: Accepts both JSON-formatted events and raw text data
40+
41+
## Overview of HPE GreenLake webhooks
42+
43+
[HPE GreenLake webhooks](https://developer.greenlake.hpe.com/docs/greenlake/services/event/public/webhooks/) facilitate automated, real-time communication between HPE GreenLake cloud services and an external service of your choosing. For example, a webhook could notify your IT Operation Management platform when a new audit log is created, or when subscriptions are about to expire. A getting started guide to HPE GreenLake webhooks is available [here](https://developer.hpe.com/blog/getting-started-with-the-hpe-greenlake-cloud-eventing-framework/).
44+
45+
### HPE GreenLake webhook security features:
46+
47+
HPE GreenLake implements robust security measures to ensure webhook authenticity:
48+
49+
* Challenge Request Validation: After registering a webhook, a verification challenge is sent to the destination (the webhook URL). The event type is `hpe.greenlake.events.v1beta1.webhooks.verification`. The challenge request includes a unique, random string generated by the server that is sent in the body as a payload.
50+
* HMAC SHA-256 Signature Verification: HPE GreenLake webhooks use a verification challenge process to ensure that webhook connections are legitimate and secure. HPE GreenLake secures webhook notifications through HMAC (Hash-based Message Authentication Code) with SHA-256, a cryptographic hashing algorithm.
51+
* Shared Secret Management: The platform supports dual secret rotation for zero-downtime security updates.
52+
53+
Challenge Request Example:
54+
55+
```json
56+
{
57+
"specversion" : "1.0",
58+
"type" : "hpe.greenlake.events.v1beta1.webhooks.verification",
59+
"source" : "//global.api.greenlake.hpe.com/events",
60+
"id" : "C234-1234-1234",
61+
"time" : "2018-04-05T17:31:00Z",
62+
"datacontenttype" : "application/json",
63+
"data" : {
64+
"challengeRequest" : "<TOKEN>"
65+
}
66+
}
67+
```
68+
69+
## Challenges and solutions
70+
71+
The primary challenge in integrating HPE GreenLake webhooks with Splunk HEC lies in the webhook verification process. The destination must read the value from the challengeRequest field and create an HMAC SHA-256 hash, using the webhook secret as salt and the challengeRequest value as a string to hash. When successful, the destination responds with a JSON object with the format `{"verification": "CREATED_HASH"}` and a HTTP 200 OK status.
72+
73+
### A challenge
74+
75+
Splunk's HEC endpoint is designed for data ingestion and doesn't natively support the  challenge-response mechanism required by HPE GreenLake webhooks. HEC expects to receive event data directly and cannot handle the initial verification handshake.
76+
77+
### The solution
78+
79+
This is where [Splunk's custom REST endpoints](https://dev.splunk.com/enterprise/docs/devtools/customrestendpoints/) capability becomes invaluable. A custom REST endpoint is a developer-defined endpoint and associated handler that lets you build out the Splunk REST API to meet your specific needs. We can create a custom endpoint handler that:
80+
81+
1. Intercepts the initial challenge request from HPE GreenLake
82+
2. Validates the challenge using HMAC SHA-256
83+
3. Responds appropriately to complete the verification
84+
4. Forwards validated event data to HEC for ingestion
85+
86+
## Custom REST endpoints in Splunk
87+
88+
Splunk's custom REST endpoints provide powerful extensibility for scenarios exactly like ours. You use a custom endpoint to add a special feature that Splunk doesn't have built-in, like, in our case, handling the unique secret handshake from HPE GreenLake.
89+
90+
Key benefits of our integration:
91+
92+
* Flexible request handling: Can process both challenge requests and event data
93+
* Custom logic implementation: Handler code implements HPE GreenLake's specific validation requirements
94+
* Centralized management: Provides a single endpoint for webhook management
95+
96+
## Where to configure the endpoint handler: Splunk Enterprise vs Splunk Cloud
97+
98+
Splunk Enterprise is the self-hosted version that an organization deploys and manages on its own infrastructure, either on-premises (on-prem) or in a private cloud.
99+
100+
Splunk Cloud Platform is the Software as a Service (SaaS) offering, where the Splunk platform is hosted, managed, and maintained by Splunk.
101+
102+
### For Splunk Enterprise
103+
104+
You can install and configure the endpoint handler directly on your Splunk Enterprise instance by placing it in the etc/apps/ directory and following the steps in this guide. Splunk Enterprise supports custom REST endpoints out of the box.
105+
106+
### For Splunk Cloud
107+
108+
[Splunk Cloud has extra security controls](https://docs.splunk.com/Documentation/SplunkCloud/latest/RESTTUT/RESTandCloud), so you might need to take additional steps to allow your helper to communicate with the Splunk REST API.
109+
110+
## Generate an Splunk REST API key
111+
112+
In order to use the custom REST endpoint in Splunk, you need to get an API key which HPE GreenLake will use to authenticate against Splunk when initially setting up the webhook and sending events. You can use the following cURL command to generate a key.
113+
114+
```shell
115+
curl -k https://your-splunk-instance:8089/services/auth/login \
116+
--data-urlencode username=YOUR_USERNAME \
117+
--data-urlencode 'password=YOUR_PASSWORD’
118+
```
119+
120+
The response will be:
121+
122+
```json
123+
<response>
124+
<sessionKey>YOUR_SESSION_KEY</sessionKey>
125+
<messages>
126+
<msg code=""></msg>
127+
</messages>
128+
</response>
129+
```
130+
131+
## Sample Python handler
132+
133+
Let's create a custom REST endpoint handler in Python to handle the HPE GreenLake webhook validation and forwards events to Splunk HEC, once validated.
134+
135+
### Directory structure
136+
137+
```markdown
138+
splunk_hpe_webhook_app/
139+
├── bin/
140+
│   └── hpe_webhook_handler.py
141+
├── default/
142+
│   ├── restmap.conf
143+
│   └── web.conf
144+
└── metadata/
145+
└── default.meta
146+
```
147+
148+
### Python handler (bin/hpe_webhook_handler.py)
149+
150+
```python
151+
import os
152+
import sys
153+
import json
154+
import hmac
155+
import hashlib
156+
import urllib.request
157+
import urllib.parse
158+
from splunk.rest import BaseRestHandler
159+
class HPEWebhookHandler(BaseRestHandler):
160+
def __init__(self, command_line, command_arg):
161+
super(HPEWebhookHandler, self).__init__(command_line, command_arg)
162+
# Configure your HEC endpoint and token
163+
self.hec_url = "<https://your-splunk-instance:8088/services/collector/event>"
164+
self.hec_token = "YOUR_HEC_TOKEN_HERE"
165+
self.webhook_secret = "YOUR_WEBHOOK_SECRET_HERE"
166+
def handle_POST(self):
167+
"""Handle POST requests from HPE GreenLake webhooks"""
168+
try:
169+
# Parse the incoming request body
170+
request_body = json.loads(self.request['payload'])
171+
event_type = request_body.get('type', '')
172+
# Check if this is a verification challenge
173+
if event_type == 'hpe.greenlake.events.v1beta1.webhooks.verification':
174+
return self._handle_challenge(request_body)
175+
else:
176+
# Validate signature for regular events
177+
if self._validate_signature():
178+
return self._forward_to_hec(request_body)
179+
else:
180+
return self._return_error("Invalid signature", 401)
181+
except Exception as e:
182+
return self._return_error(f"Error processing request: {str(e)}", 500)
183+
def _handle_challenge(self, request_body):
184+
"""Handle HPE GreenLake webhook verification challenge"""
185+
try:
186+
# Extract challenge request token
187+
challenge_request = request_body['data']['challengeRequest']
188+
# Create HMAC SHA-256 hash
189+
hmac_hash = hmac.new(
190+
key=self.webhook_secret.encode('utf-8'),
191+
msg=challenge_request.encode('utf-8'),
192+
digestmod=hashlib.sha256
193+
)
194+
# Create verification response
195+
verification_response = {
196+
"verification": hmac_hash.hexdigest()
197+
}
198+
# Return successful verification
199+
self.response.setHeader('content-type', 'application/json')
200+
self.response.write(json.dumps(verification_response))
201+
return
202+
except Exception as e:
203+
return self._return_error(f"Challenge validation failed: {str(e)}", 400)
204+
def _validate_signature(self):
205+
"""Validate HMAC signature for regular webhook events"""
206+
try:
207+
# Get signature from headers
208+
signature_header = self.request.get('headers', {}).get('hpe-webhook-signature', '')
209+
if not signature_header.startswith('sha256='):
210+
return False
211+
expected_signature = signature_header[7:] # Remove 'sha256=' prefix
212+
# Calculate expected signature
213+
payload = self.request['payload']
214+
calculated_signature = hmac.new(
215+
key=self.webhook_secret.encode('utf-8'),
216+
msg=payload.encode('utf-8'),
217+
digestmod=hashlib.sha256
218+
).hexdigest()
219+
# Compare signatures
220+
return hmac.compare_digest(expected_signature, calculated_signature)
221+
except Exception:
222+
return False
223+
def _forward_to_hec(self, event_data):
224+
"""Forward validated event data to Splunk HEC"""
225+
try:
226+
# Prepare HEC request
227+
hec_data = {
228+
"event": event_data,
229+
"sourcetype": "hpe:greenlake:webhook",
230+
"source": "hpe_greenlake",
231+
"index": "main" # Configure as needed
232+
}
233+
# Create HTTP request to HEC
234+
req = urllib.request.Request(
235+
url=self.hec_url,
236+
data=json.dumps(hec_data).encode('utf-8'),
237+
headers={
238+
'Authorization': f'Splunk {self.hec_token}',
239+
'Content-Type': 'application/json'
240+
}
241+
)
242+
# Send to HEC
243+
with urllib.request.urlopen(req) as response:
244+
if response.status == 200:
245+
self.response.setHeader('content-type', 'application/json')
246+
self.response.write(json.dumps({"status": "success"}))
247+
return
248+
else:
249+
return self._return_error("Failed to forward to HEC", 500)
250+
except Exception as e:
251+
return self._return_error(f"HEC forwarding failed: {str(e)}", 500)
252+
def _return_error(self, message, status_code):
253+
"""Return error response"""
254+
self.response.setStatus(status_code)
255+
self.response.setHeader('content-type', 'application/json')
256+
self.response.write(json.dumps({"error": message}))
257+
```
258+
259+
### Configuration files
260+
261+
#### default/restmap.conf
262+
263+
```markdown
264+
[script:hpe_webhook_handler]
265+
match = /hpe/webhook
266+
script = hpe_webhook_handler.py
267+
scripttype = persist
268+
handler = hpe_webhook_handler.HPEWebhookHandler
269+
requireAuthentication = false
270+
output_modes = json
271+
passPayload = true
272+
passHttpHeaders = true
273+
passHttpCookies = false
274+
```
275+
276+
#### default/web.conf
277+
278+
```markdown
279+
[expose:hpe_webhook_handler]
280+
pattern = hpe/webhook
281+
methods = POST`
282+
```
283+
284+
#### metadata/default.meta
285+
286+
```markdown
287+
[restmap/hpe_webhook_handler]
288+
export = system
289+
[views]
290+
export = system`
291+
```
292+
293+
## Configuring Splunk HTTP Event Collector (HEC)
294+
295+
You need to create an API token to use HEC via its API. You can do this from:
296+
297+
1.    **Settings > Data Inputs > HTTP Event Collector**
298+
299+
2.    Select **New token.** Use this token to update the Python handler script line
300+
301+
![Data inputs settings ](/img/dccf7431-b83b-4799-a795-25bccc7637db.png "Data inputs settings ")
302+
303+
Your final configuration should look like this:
304+
305+
![HEC final configuration ](/img/03af2f59-ab50-443b-ae93-90d274738317.png "HEC final configuration ")
306+
307+
Verify your global settings so that they match the following:
308+
309+
![Global settings](/img/310bb0be-5363-428a-99a2-5f64bef2ca8a.png "Global settings")
310+
311+
This allows you to get your HEC endpoint, which is used in the Python handler to create an incident based on the HPE GreenLake event received via the webhook. The URL of the endpoint should look like this:
312+
313+
`<https://<splunk-host>>:8088/services/collector/event`
314+
315+
## Final integration flow
316+
317+
The complete integration flow works as follows:
318+
319+
1. Initial setup
320+
321+
* Deploy the custom Splunk endpoint handler using the above HPE webhook handler Python script.
322+
* Make sure to set the HEC endpoint in the Python script (line 13)
323+
* Make sure to set the Splunk HEC API token in the Python script (line 14)
324+
* Make sure to set the HPE GreenLake webhook secret in the Python script (line 15)
325+
* Register the webhook handler URL with HPE GreenLake:
326+
327+
* URL of handler: [`https://your-splunk-instance:8089/servicesNS/-/your_app/hpe/webhook`](https://your-splunk-instance:8089/servicesNS/-/your_app/hpe/webhook)
328+
* Set the same secret key as we setup in the Python handler (line 15)
329+
* Use API as Authentication type and set the API key to the Splunk REST API Key generated in the section above.
330+
331+
> Note: See [this blog](https://developer.hpe.com/blog/getting-started-with-the-hpe-greenlake-cloud-eventing-framework/) to learn how to register a new webhook handler in HPE GreenLake
332+
333+
2. Webhook handler verification process
334+
335+
* HPE GreenLake sends a verification challenge to your custom endpoint.
336+
* The custom REST handler receives the challenge and validates it using HMAC SHA-256.
337+
* The handler responds with the computed verification hash.
338+
* HPE GreenLake confirms the webhook and marks it as active.
339+
340+
3. Event processing flow
341+
342+
* HPE GreenLake sends event data to the custom handler endpoint.
343+
* The custom REST handler validates the HMAC signature.
344+
* The handler forwards validated events to HEC.
345+
* Splunk HEC ingests the data for analysis and visualization.
346+
347+
4. Data flow diagram
348+
349+
![Data flow diagram](/img/diagram.jpg "Data flow diagram")
350+
351+
## Benefits of this architecture
352+
353+
Security: The custom endpoint handler ensures only validated, authentic events reach your Splunk environment.
354+
355+
Reliability: If there are more than 20 failures in a 12-hour period, the webhook enters the critical state in HPE GreenLake. If there are no new failures in 12 hours, the webhook returns to the active state. The custom handler can implement robust error handling to maintain webhook health.
356+
357+
Scalability: The solution can handle multiple webhook types and route them to different HEC endpoints or indexes as needed.
358+
359+
Monitoring: All webhook interactions are logged within Splunk for troubleshooting and monitoring.
360+
361+
## Testing and deployment
362+
363+
Testing the integration
364+
365+
1. Verify custom endpoint: Test your custom REST endpoint using curl:
366+
367+
```shell
368+
`curl -X POST`[`https://your-splunk-instance:8089/servicesNS/-/your_app/hpe/webhook`](https://your-splunk-instance:8089/servicesNS/-/your_app/hpe/webhook)`\`
369+
`-H "Content-Type: application/json" \`
370+
`-d '{"type": "test.event", "data": {"message": "Hello Splunk"}}'`
371+
```
372+
373+
2. Webhook registration: Register your webhook with HPE GreenLake using the custom endpoint URL.
374+
3. Challenge validation: Monitor Splunk logs to ensure the challenge request is handled correctly.
375+
4. Event flow testing: Trigger test events from HPE GreenLake and verify they appear in your Splunk index.
376+
377+
## Conclusion
378+
379+
Integrating HPE GreenLake webhooks with Splunk via HTTP Event Collector presents unique challenges due to the webhook verification requirements, but Splunk's custom REST endpoints capabilities provide an elegant solution. Such integration offers several key benefits:
380+
381+
Enhanced security: The custom REST endpoint handler ensures that only validated, authentic events from HPE GreenLake reach your Splunk environment, maintaining the security standards required by both platforms.
382+
383+
Seamless event flow: Once configured, events flow automatically from HPE GreenLake to Splunk, enabling real-time monitoring and analysis of your cloud infrastructure.
384+
385+
Extensible architecture: The custom REST handler can be extended to support multiple webhook types, different routing logic, and additional validation mechanisms as your requirements evolve.
386+
387+
Whether you're monitoring subscription changes, or audit events, this integration ensures that your HPE GreenLake data becomes a valuable part of your Splunk analytics ecosystem, empowering your organization with comprehensive, real-time insights into your cloud infrastructure.
32.3 KB
Loading
22.3 KB
Loading
125 KB
Loading

static/img/diagram.jpg

23.6 KB
Loading

0 commit comments

Comments
 (0)