Skip to content

Instantly share code, notes, and snippets.

View manuthu's full-sized avatar

Mike manuthu

View GitHub Profile
@manuthu
manuthu / cloudstack-routers-running-in-a-storagepool.sh
Last active April 15, 2020 15:38
A script to get all the running routers in a given storage pool in XEN.
# Get all running routers. Routers in cloudstack are prefixed with `r-DIGIT`
RUNNING_VMS=$(xe vm-list | grep -A2 -B2 'r-[0-9]' | grep uuid | awk -F':' '{print $2}')
SRID=8c269040-fc42-c12d-b091-8958784ec65e
for vm_id in $RUNNING_VMS
do
xe vbd-list vm-uuid=$vm_id | grep vdi-uuid | awk -F':' '{print $2}' | xargs -I {} xe vdi-list uuid={} | grep $SRID && echo $vm_id
done
@manuthu
manuthu / install-postgres-10-ubuntu.md
Created June 6, 2019 12:42 — forked from alistairewj/install-postgres-10-ubuntu.md
Install PostgreSQL 10 on Ubuntu

Install PostgreSQL 10 on Ubuntu

This is a quick guide to install PostgreSQL 10 - tested on Ubuntu 16.04 but likely can be used for Ubuntu 14.04 and 17.04 as well, with one minor modification detailed below.

(Optional) Uninstall other versions of postgres

To make life simple, remove all other versions of Postgres. Obviously not required, but again, makes life simple.

dpkg -l | grep postgres
@manuthu
manuthu / ipblock.py
Created December 4, 2018 16:03
IP Block with signal handling
#!/opt/venv/ipblock/env/bin/python
__author__ = 'Mike Manuthu <[email protected]>'
"""
A simple script to disable the number of connections to the server.
Uses IPTables to block the IPS with more than the threshold connections.
Uses Fail2Ban as the default IP Blocker.
usage: IP Blocker :: [-h] [-i IP] [-I IPRANGE] [-c CONNECTIONS] [-B]
[-f FREQUENCY]
@manuthu
manuthu / blockips.py
Last active April 2, 2018 12:34
Block IP with a connection to the server on Port 80, 443, 22. If there are more than specified connections, use iptables drop the connections.
#!/root/env/bin/python
import argparse
import iptc
import logging
import time
from bash import bash
from ipwhois import IPWhois
import logging
import json
from flask import Flask, current_app, jsonify
from flask import request
logging.basicConfig(level=logging.DEBUG)
app = Flask(__name__)
@manuthu
manuthu / gist:daa278db35ba7ab25e8dbbe68208b060
Created December 21, 2017 17:53 — forked from mbirtwell/gist:aaccdb7972e1a7ed094b
SQLAlchemy Enum recipe enhanced for use in postgresql arrays
# Based on http://techspot.zzzeek.org/2011/01/14/the-enum-recipe/
import six
from sqlalchemy.dialects import postgresql
from sqlalchemy.types import SchemaType, TypeDecorator, Enum
from sqlalchemy import __version__, text, cast
import re
if __version__ < '0.6.5':
raise NotImplementedError("Version 0.6.5 or higher of SQLAlchemy is required.")
@manuthu
manuthu / get-ip-address.md
Last active October 2, 2017 18:54
libvirt fetch IP address from a domain

View running domains

~ virsh list --all
 Id    Name                           State
----------------------------------------------------
 15    compute.local                  running
 16    storage.local                  running
@manuthu
manuthu / vagrant-ssh-configurations.sh
Created August 17, 2017 11:44
vagrant ssh configurations
~: vagrant ssh-config
Host webserver1
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/Mike/projects/sandbox/haproxylab/.vagrant/machines/webserver1/virtualbox/private_key
IdentitiesOnly yes
@manuthu
manuthu / ssl_server.py
Last active January 26, 2018 09:43
Simple Python SSL Server
"""
Generate a server.key and server.cert.
>> mike:tmp$ openssl req -nodes -new -x509 -keyout server.key -out server.cert
Combine the generated keys.
>> mike:tmp$ cat server.key server.cert > server.pem
Now run the script