Skip to content

Instantly share code, notes, and snippets.

View DavidWittman's full-sized avatar

David Wittman DavidWittman

View GitHub Profile
@DavidWittman
DavidWittman / saltstack-devstack.md
Last active March 29, 2018 15:36
Automated DevStack deployments on Rackspace with salt-cloud

Automated DevStack deployments on Rackspace with salt-cloud

Preparation

Install salt-master and salt-cloud

These instructions will install salt-master and salt-cloud on recent Ubuntu releases. Consult the SaltStack Installation Documentation should you require instructions for other distributions.

echo deb http://ppa.launchpad.net/saltstack/salt/ubuntu `lsb_release -sc` main | sudo tee /etc/apt/sources.list.d/saltstack.list
@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 / 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 / stunnel-chroot-reload.md
Created March 25, 2015 03:28
Reloading stunnel configurations when in a chroot

Reloading stunnel configurations when in a chroot

Example stunnel config

# /etc/stunnel/stunnel.conf
cert = /etc/stunnel/cert.pem
sslVersion = TLSv1 TLSv1.1 TLSv1.2

chroot = /var/run/stunnel/
@DavidWittman
DavidWittman / hipchat-relay.go
Last active May 10, 2016 14:37
Room-to-room message relay for Hipchat, with support across accounts.
package main
import (
"flag"
"fmt"
"github.com/andybons/hipchat"
"log"
"os"
"path"
"strings"
@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

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 / 99-motd-segfaults
Last active December 31, 2015 02:29
I hope I never need this again.
#!/bin/bash
SECONDS_SINCE_LAST_SEGFAULT=$(( $(date '+%s') - $(date -d "$(fgrep segfault /var/log/syslog | tail -1 | awk '{ print $1,$2,$3 }')" '+%s') ))
echo "IT HAS BEEN"
echo -ne "\e[00;33m"
figlet -f big $SECONDS_SINCE_LAST_SEGFAULT
echo -ne "\e[00m"
echo "SECONDS SINCE THE LAST SEGFAULT!"