Skip to content

Instantly share code, notes, and snippets.

View rylnd's full-sized avatar

Ryland Herrick rylnd

View GitHub Profile
@rylnd
rylnd / derive_import_payload_from_package_rules.sh
Last active November 21, 2024 20:32
Rule Import Benchmarking, Mark II
#!/bin/bash
RULE_PATH="${1:-.}"
echo "Rule Path: $RULE_PATH"
IMPORT_FILE="${2:-rules.ndjson}"
echo "Import file: $IMPORT_FILE"
rule_count=0;
@rylnd
rylnd / sdh.sh
Created June 28, 2024 20:02
WIP script to update rules to use event.ingested instead of @timestamp
#!/bin/sh
#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
#
set -e
@rylnd
rylnd / example.http
Last active May 3, 2023 22:07
Aggregate over multiple types of documents, grouping by common fields
GET risk_score,watchlist/_search
{
"size": 0,
"aggs": {
"identities": {
"composite": {
"sources": [
{
"identityField": {
"terms": {
# for each identifier (example with user.name)
GET risk-score-demo/_search
{
"size": 0,
"query": {
"bool": {
"must": [
{
"match": {
"event.category": "risk"
@rylnd
rylnd / scoring_code.ts
Created December 16, 2022 20:41
Scoring Pseudocode
const RiskReasonLocation = '.alerts*' // configurable in future
const IdentifierMapping = [
{sourceField: 'host.name', entityField: 'host.name'},
{sourceField: 'user.name', entityField: 'user.name'},
]; // configurable in future
for (Identifier of IdentifierMapping) {
GET(`${RiskReasonLocation}/_search`, {
'event.type': 'risk_reason',
[Identifier.sourceField]: '*',
@rylnd
rylnd / demo.sh
Last active September 8, 2022 22:16
Reindex Worker Demo
## REINDEX DEMO
DELETE events-1
DELETE security-events-1
PUT events-1
{
"mappings": {
"properties": {
"@timestamp": {
@rylnd
rylnd / fix_affected_rule.sh
Last active July 8, 2022 17:23 — forked from spong/bulk_add_actions_to_all_rules.sh
Bulk Update Rules' API Keys
#!/usr/bin/env bash
KIBANA_URI="${KIBANA_URL:-"http://localhost:5601"}"
KIBANA_USR="${KIBANA_USER:-"elastic"}"
KIBANA_PWD="${KIBANA_PASS:-"changeme"}"
KIBANA_SPACE="${SPACE_ID:-""}"
if [ -n "$KIBANA_SPACE" ]; then
SPACE_PART="s/${KIBANA_SPACE}/"
fi
@rylnd
rylnd / example_request.ts
Last active August 6, 2020 19:30
Proposal: Using io-ts to validate request/response
type I = unknown;
type A = RequestOverWire // snake case, optionals
type O = RequestToUse // camelCase, all keys present, values defaulted
// frontend
const request: I = { id: 'my-id' };
const payload: A = requestSchema.decode(request);
if (isLeft(payload)) {
displayErrors(payload);
} else {
@rylnd
rylnd / instructions.sh
Created September 6, 2019 17:41
Slow repo test
# outside of a repo
git init test
cd test
time git status
for i in {1..40000}; do touch $i; done
time git status
git add .
git commit -m "adding files"
time git status
@rylnd
rylnd / b.rb
Last active February 9, 2019 01:31
Rails NameError
# a/b.rb
module A
module B
THING = 'thing'
end
end