Skip to content

Instantly share code, notes, and snippets.

View mzupan's full-sized avatar

Mike Zupan mzupan

View GitHub Profile
@mzupan
mzupan / fabfile.py
Created October 19, 2014 02:07
python decorator to time a fabric function
from fabric.api import env, run
import time
env.hosts = ['web01-east']
def logtime(method):
def timed(*args, **kw):
ts = time.time()
#!/usr/bin/env python
from termcolor import colored
import requests
import time
while True:
ltc = requests.get("https://btc-e.com/api/2/ltc_usd/ticker").json()
btc = requests.get("https://btc-e.com/api/2/btc_usd/ticker").json()
@mzupan
mzupan / check-spf.py
Last active September 1, 2016 16:10
SPF dns lookup nagios check
#!/usr/bin/env python
#
# usage: ./check-spf.py domain.com
#
# author: mike@zcentric.com
#
#
import sys
[root@photoblogcom named]# dig +trace test1.photoblog.com
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5_8.6 <<>> +trace test1.photoblog.com
;; global options: printcmd
. 44083 IN NS d.root-servers.net.
. 44083 IN NS e.root-servers.net.
. 44083 IN NS f.root-servers.net.
. 44083 IN NS g.root-servers.net.
. 44083 IN NS h.root-servers.net.
. 44083 IN NS i.root-servers.net.
from fabric.api import *
@task
@runs_once
def prod():
env.roledefs['app'] = ['web1.sc', 'web2.sc', 'web3.sc', 'web4.sc']
env.roledefs['lb'] = ['lb1.sc', 'lb2.sc']
env.roledefs['sql'] = ['mysql1.sc', 'mysql2.sc']
@task
@mzupan
mzupan / etc-default-uwsgi-graphite
Created March 20, 2013 19:26
graphite with nginx and uwsgi
PYTHONPATH=/opt/graphite/webapp/graphite
MODULE=graphite_uwsgi
# The following part is optional! It just compiles and installs the chosen
# global ruby version to help on bootstrapping. To achieve this, it uses
# "ruby-build" utility.
define rbenv::compile($user,$global_ruby="1.9.2-p290",$bundler_version='1.1.3') {
# STEP 1
exec { "checkout rbenv for ${user}":
command => "git clone git://github.com/sstephenson/rbenv.git .rbenv",
user => $user,
cwd => "/home/${user}",
@mzupan
mzupan / purge_mailq.py
Created June 20, 2012 16:44
Python script to purge select emails from postfix's mail queue
#!/usr/bin/env python
import sys
from subprocess import Popen, PIPE, STDOUT
try:
search = sys.argv[1]
except:
print "Need to enter a email or a part of an email"
@mzupan
mzupan / check_monit.py
Created June 11, 2012 17:46
Nagios check for monit services going unmonitored
#!/usr/bin/env python
import urllib2
import base64
import sys
import optparse
from xml.dom.minidom import parseString
def local_sed(filename, before, after, limit='', use_sudo=False, backup=''):
"""
Run a search-and-replace on ``filename`` with given regex patterns.
Equivalent to ``sed -i<backup> -r -e "/<limit>/ s/<before>/<after>/g
<filename>"``.
For convenience, ``before`` and ``after`` will automatically escape forward
slashes, single quotes and parentheses for you, so you don't need to
specify e.g. ``http:\/\/foo\.com``, instead just using ``http://foo\.com``