Skip to content

Instantly share code, notes, and snippets.

View shcallaway's full-sized avatar
😉
Building Opkit

Sherwood Callaway shcallaway

😉
Building Opkit
View GitHub Profile
@shcallaway
shcallaway / README.md
Last active October 25, 2023 19:15
Datadog reserved log attributes

Datadog's reserved log attributes are confusing as heck. It's not clear what each attribute does, so you can’t predict or understand what will happen when you create a mapping. Allow me to demonstrate.

I got this logline from my Datadog S3 archive bucket. It gives you a sense of what logs look like after going through Datadog's opaque transformations.

{
    "_id": "AW5Hc8y8FxIBf2udiA1a", // Log ID generated by Datadog
    "attributes": { // Key-values from the original JSON logline are moved under "attributes"
        "@timestamp": "2019-11-07T19:59:59.804Z",
        "@version": "1",
@shcallaway
shcallaway / README.md
Created October 7, 2019 23:51
View paginated, colorized JSON in your terminal with jq and less

You can view paginated, colorized JSON in your terminal by piping JSON to jq -C and less -R:

curl https://jsonplaceholder.typicode.com/posts | jq -C | less -R
@shcallaway
shcallaway / setup.sh
Last active June 11, 2021 16:19
Set up a new MacBook with "curl -L dev.sherwoodcallaway.com | sh"
#!/bin/sh
set -e
# =============================
# ========= Homebrew ==========
# =============================
echo "Running Homebrew..."
@shcallaway
shcallaway / count-trace-id.sh
Created October 1, 2019 20:32
Count the number of log lines that contain a field "trace_id"
#!/bin/bash
TOTAL=$(cat $1 | wc -l)
TOTAL_W_TRACE_ID=$(cat input.csv | awk 'BEGIN { FS = "," } ; { print $5 }' | grep . | wc -l)
echo "Total: $TOTAL"
echo "Total with trace_id: $TOTAL_W_TRACE_ID"
echo "To calculate a percentage, plug these numbers into something that can do floating point arithmetic."
@shcallaway
shcallaway / list-k8s-resources.sh
Created September 24, 2019 23:32
List all resource and subresource types available in a Kubernetes cluster
#!/bin/sh
# Source: https://medium.com/@tannhauser.sphinx/bash-kubernetes-script-to-list-all-available-resources-subresources-c65a5c2c1173
_list=($(kubectl get --raw / |grep "^ \"/api"|sed 's/[",]//g'));
for _api in ${_list[@]}; do
_aruyo=$(kubectl get --raw ${_api} | jq .resources);
if [ "x${_aruyo}" != "xnull" ]; then
echo;
echo "===${_api}===";
@shcallaway
shcallaway / README.md
Created August 29, 2019 20:26
Print a list of Helm releases w/ their statuses

Print a list of Helm releases w/ their statuses. This command references the ConfigMaps directly -- Helm's underlying storage mechanism -- which makes it good for debugging Helm state.

kubectl get cm -o json | jq '.items[] | select(.metadata.labels.OWNER=="TILLER") | .metadata.labels.NAME + " - " + .metadata.labels.STATUS'
@shcallaway
shcallaway / README.md
Created August 28, 2019 17:55
Re-run migration jobs in Kubernetes

If you have some migration jobs in Kubernetes, you can re-run them with this one-liner:

kubectl get jobs | grep migrations | awk '{print $1}' | xargs -I {} sh -c "kubectl get job {} -o json | jq 'del(.spec.selector)' | jq 'del(.spec.template.metadata.labels)' | kubectl replace --force -f -"

Based on this Stack Overflow answer.

@shcallaway
shcallaway / check-loadbalancers.sh
Created August 10, 2019 00:39
Check for any public Kubernetes LoadBalancers on AWS
#!/bin/bash
echo "Kubernetes Context: $1"
echo "-- LOADBALANCERS --"
LOADBALANCERS=`kubectl get svc --context $1 | grep LoadBalancer | awk '{print $1}'`
for LOADBALANCER in $LOADBALANCERS; do
echo $LOADBALANCER
PRIVATE=`kubectl get svc --context $1 $LOADBALANCER -o jsonpath='{.metadata.annotations.service\.beta\.kubernetes\.io\/aws-load-balancer-internal}'`
@shcallaway
shcallaway / README.md
Last active July 29, 2019 22:18
Provide cross-account access to an S3 bucket

It's somewhat confusing to provide S3 access to an IAM role from another AWS account. The thing to remember is this: you need to provide access from both sides. In other words, you need to set the bucket resource policy and attach a regular IAM policy to the role.

It's kind of like how, when you want to go to your friend's house, you need permission from both moms. :)

See "Resource-based policies and IAM policies".

@shcallaway
shcallaway / README.md
Created July 29, 2019 19:56
List Kubernetes pod IP addresses
kubectl get po -o json | jq '.items[] | select(.metadata.name | test("my-pod")) | .status.podIP'