Skip to content

Instantly share code, notes, and snippets.

View adimania's full-sized avatar

Aditya Patawari adimania

View GitHub Profile
@adimania
adimania / logtailer.py
Last active December 14, 2015 06:59
A simple tailer to send the data to remote machine using UDP. It was originally written to ship logs to logstash but it can be used to ship any text anywhere.
#!/usr/bin/python
from time import sleep
import socket
log=open("somefile.log","r")
log.readlines()
pos=log.tell() # This is the last line of the file
while True:
line=log.readline()
@adimania
adimania / image-uploader.rb
Created March 2, 2013 10:43
Simple ruby script to upload and view images.
require 'rubygems'
require 'sinatra'
get '/' do
"uploader up"
end
post '/image' do
puts params.inspect
File.open("upload-dir/#{params[:id]}", "w") do |f|
@adimania
adimania / 100users.sh
Created March 4, 2013 18:39
Script to create hundreds of users in one go.
#!/bin/bash
echo This script requires super user permissions. Press \'y\' if you are running as super user.
read ch
count=$1
if [ $ch = "y" ] || [ $ch = "Y" ]
then
echo in if now
while [ $count -ne 0 ]
@adimania
adimania / repo.sh
Created March 4, 2013 18:40
This script will create a local Fedora mirror via Rsync
#!/bin/sh
rsync="rsync -avrt"
mirror=mirrors.kernel.org::mirrors/fedora
verlist="13 14"
archlist="i386"
baselist="os"
local=/var/www/fedrepo
@adimania
adimania / check_elb.py
Created March 5, 2013 10:54
Nagios check for checking the number of "InService" instances in Amazon EC2 Elastic Load Balancer and alerting if it crosses threshold.
#!/usr/bin/env python
import boto.ec2.elb
import ConfigParser
import os.path
import sys
from optparse import OptionParser
check = os.path.isfile(os.path.expanduser('~/.aws.conf'))
if cmp(check,False) == 0:
@adimania
adimania / izanami.py
Created November 6, 2014 17:53
Script to block annoying IPs
import socket
import subprocess
import random
import string
BAD_THRESHOLD = 5 # If there are more than these failed attempt then IP will be blocked
iptables_str = "/sbin/iptables -I INPUT -s IP-HERE -j DROP\n"
identifier = ''.join(random.choice(string.lowercase) for i in range(6))
script = open("/tmp/iptables.sh-" + identifier,"w")
@adimania
adimania / facts_db.py
Created December 9, 2014 06:39
Flask + SQLAlchemy for pyfacts
# get this from https://gist.github.com/adimania/96960173f906c9830e22
import json
import datetime
from flask import Flask, request
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////home/app/inventory.db'
db = SQLAlchemy(app)
base_uri = '/inv/v1'
@adimania
adimania / bw_nagios_average.py
Created December 19, 2014 13:05
Nagios Bandwidth Check
import subprocess
import time
import json
import re
import pynsca
import sys
from pynsca import NSCANotifier
'''
We need to alert on 30 Mbps. ifconfig returns bytes.
@adimania
adimania / dockerfiles_test.sh
Last active September 10, 2015 03:06
Testing Fedora-Dockerfiles package
#!/bin/bash
# You can change the url below if you are going to test a fork.
git clone https://github.com/fedora-cloud/Fedora-Dockerfiles.git
cd Fedora-Dockerfiles
# if you are running against a particular branch then uncomment the line below and write the branch name.
# git checkout <branch_name>
mkdir logs
dfiles_dir=$(pwd)
@adimania
adimania / nginx-flask-rc.yml
Created September 6, 2015 17:26
Kubernetes replication controller demo
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx-flask-controller
spec:
replicas: 2
selector:
app: nginx-flask-pod
template:
metadata: