|
| 1 | +# Azure Functions for Sending Event Hub data to a Splunk HTTP Event Collector |
| 2 | +Events arriving on an Azure Event Hub can trigger serverless Azure Functions. Azure Functions can further process the raw events in near real-time. |
| 3 | + |
| 4 | +<a href="https://portal.azure.com/#blade/Microsoft_Azure_CreateUIDef/CustomDeploymentBlade/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fsplunk%2Fazure-functions-splunk%2Fevent-hubs%2Fevent-hubs-hec%2Fdeploy%2FazureDeploy.json/createUIDefinitionUri/https%3A%2F%2Fraw.githubusercontent.com%2Fsplunk%2Fazure-functions-splunk%2Fevent-hubs%2Fevent-hubs-hec%2Fdeploy%2FazureDeploy.portal.json" target="_blank"> |
| 5 | +<img src="https://aka.ms/deploytoazurebutton"/> |
| 6 | +</a> |
| 7 | + |
| 8 | +This repository contains a collection of Azure Functions for: |
| 9 | +* Processing events as they arrive on an Event Hub |
| 10 | +* Separating batched events (events in a `records[]` array) into individual events |
| 11 | +* Formatting events in the `event` format for a Splunk HTTP Event Collector |
| 12 | +* Sending event data to Splunk via [HTTP Event Collector](https://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector) |
| 13 | +* Writing event data to a Storage Blob if data cannot successfully be sent to Splunk |
| 14 | + * The [Splunk Add-on for Microsoft Cloud Services](https://splunkbase.splunk.com/app/3110/) can be utilized to retrieve Storage Blob data |
| 15 | + |
| 16 | +## Getting Started |
| 17 | + |
| 18 | +### 1. Create an HTTP Event Collector token in your Spunk Environment |
| 19 | +An HTTP Event Collector receives data pushed from the Azure Functions. Refer to the Splunk documentation for [setting up an HTTP Event Collector input](https://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector) in your Splunk Enterprise or Splunk Cloud environment. |
| 20 | + |
| 21 | +### 2. Create an Event Hub Namespace |
| 22 | +An Event Hub Namespace will contain one or more Event Hubs. Refer to the Microsoft documentation for [Event Hub Namespace setup instructions](https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-create). |
| 23 | + |
| 24 | +### 3. Send data to an Event Hub |
| 25 | +Microsoft Azure uses [diagnostics settings](https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/diagnostic-settings) to define data export and destination rules. Each resource to be monitored must have a diagnostic setting. Diagnostic settings can be defined using the Azure portal, PowerShell, [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/monitor/diagnostic-settings?view=azure-cli-latest), [Resource Manager templates](https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/resource-manager-diagnostic-settings), REST API, or an Azure Policy. |
| 26 | + |
| 27 | +* [Sending Azure Activity log data to an Event Hub using the Azure Portal walkthrough](docs/activity_log_diagnostic_settings.md) |
| 28 | +* [Sending Azure Diagnostic logs and metrics to an Event Hub](https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/diagnostic-settings) |
| 29 | +* [Sending Azure Active Directory logs to an Event Hub](docs/azure_ad_diagnostic_settings.md) |
| 30 | +* Sending Azure Virtual Machine data to an Event Hub |
| 31 | + * [Windows VMs](https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-windows) |
| 32 | + * [Linux VMs](https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-linux) |
| 33 | + |
| 34 | + |
| 35 | +### 4. Deploy the functions to Azure |
| 36 | + |
| 37 | +Use the "Deploy to Azure" button above to deploy the Azure Functions from this repo to your Azure account. During setup, you will be prompted for the following information: |
| 38 | + |
| 39 | +* Event Hub Namespace |
| 40 | +* Event Hub consumer group for each hub monitored |
| 41 | +* Splunk sourcetype or sourcetype base for each hub monitored |
| 42 | + * Note: see section below about sourcetypes |
| 43 | +* Splunk [HTTP Event Collector](https://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector) Endpoint |
| 44 | +* Splunk [HTTP Event Collector](https://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector) Token |
| 45 | + |
| 46 | +## Splunk Sourcetypes |
| 47 | +### Azure Active Directory Sourcetypes |
| 48 | +Functions that collect Azure Active Directory data use a sourcetype base. The category of the Azure Active Directory event is appended to the sourcetype base to construct the full sourcetype. |
| 49 | + |
| 50 | +**Example** |
| 51 | + |
| 52 | +The default sourcetype base for Azure Active Directory Sign-in and Audit events is `azure:aad` |
| 53 | + |
| 54 | +A sign-in event with a category of `SignInLogs` will have a sourcetype of `azure:aad:signinlogs` |
| 55 | + |
| 56 | +An audit event with a category of `AuditLogs` will have a sourcetype of `azure:aad:auditlogs` |
| 57 | + |
| 58 | +### Diagnostic Logs |
| 59 | +Functions that collect diagnostic log data attempt to construct a sourcetype based on the `resourceId` of the event. The logic for this sourcetype construction can be found in the `getSourceType` function in the [./helpers/splunk.js file](helpers/splunk.js). The following steps are used to construct the sourcetype: |
| 60 | + |
| 61 | +* A regular expression is used to extract two groups after the text `/PROVIDERS` |
| 62 | + * Example `/PROVIDERS/`**`MICROSOFT.RESOURCES/DEPLOYMENTS/`** |
| 63 | +* Periods (`.`) and forward slashes (`/`) are replaced with colons (`:`) |
| 64 | +* The event category is appended |
| 65 | + |
| 66 | +**Example** |
| 67 | + |
| 68 | +An event with a `resourceId` of `/SUBSCRIPTIONS/subscription ID/RESOURCEGROUPS/group/PROVIDERS/MICROSOFT.RESOURCES/DEPLOYMENTS/FAILURE-ANOMALIES-ALERT-RULE-DEPLOYMENT-12345678` will have a sourcetype of `azure:resources:deployments:administrative` |
| 69 | + |
| 70 | +If a sourcetype cannot be constructed from the event, the specified default sourcetype entered at setup will be used. |
| 71 | + |
| 72 | + |
| 73 | +## Securing Azure Function settings |
| 74 | +Microsoft stores the above values as [application settings](https://docs.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings#settings). These settings are stored encrypted, but you may opt to transfer one or more of these settings to a Key Vault. Refer to the following documentation for details on this procedure: |
| 75 | + |
| 76 | +* [Use Key Vault references for App Service and Azure Functions](https://docs.microsoft.com/en-us/azure/app-service/app-service-key-vault-references) |
| 77 | + |
| 78 | + |
| 79 | +## Support |
| 80 | +This software is released as-is. Splunk provides no warranty and no support on this software. If you have any issues with the software, please file an issue on the repository. |
0 commit comments