Skip to content

Instantly share code, notes, and snippets.

@pmuellr
Last active January 14, 2020 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmuellr/29042ba4fd58f8e4c088d3b0a703da2e to your computer and use it in GitHub Desktop.
Save pmuellr/29042ba4fd58f8e4c088d3b0a703da2e to your computer and use it in GitHub Desktop.
whole-lotta-alerts stress tester for Kibana alerting using heartbeat data
#!/usr/bin/env bash
# creates a number of alerts with a server-log action
# Note that default alerttype - example.heartbeat is from
# https://github.com/pmuellr/kbn-sample-plugins#exampleheartbeat
# requires the following:
# jq: https://stedolan.github.io/jq/download/
# kbn-action: https://github.com/pmuellr/kbn-action/blob/master/README.md
# es-hb-sim: https://github.com/pmuellr/es-hb-sim
# es-hb-sim can be used to write "heartbeat" documents that example.heartbeat will process,
# and allows you to dynamically change the up/down state via keyboard presses.
# run with:
# es-hb-sim 1 whole-lotta-hb host-A https://elastic:changeme@localhost:9200
# to delete the all the alerts and actions, use the following, presumably when you're done:
# kbn-action ls | jq -r '.data | .[] | .id' | xargs -L 1 kbn-action delete
# kbn-alert ls | jq -r '.data | .[] | .id' | xargs -L 1 kbn-alert delete
# you can set the Kibana URL via env var like:
# export KBN_URLBASE=https://elastic:changeme@localhost:5601
# overridable params via env vars
ALERTS=${ALERTS:-100}
ALERT_TYPE=${ALERT_TYPE:-example.heartbeat}
ALERT_INTERVAL=${ALERT_INTERVAL:-1s}
HB_INDEX_NAME=${HB_INDEX_NAME:-whole-lotta-hb}
HB_WINDOW=${HB_WINDOW:-0.16}
# note the 0.16 above means the heartbeat "window" is 10 seconds, which works well for
# es-hb-sim running on a 1 second interval.
# use the date in the action/alert descriptions
DATE=`date`
# create a new server-log action (writes a line to the Kibana log)
ACTION_ID=`kbn-action create .server-log "server-log $DATE" '{}' '{}' | jq -r '.id'`
# note that we create each alert in the background, because they take too long
# to create serially
for (( i=1; i<=$ALERTS; i++ ))
do
kbn-alert create \
$ALERT_TYPE \
"$ALERT_TYPE-$i" \
$ALERT_INTERVAL \
"{index:'${HB_INDEX_NAME}', window:${HB_WINDOW}}" \
"[ \
{group:up id:'${ACTION_ID}' params:{message: '{{context.startedAt}} alert {{context.name}} up'}} \
{group:down id:'${ACTION_ID}' params:{message: '{{context.startedAt}} alert {{context.name}} down'}} \
{group:flapping id:'${ACTION_ID}' params:{message: '{{context.startedAt}} alert {{context.name}} flapping'}} \
{group:noData id:'${ACTION_ID}' params:{message: '{{context.startedAt}} alert {{context.name}} noData'}} \
]" \
&
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment