Skip to content

Instantly share code, notes, and snippets.

View DavidWittman's full-sized avatar

David Wittman DavidWittman

View GitHub Profile
@DavidWittman
DavidWittman / nova_nuke.py
Last active December 24, 2015 16:49
Nova Nuke: Forcefully removes an instance from the Nova database. Useful for cleaning up instances stuck in an 'error' or 'deleting' state.
#!/usr/bin/env python
#
# nova_nuke.py
# usage: nova_nuke.py <uuid>
#
# Forcefully removes an instance from the Nova database.
# Useful for destroying instances stuck in an 'error' or 'deleting' state.
#
# Completes the following actions:
Vagrant.configure("2") do |config|
config.vm.box = "dummy"
config.vm.synced_folder './vagrant', '/vagrant'
config.ssh.private_key_path = File.expand_path("~/.ssh/id_rsa")
ENV['VAGRANT_DEFAULT_PROVIDER'] = "rackspace"
config.vm.provider :rackspace do |rs, override|
override.vm.box = 'dummy'
override.vm.box_url = 'https://github.com/mitchellh/vagrant-rackspace/raw/master/dummy.box'
@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!"
@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

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

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:

@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 / 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 / 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 / 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