|
| 1 | +# Splunk Plugin for Perses |
| 2 | + |
| 3 | +This plugin provides Splunk datasource and query support for [Perses](https://github.com/perses/perses). |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The Splunk plugin enables Perses to connect to Splunk instances and query data using Splunk Processing Language (SPL). It supports both time series visualizations and log queries. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Splunk Datasource**: Connect to Splunk Enterprise or Splunk Cloud instances |
| 12 | +- **Time Series Queries**: Execute SPL queries for time series data visualization |
| 13 | +- **Log Queries**: Retrieve and display log data from Splunk |
| 14 | +- **Variable Support**: Use Perses variables in your SPL queries |
| 15 | +- **Flexible Authentication**: Support for direct URL or proxy-based connections |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +This plugin is part of the Perses plugins repository. To use it: |
| 20 | + |
| 21 | +1. Build the plugin: |
| 22 | + |
| 23 | +```bash |
| 24 | +cd plugins/splunk |
| 25 | +npm install |
| 26 | +npm run build |
| 27 | +``` |
| 28 | + |
| 29 | +2. Configure Perses to load the plugin (see [Perses Plugin Documentation](https://perses.dev)) |
| 30 | + |
| 31 | +## Configuration |
| 32 | + |
| 33 | +### Datasource Configuration |
| 34 | + |
| 35 | +The Splunk datasource can be configured in two ways: |
| 36 | + |
| 37 | +#### Direct URL |
| 38 | + |
| 39 | +```yaml |
| 40 | +kind: Datasource |
| 41 | +metadata: |
| 42 | + name: my-splunk |
| 43 | +spec: |
| 44 | + plugin: |
| 45 | + kind: SplunkDatasource |
| 46 | + spec: |
| 47 | + directUrl: https://splunk.example.com:8089 |
| 48 | +``` |
| 49 | +
|
| 50 | +#### Proxy Configuration |
| 51 | +
|
| 52 | +```yaml |
| 53 | +kind: Datasource |
| 54 | +metadata: |
| 55 | + name: my-splunk |
| 56 | +spec: |
| 57 | + plugin: |
| 58 | + kind: SplunkDatasource |
| 59 | + spec: |
| 60 | + proxy: |
| 61 | + kind: HTTPProxy |
| 62 | + spec: |
| 63 | + url: https://splunk.example.com:8089 |
| 64 | + allowedEndpoints: |
| 65 | + - endpointPattern: /services/search/jobs |
| 66 | + method: POST |
| 67 | + - endpointPattern: /services/search/jobs/([a-zA-Z0-9_.-]+)/results |
| 68 | + method: GET |
| 69 | +``` |
| 70 | +
|
| 71 | +## Query Types |
| 72 | +
|
| 73 | +### Time Series Query |
| 74 | +
|
| 75 | +Use `SplunkTimeSeriesQuery` for visualizing metrics over time: |
| 76 | + |
| 77 | +```yaml |
| 78 | +kind: TimeSeriesQuery |
| 79 | +spec: |
| 80 | + plugin: |
| 81 | + kind: SplunkTimeSeriesQuery |
| 82 | + spec: |
| 83 | + query: 'search index=main | timechart count by host' |
| 84 | + datasource: |
| 85 | + kind: SplunkDatasource |
| 86 | + name: my-splunk |
| 87 | +``` |
| 88 | + |
| 89 | +### Log Query |
| 90 | + |
| 91 | +Use `SplunkLogQuery` for retrieving log data: |
| 92 | + |
| 93 | +```yaml |
| 94 | +kind: LogQuery |
| 95 | +spec: |
| 96 | + plugin: |
| 97 | + kind: SplunkLogQuery |
| 98 | + spec: |
| 99 | + query: 'search index=main error | head 1000' |
| 100 | + datasource: |
| 101 | + kind: SplunkDatasource |
| 102 | + name: my-splunk |
| 103 | + maxResults: 1000 |
| 104 | +``` |
| 105 | + |
| 106 | +## SPL Query Examples |
| 107 | + |
| 108 | +### Time Series Examples |
| 109 | + |
| 110 | +```spl |
| 111 | +# Count events over time |
| 112 | +search index=main | timechart count |
| 113 | +
|
| 114 | +# Average response time by service |
| 115 | +search index=web | timechart avg(response_time) by service |
| 116 | +
|
| 117 | +# Error rate over time |
| 118 | +search index=main error | timechart count |
| 119 | +``` |
| 120 | + |
| 121 | +### Log Query Examples |
| 122 | + |
| 123 | +```spl |
| 124 | +# Recent errors |
| 125 | +search index=main error | head 100 |
| 126 | +
|
| 127 | +# Specific application logs |
| 128 | +search index=app sourcetype=application:log level=ERROR |
| 129 | +
|
| 130 | +# Search with filters |
| 131 | +search index=main host=server01 status=500 |
| 132 | +``` |
| 133 | + |
| 134 | +## Development |
| 135 | + |
| 136 | +### Prerequisites |
| 137 | + |
| 138 | +- Node.js version 22 or greater |
| 139 | +- npm version 10 or greater |
| 140 | + |
| 141 | +### Running in Development Mode |
| 142 | + |
| 143 | +1. In the main Perses repository, enable dev mode in `config.yaml`: |
| 144 | + |
| 145 | +```yaml |
| 146 | +plugin: |
| 147 | + enable_dev: true |
| 148 | +``` |
| 149 | + |
| 150 | +2. Start the Perses backend: |
| 151 | + |
| 152 | +```bash |
| 153 | +./scripts/api_backend_dev.sh |
| 154 | +``` |
| 155 | + |
| 156 | +3. Login with percli: |
| 157 | + |
| 158 | +```bash |
| 159 | +percli login http://localhost:8080 |
| 160 | +``` |
| 161 | + |
| 162 | +4. Start the plugin development server: |
| 163 | + |
| 164 | +```bash |
| 165 | +percli plugin start /path/to/plugins/splunk |
| 166 | +``` |
| 167 | + |
| 168 | +## API Endpoints |
| 169 | + |
| 170 | +The plugin uses the following Splunk REST API endpoints: |
| 171 | + |
| 172 | +- `/services/search/jobs` - Create search jobs |
| 173 | +- `/services/search/jobs/{sid}` - Get job status |
| 174 | +- `/services/search/jobs/{sid}/results` - Get search results |
| 175 | +- `/services/search/jobs/{sid}/events` - Get search events |
| 176 | +- `/services/search/jobs/export` - Export search results |
| 177 | +- `/services/data/indexes` - Get index information |
| 178 | + |
| 179 | +## Authentication |
| 180 | + |
| 181 | +Splunk authentication can be configured through: |
| 182 | + |
| 183 | +- HTTP headers (Authorization token) |
| 184 | +- Proxy settings with credentials |
| 185 | +- Direct URL with embedded credentials (not recommended for production) |
| 186 | + |
| 187 | +Refer to the [Splunk REST API documentation](https://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTprolog) for more details on authentication methods. |
| 188 | + |
| 189 | +## License |
| 190 | + |
| 191 | +This plugin is licensed under the Apache License, Version 2.0. See the [LICENSE](../../LICENSE) file for details. |
| 192 | + |
| 193 | +## Contributing |
| 194 | + |
| 195 | +Contributions are welcome! Please refer to the main [Perses contributing guidelines](https://github.com/perses/perses/blob/main/CONTRIBUTING.md). |
| 196 | + |
| 197 | +## Support |
| 198 | + |
| 199 | +For issues and questions: |
| 200 | + |
| 201 | +- [Perses GitHub Issues](https://github.com/perses/perses/issues) |
| 202 | +- [Perses Documentation](https://perses.dev) |
0 commit comments