Skip to content

Instantly share code, notes, and snippets.

@sharmaansh21
sharmaansh21 / consul-iptables.py
Created January 2, 2020 14:12 — forked from smarnach/consul-iptables.py
Setting up netfilter rules to forward traffic targetted at a local port to a Consul service
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Run with
# sudo consul watch -type=service -service=redis ./consul-iptables.py
import json
import subprocess
import sys
def main():
@sharmaansh21
sharmaansh21 / glossary.md
Created August 23, 2019 05:47 — forked from g0t4/glossary.md
Consul and related terms
  • Node - a physical or virtual machine that hosts services
    • Nodes also referred to as members.
    • Examples
      • Your computer
      • An AWS EC2 instance
      • A bare metal machine in your private data center
  • Service - executing software that provides utility via an interface
    • Typically long-lived process listening on a port(s)
    • Examples
  • A web server (nginx, apache, iis)
@sharmaansh21
sharmaansh21 / Makefile
Created February 16, 2019 10:21 — forked from ryu1kn/Makefile
Encrypt/decrypt with AWS KMS using AWS cli
# How to encrypt/decrypt your text/blob secret with AWS KMS with AWS cli
KEY_ID=alias/my-key
SECRET_BLOB_PATH=fileb://my-secret-blob
SECRET_TEXT="my secret text"
ENCRYPTED_SECRET_AS_BLOB=encrypted_secret_blob
DECRYPTED_SECRET_AS_BLOB=decrypted_secret_blob # Result of decrypt-blob target
encrypt-text:
/*
The code below shows how to encrypt and then decrypt some plaintext into a cyphertext using
KMS's Encrypt/Decrypt functions and secretbox (https://godoc.org/golang.org/x/crypto/nacl/secretbox).
The plaintext message is sealed into a secretbox using a key that is generated by kmsClient.GenerateDataKey().
Note that this procedure reuquires that a master key would *already exist in KMS* and that its arn/alias is specified.
The aws library assumes that the proper credentials can be found in the shared file (~/.aws/credentials)
and opts for the 'default' role.
Once sealed, the cyphertext is then unboxed, again by first getting the key from kms (kmsClient.Decrypt),
@sharmaansh21
sharmaansh21 / gist:0a44efd348e78fa958c460c8eafb33ef
Created October 14, 2017 08:14 — forked from be-hase/gist:e97aea92abfd7749ca09
elasticsearchのindex削除用のcron script

elasticsearchのindexを定期的にcronを使用して削除するscript。

indexにTTLを設定すればいいじゃないかという指摘もありそうですが、
公式ブログに大量のログを保存するときは、TTL設定しているとオーバーヘッドが大きいと書いてあったので、
cronで消すようにします。
http://www.elasticsearch.org/tutorials/using-elasticsearch-for-logs/

Curatorを使えばこういったことも楽にできそうではあるが、
わざわざそのためにPythonをいじるのもアレなので、簡単にシェルスクリプトで書いてみました。

@sharmaansh21
sharmaansh21 / setup-ldap-client.sh
Created October 9, 2017 07:16 — forked from shichao-an/setup-ldap-client.sh
Setup OpenLDAP client server with SSH access
#!/bin/bash
# vim: softtabstop=4 shiftwidth=4 expandtab fenc=utf-8 spell spelllang=en cc=120
set -e
# Check Ubuntu release
[ "$(lsb_release -sc)" = "trusty" ] || {
echo 'This script should be run on Ubuntu 14.04.' >&2
exit 1
}
@sharmaansh21
sharmaansh21 / ha_drbd.md
Created September 16, 2017 06:57 — forked from irvingpop/ha_drbd.md
Cloning a Chef Server 12 installation

Customer Scenario

A customer has a Chef Server 12 (HA - DRBD) in Production. They want to test an in-place upgrade (or maintenance) using their current OPC Production data and config. This gives us a good chance to make corrections if we find that their data is too broken for the migrations to handle, and gives the customer experience in managing the upgrade in Production.

The sequence of events will broadly be these:

  • Install the same version of Chef Server on the target HA Test cluster
  • Restore data from Production instance backup (LVM snapshot or full-stop backup)
  • Test
@sharmaansh21
sharmaansh21 / vagrant_centos_multi.rb
Created September 14, 2017 05:01 — forked from ashrithr/vagrant_centos_multi.rb
vagrant multi machine centos
# -*- mode: ruby -*-
# vi: set ft=ruby :
boxes = [
{
name: "server1.local",
eth1: "192.168.0.101",
mem: 1024,
cpu: 1
},
@sharmaansh21
sharmaansh21 / cf_create_or_update.py
Created August 28, 2017 15:43 — forked from svrist/cf_create_or_update.py
Update or create a CloudFormation stack given a name and template + params'
'Update or create a stack given a name and template + params'
from __future__ import division, print_function, unicode_literals
from datetime import datetime
import logging
import json
import sys
import boto3
import botocore
@sharmaansh21
sharmaansh21 / alb_logs.sql
Created August 16, 2017 10:13 — forked from szinck/alb_logs.sql
Athena Table for ALB Logs
-- This creates an athena table that can parse ALB logs.
-- Advantage of this over others are this works when the log ends with a trailing space
-- plus it also breaks the http request into route and params for easier grouping
CREATE EXTERNAL TABLE IF NOT EXISTS alb_logs (
type string,
timestamp string,
elb string,
client_ip string,
client_port int,