Power Outage Data in Splunk

To get power outage data into Splunk, run a small Python poller every 15 minutes that reads county outage counts from the PowerOutage.us v2 REST API and sends one event per county to the HTTP Event Collector (HEC). Each event carries the county id, customers out, customers tracked and the minutes since the utility last reported, stamped with the time of the snapshot, so stats, timechart and scheduled alerts work on it like any other source type. HEC works the same way on Splunk Cloud Platform and Splunk Enterprise, and nothing has to be installed inside Splunk.

What you'll have

  • One event per county per run in a poweroutage index, with customersOut, customersTracked, the FIPS code and minutesSinceUpdate.
  • SPL searches for the counties with the most customers out right now and for a state's outage curve over the last day.
  • A scheduled alert that fires once per county when it passes 5,000 customers out, throttled by countyId.
  • The same setup on Splunk Cloud Platform and Splunk Enterprise: no add-on, app vetting or scripted input.

What you need

An API key (request one with the form below) and these endpoints. Full details are in the API reference.

EndpointMethodUsed forPackage
/outages/countiesGETCounty customersOut, customersTracked, lastUpdatedAt and FIPS codes for the states you watch, sent to HEC as one event per county.Core

Step 1: Create an index and an HEC token

Creating indexes and HEC tokens needs the admin role on Splunk Enterprise or sc_admin on Splunk Cloud Platform. Create an events index named poweroutage under Settings > Indexes > New Index. Then go to Settings > Add Data > Monitor > HTTP Event Collector, name the token, leave indexer acknowledgment off, choose New for the source type and enter poweroutage:county, and allow only the poweroutage index. HEC is on by default on Splunk Cloud Platform; on Splunk Enterprise also open Settings > Data Inputs > HTTP Event Collector > Global Settings and set All Tokens to Enabled. Copy the token value, and note your HEC URL, which depends on where Splunk runs. The poller's host needs outbound HTTPS to poweroutage.us and to that URL.

text
Splunk Cloud Platform on AWS       https://http-inputs-<stack>.splunkcloud.com/services/collector/event
Splunk Cloud Platform on GCP/Azure https://http-inputs.<stack>.splunkcloud.com/services/collector/event
Splunk Enterprise                  https://<splunk-host>:8088/services/collector/event

Step 2: Write the poller

Save this as /opt/poweroutage/poweroutage_hec.py. It uses only the Python standard library (3.8 or later), sends the API key in an Authorization: Bearer header, and on a 429 waits the Retry-After seconds, three tries at most, without waiting after the last. Each county becomes one HEC event: id to countyId, name to county, stateId, fips.full to fips (null for the Unknown county), customersOut, customersTracked and lastUpdatedAt unchanged, plus minutesSinceUpdate, the gap between lastUpdatedAt and meta.generatedAt. The event time is meta.generatedAt, so all counties in a run share one _time. Events go to HEC in batches of 500, stacked one after another in the request body. Change STATE_IDS to the states you watch.

python
import json
import os
import time
import urllib.error
import urllib.request
from datetime import datetime

API_KEY = os.environ['POWEROUTAGE_API_KEY']
HEC_URL = os.environ['SPLUNK_HEC_URL']  # ends in /services/collector/event
HEC_TOKEN = os.environ['SPLUNK_HEC_TOKEN']
INDEX = os.environ.get('SPLUNK_INDEX', 'poweroutage')
# 44 is Florida and 45 is Georgia. List ids with GET /outages/states.
STATE_IDS = '44,45'


def call(url):
    """GET a PowerOutage.us endpoint, waiting out a 429 for as long as Retry-After says."""
    request = urllib.request.Request(url, headers={'Authorization': f'Bearer {API_KEY}'})
    for attempt in range(3):
        try:
            with urllib.request.urlopen(request, timeout=30) as response:
                return json.load(response)
        except urllib.error.HTTPError as err:
            if err.code != 429 or attempt == 2:
                raise
            time.sleep(int(err.headers.get('Retry-After', '10')))


def epoch(timestamp):
    # The API sends UTC timestamps such as 2026-12-03T17:13:59.980Z
    return datetime.fromisoformat(timestamp.replace('Z', '+00:00')).timestamp()


payload = call(f'https://poweroutage.us/api/v2/outages/counties?stateId={STATE_IDS}&include=fips')
generated_at = epoch(payload['meta']['generatedAt'])
events = []
for county in payload['data']:
    updated = county['lastUpdatedAt']
    events.append({
        'time': generated_at,  # every event in a run shares the snapshot time
        'source': 'poweroutage.us',
        'sourcetype': 'poweroutage:county',
        'index': INDEX,
        'event': {
            'countyId': county['id'],
            'county': county['name'],
            'stateId': county['stateId'],
            'fips': (county['fips'] or {}).get('full'),
            'customersOut': county['customersOut'],
            'customersTracked': county['customersTracked'],
            'lastUpdatedAt': updated,
            'minutesSinceUpdate': round((generated_at - epoch(updated)) / 60) if updated else None,
        },
    })

