Instantly share code, notes, and snippets.

David Wittman DavidWittman

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

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 Mar 21, 2017
Scrape the Lenovo order details page and print the estimated arrival date.
View when-will-my-lenovo-arrive.sh
#!/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 Apr 18, 2016
s3cmd helper script to prompt for GPG passphrase for encrypting/decrypting
View s3cmdcrypt.sh
#!/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 Apr 14, 2016
Parses the output from AWS credential reports and displays users which have been inactive for 60+ days.
View audit_iam_accounts.py
#!/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 Apr 12, 2016
Script for converting Ansible dynamic inventory to static files. It's not perfect, but it'll get you 90% of the way there.
View ansible-dynamic-inventory-converter.py
#!/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
View keybase.md

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:

View 000-mongostat-to-elasticsearch.md

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 Feb 1, 2016
Auto add and remove NAT rules for OpenVZ containers
View example.out
[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 Dec 23, 2015
Script to merge .part files from Amazon S3
View merge-s3-parts.sh
#!/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 Jul 9, 2015
Relay for posting messages from a HipChat room into a Slack room
View hipchat-to-slack.go
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"