Skip to content

Instantly share code, notes, and snippets.

View keymon's full-sized avatar

Hector Rivas Gandara keymon

  • London, UK
  • 08:52 (UTC +01:00)
View GitHub Profile
@keymon
keymon / trigger-alert.sh
Created November 23, 2018 17:01
Trigger a fake alert in alertmanager
#!/bin/bash
name="a-terrible-thing-$RANDOM"
url='http://localhost:9093/api/v1/alerts'
echo "firing up alert $name"
curl -XPOST $url -d @- <<EOF
[{
"labels": {
@keymon
keymon / gorouter-panic.log
Created August 13, 2018 17:04
Gorouter panic
[2018-08-13 14:46:48+0000] fatal error: sync: Unlock of unlocked RWMutex
[2018-08-13 14:46:48+0000]
[2018-08-13 14:46:48+0000] goroutine 68250842 [running]:
[2018-08-13 14:46:48+0000] runtime.throw(0xa72d45, 0x20)
[2018-08-13 14:46:48+0000] /var/vcap/data/packages/golang-1.9-linux/88a7626f51143d021545ce3f6ac2a6ed44766aed/src/runtime/panic.go:605 +0x95 fp=0xc4221274b8 sp=0xc422127498 pc=0x42d615
[2018-08-13 14:46:48+0000] sync.throw(0xa72d45, 0x20)
[2018-08-13 14:46:48+0000] /var/vcap/data/packages/golang-1.9-linux/88a7626f51143d021545ce3f6ac2a6ed44766aed/src/runtime/panic.go:594 +0x35 fp=0xc4221274d8 sp=0xc4221274b8 pc=0x42d575
[2018-08-13 14:46:48+0000] sync.(*RWMutex).Unlock(0xc420d9d590)
[2018-08-13 14:46:48+0000] /var/vcap/data/packages/golang-1.9-linux/88a7626f51143d021545ce3f6ac2a6ed44766aed/src/sync/rwmutex.go:125 +0xa1 fp=0xc422127508 sp=0xc4221274d8 pc=0x475131
[2018-08-13 14:46:48+0000] code.cloudfoundry.org/gorouter/route.(*RoundRobin).Next(0xc42034f260, 0xc420d9d590)
@keymon
keymon / test.go
Last active June 7, 2018 11:01
Send metrics to loggregator
export GOPATH=/root/go
export GOROOT=/usr/local/go/
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
cd /root
cat > test.go # Copy file above
# Remount /tmp rw
mount -o remount,exec /tmp
@keymon
keymon / spec_job_properties.rb
Last active March 2, 2018 10:58
This scripts gets a bosh job spec, a bosh manifest, and prints the properties that are declared in the spec and defined in the manifest.
#!/usr/bin/env ruby
#
# This scripts gets a bosh job spec, a bosh manifest, and prints the properties that are declared in the spec and defined in the manifest.
#
# Usage:
# spec_job_properties.rb ~/workspace/uaa-release/jobs/uaa/spec cf-manifest.yml
#
require 'yaml'
class PropertyTree
@keymon
keymon / tide2crunch.rb
Created December 17, 2017 19:04
Converts tide.co.uk CSV statements to crunch CSV statements
#!/usr/bin/env ruby
# Crunch requires a special date format, the balance and a filtered description.
#
# ./tide2crunch.rb < tide.csv > crunch.csv
#
# There is a thread requesting the balance in the CSV here[1]
# https://www.tide.co/community/t/balance-on-csv/1732/7
require "csv"
# Extract the hash of entries
@keymon
keymon / Dockerfile
Last active July 13, 2017 16:46
Configure the terraform backend in S3, with dynamodb db lock, and run terraform.
FROM python:3-alpine
ENV TERRAFORM_VERSION=0.9.8
RUN apk add --no-cache --update ca-certificates openssl curl && \
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/bin/ && \
rm -f terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
pip install awscli
@keymon
keymon / echo_server.go
Created June 13, 2017 16:21
Small echo server for testing purposes. Simply prints the HTTP request info
//
// Small echo server for testing purposes. Simply prints the request.
// Usage:
// - To create certs:
// openssl req -subj '/CN=company.com/O=SomeCompany./C=DB' \
// -new -newkey rsa:2049 -days 365 -nodes -x509 \
// -keyout server.key -out server.crt
// - To start:
// HTTP_PORTS=8080,8081 HTTPS_PORTS=8443,12345 \
// HTTPS_SERVER_CERT_CRT_FILE=$(pwd)/server.crt \
2017/05/19 17:36:44 [INFO] Terraform version: 0.9.5 a59ee0b30e1350d18e44a3a2a405124302751f93
2017/05/19 17:36:44 [INFO] Go runtime version: go1.8
2017/05/19 17:36:44 [INFO] CLI args: []string{"/home/keymon/local/terraform-0.9.5/terraform", "apply", "-var-file", "spurious.json"}
2017/05/19 17:36:44 [DEBUG] Detected home directory from env var: /home/keymon
2017/05/19 17:36:44 [DEBUG] Detected home directory from env var: /home/keymon
2017/05/19 17:36:44 [DEBUG] Attempting to open CLI config file: /home/keymon/.terraformrc
2017/05/19 17:36:44 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2017/05/19 17:36:44 [DEBUG] Detected home directory from env var: /home/keymon
2017/05/19 17:36:44 [INFO] CLI command args: []string{"apply", "-var-file", "spurious.json"}
2017/05/19 17:36:44 [DEBUG] command: loading backend config file: /home/keymon/workspace/tf_json_bug
@keymon
keymon / prepare-commit-msg.sh
Created May 5, 2017 10:09
prepare-commit-msg to add a suffix with the ticket number
#!/bin/sh
ORIG_MSG_FILE="$1"
TICKETNO="$(git rev-parse --abbrev-ref HEAD | sed 's/.*\(PLAT-[0-9]*\).*/\1/')"
if [ -n "${TICKETNO}" ]; then
grep -q "${TICKETNO}" "${ORIG_MSG_FILE}" && exit
TEMP="$(mktemp /tmp/git-XXXXX)"
(cat "$ORIG_MSG_FILE"; echo; echo "$TICKETNO";) > "$TEMP"
cat "$TEMP" > "$ORIG_MSG_FILE"
rm "${TEMP}"
@keymon
keymon / aws_cleanup_component.sh
Created March 31, 2017 15:26
Delete cloud formation and services running in ECS based on a component name
# Deletes a cloudformation stack
clean_up_cloudformation() {
component_name="$1"
aws cloudformation delete-stack \
--region eu-west-1 \
--stack-name "${component_name}"
}
# Checks if the given cloudformation stack is deleted
check_cloudformation(){
component_name="$1"