Skip to content

Instantly share code, notes, and snippets.

View saliceti's full-sized avatar
🐌

Colin Saliceti saliceti

🐌
  • Department for Education
View GitHub Profile
@saliceti
saliceti / val_from_yaml.rb
Last active October 1, 2015 15:50
Extract a value from a YAML file
#!/usr/bin/env ruby
require 'yaml'
filename = ARGV[0]
path = ARGV[1]
def get(hash, path_array)
unless path_array.empty?
get(hash[path_array[0]], path_array[1..-1])
require "net/http"
require "uri"
require "json"
def print_router_routes(name, ip)
uri = URI.parse("http://#{ip}:8080/routes")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
request.basic_auth("router_user", "router_password")
@saliceti
saliceti / SampleOutput.md
Last active November 19, 2015 16:16
Parse and compare manifests
$ ruby scripts/diff.rb scripts/v224.yml scripts/v225.yml 
compilation.cloud_properties.availability_zone: __stub__eu-west-1a != __stub__eu-west-1b

compilation.cloud_properties.instance_type.c3.large: only in 1

compilation.network: only in 2

jobs.consul_z1.networks.cf1.static_ips.10.0.10.39: only in 1
@saliceti
saliceti / pre-commit
Last active March 12, 2021 18:38
Git pre-commit hook to check for AWS keys
#!/usr/bin/env bash
# Install globally using https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook
# The checks are simple and can give false positives. Amend the hook in the specific repository.
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
@saliceti
saliceti / flow-logs.sh
Last active February 10, 2016 18:09
Capture TCP connections
#!/bin/bash
set -x
GATEWAY=52.48.251.177
TMP_DIR=/tmp/flow_log
VM_LIST_FILE=${TMP_DIR}/vm_list.txt
IPTABLES_INSTALL_OUTPUT="iptables -A OUTPUT -m state --state NEW -j LOG --log-prefix '[flow-logs-output] '"
IPTABLES_INSTALL_INPUT="iptables -A INPUT -m state --state NEW -j LOG --log-prefix '[flow-logs-input] '"
IPTABLES_REMOVE_OUTPUT="iptables -D OUTPUT -m state --state NEW -j LOG --log-prefix '[flow-logs-output] '"
IPTABLES_REMOVE_INPUT="iptables -D INPUT -m state --state NEW -j LOG --log-prefix '[flow-logs-input] '"
@saliceti
saliceti / process.sh
Created February 10, 2016 12:54
Flow log data workflow
#!/bin/bash
dirs=$@
base_dir=$(pwd)
rm -rf merged
mkdir merged
for dir in ${dirs}; do
echo Processing ${dir}...
#!/bin/sh
set -eu
NAME=$1
UAA_ENDPOINT=https://...
UAA_ADMIN_CLIENT_PASS=xxxxx
PASSWORD=test
echo "Creating user ${NAME}"
uaac --trace target "${UAA_ENDPOINT}"
@saliceti
saliceti / usage.rb
Last active September 23, 2016 15:56
CF usage
#!/usr/bin/env ruby
require 'json'
orgs = JSON.load(`cf curl /v2/organizations`)["resources"]
quotas = JSON.load(`cf curl /v2/quota_definitions`)["resources"]
orgs_reserved_memory = 0
apps_reserved_memory = 0
allocated_services = 0
require 'loggregator_emitter'
require 'net/http'
require 'json'
nats_ip = '10.0.16.11'
nats_monitor_port = 4333
metron_port = 3457
@http = Net::HTTP.new(nats_ip, nats_monitor_port)
@get_varz = Net::HTTP::Get.new('/varz')
@saliceti
saliceti / create-token-role.sh
Created January 5, 2017 16:48 — forked from keymon/create-token-role.sh
Get temporary credentials from AWS using a MFA token, also assuming role: you can assume a role ⁠⁠⁠⁠./create-token-role.sh elasticache-broker-spike-role⁠⁠⁠⁠ or create new tokens for yourself ⁠⁠⁠⁠./create-token-role.sh me 900⁠⁠⁠⁠
#!/bin/bash
SCRIPT_NAME="$0"
usage() {
cat <<EOF
Creates a set of tokens assuming the given role. Use "me" as role to simply generate a new session token for your user.
Usage:
$SCRIPT_NAME <role name> [duration in seconds]