# HEC takes events stacked one after another; 500 per request stays far below its size limit.
for i in range(0, len(events), 500):
    request = urllib.request.Request(
        HEC_URL,
        data='\n'.join(json.dumps(event) for event in events[i : i + 500]).encode(),
        headers={'Authorization': f'Splunk {HEC_TOKEN}'},
    )
    with urllib.request.urlopen(request, timeout=30) as response:
        response.read()
print(f'Sent {len(events)} county events to Splunk')

Step 3: Run it every 15 minutes

Put the API key and the HEC token in an environment file that only the job's account can read, never in the script, and run the poller from that account's crontab. set -a exports every line of the file to the script, and the shell reads the file, so keep every value in single quotes, as shown. Every 15 minutes is enough for most uses. The data updates every minute, so for the latest numbers run it every 1 or 2 minutes (* * * * * or */2 * * * *), which indexes proportionally more data against your license. Check the log file after the first run: a 403 from HEC means a wrong token, and a 400 that mentions the index means the token is not allowed to write to it.

text
# /opt/poweroutage/splunk.env: owned by the account that runs the job, chmod 600.
# Put every value in single quotes, as below; write a single quote inside a value as '\''.
POWEROUTAGE_API_KEY='...'
SPLUNK_HEC_URL='https://http-inputs-<stack>.splunkcloud.com/services/collector/event'
SPLUNK_HEC_TOKEN='...'
SPLUNK_INDEX='poweroutage'

# crontab -e, as that account
*/15 * * * * set -a && . /opt/poweroutage/splunk.env && /usr/bin/python3 /opt/poweroutage/poweroutage_hec.py >> /opt/poweroutage/poweroutage_hec.log 2>&1

Step 4: Search the counts

Splunk extracts the JSON fields at search time, so they are ready in any search. Group by stateId and countyId, not by county, because county names repeat across states; within a single stateId, as in the timechart, names are unique. A large minutesSinceUpdate means the utility has stopped updating that county and the count may be stale.

spl
Counties with the most customers out in the latest snapshot:

index=poweroutage sourcetype="poweroutage:county" earliest=-30m
| stats latest(customersOut) AS customersOut latest(customersTracked) AS customersTracked
        latest(county) AS county latest(minutesSinceUpdate) AS minutesSinceUpdate BY stateId countyId
| eval pctOut = round(customersOut / customersTracked * 100, 2)
| sort - customersOut
| head 20

Georgia's ten worst counties over the last day:

index=poweroutage sourcetype="poweroutage:county" stateId=45 earliest=-24h
| timechart span=15m limit=10 useother=false max(customersOut) BY county

Step 5: Alert when a county passes 5,000 customers out

Run the search, then select Save As > Alert with these settings. Every 15 minutes it looks at the latest snapshot and returns each county at or above 5,000 customers out. Trigger For each result raises one alert per county, and the throttle on countyId keeps a county that stays dark from alerting again for 2 hours. Change the threshold, or filter on stateId, to suit your territory.

text
Search
  index=poweroutage sourcetype="poweroutage:county" earliest=-20m
  | stats latest(customersOut) AS customersOut latest(county) AS county BY stateId countyId
  | where customersOut >= 5000

Save As > Alert
  Alert type                Scheduled, Run on Cron Schedule, cron expression */15 * * * *
  Trigger alert when        Number of Results is greater than 0
  Trigger                   For each result
  Throttle                  checked
  Suppress results containing field value   countyId
  Suppress triggering for   2 hours
  Trigger Actions           Add to Triggered Alerts, plus email or any alert action you use

Tips for Splunk

  • Splunk Enterprise serves HEC with a self-signed certificate unless you replace it, and Python rejects that by default. Install a certificate from your own CA on HEC, or pass context=ssl.create_default_context(cafile=...) with your CA bundle to both urlopen calls that go to HEC.
  • Each event is about 200 bytes. Florida and Georgia come to roughly 4 MB of license usage a day; every US county, about 3,300 of them, is closer to 60 MB a day.
  • If your Splunk Cloud Platform stack limits which addresses can reach HEC, add the poller host's public address to that allow list.
  • Each state can include a county named Unknown for customers a utility could not place in a county. Its fips is null.
  • Use a separate API key for the poller, restricted to the states it reads, so other tools do not share its rate limit and a leaked key exposes less.

Used by

Related integrations

FAQ

Here are some commonly asked questions

Request API access

Tell us what you're building and we'll set you up with a trial key.