Skip to content

Instantly share code, notes, and snippets.

View hartfordfive's full-sized avatar

Alain Lefebvre hartfordfive

View GitHub Profile
@hartfordfive
hartfordfive / pre-receive-puppet
Last active October 2, 2020 16:33
Server-side pre-receive hook to validate puppet files.
#!/bin/bash
COMMAND='puppet parser validate'
TEMPDIR=`mktemp -d`
echo "### Attempting to validate puppet files... ####"
# See https://www.kernel.org/pub/software/scm/git/docs/githooks.html#pre-receive
oldrev=$1
newrev=$2
@hartfordfive
hartfordfive / gce-disk-throughput.py
Last active August 29, 2015 14:04
Test GCE disk throughput
#!/usr/bin/python
''' Used to troubleshoot Google Compute Engine slow disk throughput '''
''' Adjust block device readahead to optimize throughput via '''
''' $ blockdev [/dev/sda] --setra $((1024*1024*8)) '''
import sys
import os
import datetime
@hartfordfive
hartfordfive / azure-ssh.py
Last active August 29, 2015 14:11
Simple python wrapper to connect to Azure VM via SSH
#!/usr/bin/python
import sys, subprocess, json, os
if __name__ == "__main__":
key_path='[PATH_TO_PRIVATE_KEY]'
proc = subprocess.Popen("azure vm list --json", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@hartfordfive
hartfordfive / aws-ssh.py
Last active December 21, 2018 12:48
Sample python script to SSH into EC2 instances by hostname tag
#!/usr/bin/env python
import sys, subprocess, json, os
from pprint import pprint
if __name__ == "__main__":
if 'AWS_SSH_KEY_FILE' in os.environ:
key_path = os.environ['AWS_SSH_KEY_FILE']
else:
@hartfordfive
hartfordfive / create_cert_databag.sh
Last active August 29, 2015 14:13
Create un-encrypted data bag file to be used with chef certificate_manage cookbook
if [ "$1" == "" ] || [ "$2" == "" ] || [ "$3" == "" ]; then
echo ""
echo "Usage: ./create_cert_databag.sh [DATABAG_NAME] [SSL_CERT] [SSL_KEY [SSL_CA_CHAIN]]"
echo ""
exit 1
fi
DATABAG_NAME=$1
SSL_CERT=$2
@hartfordfive
hartfordfive / pre-commit
Created March 4, 2015 16:13
Git pre-commit hook to validate Chef JSON environment files
#!/bin/bash
# Comments:
# 1. You must add execution rights to this file (chmod u+x pre-commit)
# 2. You need to have the 'jq' package installed to parse the json
echo -e "\n#### Validating chef environment files ####"
if git-rev-parse --verify HEAD >/dev/null 2>&1; then
@hartfordfive
hartfordfive / compare_json.py
Last active August 29, 2015 14:16
Comparing two JSON files
#!/usr/bin/python
import sys,json,hashlib
try:
with open(sys.argv[1], 'r') as content_file_orig:
content_original = content_file_orig.read()
json_orig = json.loads(content_original)
except Exception, e:
print "Error loading JSON file {0}! Please check it's validity.".format(sys.argv[1])
@hartfordfive
hartfordfive / lsfw-open-files.sh
Created April 2, 2015 19:54
Get list of files open by logstash-forwarder
#!/bin/bash
OUTPUT=`lsof -X -c logstash- | egrep -v '\.logstash-forwarder' | egrep -E '[0-9]+r\s+REG' | awk '{print $9}'`
case "$1" in
'json')
FILES=`printf ",\"%s\"" \${OUTPUT[@]}`
echo "{\"open_files\": [${FILES:1:${#FILES}-1}]}"
;;
*)
for F in "$OUTPUT"
@hartfordfive
hartfordfive / open-files.sh
Created April 2, 2015 19:55
Get list of open files for a given user
#!/bin/bash
OUTPUT=`lsof -X -c $1 | egrep -v '\.logstash-forwarder' | egrep -E '[0-9]+r\s+REG' | awk '{print $9}'`
case "$2" in
'json')
FILES=`printf ",\"%s\"" \${OUTPUT[@]}`
echo "{\"open_files\": [${FILES:1:${#FILES}-1}]}"
;;
*)
for F in "$OUTPUT"
@hartfordfive
hartfordfive / cloudtrail-pull
Created April 10, 2015 14:07
Script to pull AWS CloudTrail logs and output them to a json file
#!/bin/bash
if [[ "$1" == "" || "$2" == "" || "$3" == "" || "$4" == "" ]]; then
echo "Usage: pull-cloudtrail [CONFIG] [BUCKET_NAME] [ACCOUNT_NUMBER] [REGION]"
exit 1
fi
YEAR=`date +%Y`
MONTH=`date +%m`
DAY=`date +%d`