Skip to content

Instantly share code, notes, and snippets.

View DavidWittman's full-sized avatar

David Wittman DavidWittman

View GitHub Profile
@DavidWittman
DavidWittman / elasticsearch_primary_shards_per_node.md
Last active March 19, 2017 04:19
One-liner to list the number of primary shards per data node in Elasticsearch

List the number of primary shards per data node in Elasticsearch:

curl -s localhost:9200/_cat/shards?h=node,prirep | awk '
$2 == "p" { 
  result[$1] += 1; total += 1
}
END {
  for (var in result)
 printf "%s\t%s (%0.2f%%)\n",var,result[var],result[var]/total*100
@DavidWittman
DavidWittman / when-will-my-lenovo-arrive.sh
Last active March 21, 2017 22:13
Scrape the Lenovo order details page and print the estimated arrival date.
#!/usr/bin/env bash
# When will my Lenovo order arrive?
#
# I grew impatient while waiting for my Thinkpad to ship, and the arrival date
# kept changing, so I wrote this script to scrape their order details page.
#
# Might not work on all platforms, and it's parsing HTML with sed, so there be
# plenty of dragons within this script.
@DavidWittman
DavidWittman / s3cmdcrypt.sh
Last active April 18, 2016 20:41
s3cmd helper script to prompt for GPG passphrase for encrypting/decrypting
#!/usr/bin/env bash
# s3cmd helper script to prompt for GPG passphrase for encrypting/decrypting
S3CMD_CONFIG=${S3CMD_CONFIG:-"$HOME/.s3cfg"}
S3CMD="$(which s3cmd)"
if [[ -z "$GPG_PASSPHRASE" ]]; then
# Add the -s flag here to hide the passphrase
read -r -p "Encryption passphrase: " GPG_PASSPHRASE
@DavidWittman
DavidWittman / audit_iam_accounts.py
Created April 14, 2016 22:34
Parses the output from AWS credential reports and displays users which have been inactive for 60+ days.
#!/usr/bin/env python
# Parses the output from AWS credential reports and displays
# users which have been inactive for 60+ days.
#
# Usage:
# audit_iam_accounts.py credential_report.csv <days>
#
import csv
@DavidWittman
DavidWittman / ansible-dynamic-inventory-converter.py
Created April 12, 2016 22:42
Script for converting Ansible dynamic inventory to static files. It's not perfect, but it'll get you 90% of the way there.
#!/usr/bin/env python
# Converts Ansible dynamic inventory sources to static files
# Input is received via stdin from the dynamic inventory file
# ex:
# ec2.py --list | ansible-dynamic-inventory-converter.py
import json
import os
import sys

Keybase proof

I hereby claim:

  • I am DavidWittman on github.
  • I am daveops (https://keybase.io/daveops) on keybase.
  • I have a public key whose fingerprint is 7DA6 052D DCB6 ADA4 00A7 EFDF FF43 3B38 9A3F DB4B

To claim this, I am signing this object:

Piping data from Mongostat to Elasticsearch with Logstash

Requirements

  • Logstash 1.5.x
    • If you want to run Logstash 2.x, see the section titled Logstash 2.x below
  • Mongostat 2.8+ (for support of the --json flag)

Preparation

@DavidWittman
DavidWittman / example.out
Created February 1, 2016 18:35
Auto add and remove NAT rules for OpenVZ containers
[root@iadesapp0 ~]# iptables -t nat -vnL | grep 51008
[root@iadesapp0 ~]# vzctl start 1007
Starting container...
Warning: configuration file for distribution OR-centos-6.4-x86_64 not found, using defaults from /etc/vz/dists/default
Adding NAT rules for ports 31008,41008,51008,61008
VZ mount is iadesapp0vz7
mount: special device /data/iadesapp0vz7 does not exist
Container is mounted
/etc/vz/conf/vps.mount: line 36: /etc/vz/conf/vps-set-io.sh: No such file or directory
Adding IP address(es): 10.57.152.45
@DavidWittman
DavidWittman / merge-s3-parts.sh
Created December 23, 2015 16:47
Script to merge .part files from Amazon S3
#!/usr/bin/env bash
if [[ $# -ne 1 ]]; then
echo "Merge matching *.part files in a directory"
echo
echo "usage: $0 <directory>"
exit 1
fi
DIRECTORY="$1"
@DavidWittman
DavidWittman / hipchat-to-slack.go
Created July 9, 2015 03:17
Relay for posting messages from a HipChat room into a Slack room
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"