Skip to content

Instantly share code, notes, and snippets.

View williamsjj's full-sized avatar

Jason J. W. Williams williamsjj

View GitHub Profile
#!/bin/sh
# Start/stop the named twistd application
#
APP=/opt/myapp/myapp.py
TWISTD=/usr/bin/twistd
PID=/var/run/myapp.pid
LOGFILE=/var/log/myapp/myapp.log
DESCRIPTION="Super duper Twisted apptacularness!"
NAME=myapp
import sys, os, socket, struct
from amqplib import client_0_8 as amqp
from optparse import OptionParser
### Constants
EXIT_NAGIOS_OK = 0
EXIT_NAGIOS_WARN = 1
EXIT_NAGIOS_CRITICAL = 2
#!/usr/bin/python
from twisted.internet import defer, reactor, threads
import redis
import uuid
import time
def do_redis_in_thread(uuid_str, thread_num):
print "[%s] Thread %d Pre-Connect" % (str(time.clock()), thread_num)
#!/usr/bin/python
import sys
if sys.platform == "linux2":
from twisted.internet import epollreactor
epollreactor.install()
import datetime, time
from StringIO import StringIO
from twisted.internet import reactor, task
class RedisClientFactory(protocol.ReconnectingClientFactory):
"""Redis client factory that reconnects/creates a new connection when the old one is lost."""
maxRetries = 3
def buildProtocol(self, addr):
self.client = Redis()
self.client.factory = self
self.resetDelay()
# Enhanced txRedis that handles setting up auth and DB
class ERedis(Redis):
def __init__(self, db=None, charset='utf8', errors='strict', passwd=None):
self.charset = charset
self.db = db
self.errors = errors
self._buffer = ''
self._bulk_length = None
self._disconnected = False
---------------------------------------------------------------------------------------------------------------------------------
Option Name Value Type Default Description
____________________________ ________________ ____________ ______________________________________________________________________
dump\_log\_write\_threshold integer 100 How often to flush/dump the contents of the append-only log
into the actual database files. It is specified in terms of
how many entries must be in the log before a dump operation occurs.
Setting this to a higher number can reduce I/O load and increase
performance for persistent messages.
--------------------------------------------------------------------------------------------------------
<table>
<caption>
&quot;mnesia&quot; Configuration Options
</caption>
<col width="100%" />
<tbody>
<tr>
<td align="left">
Option Name Value Type Default Description
____________________________ ________________ ____________
import re, uuid
def base36encode(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
'''
Convert positive integer to a base36 string. From: http://en.wikipedia.org/wiki/Base_36#Python_Conversion_Code
'''
if not isinstance(number, (int, long)):
raise TypeError('number must be an integer')
if number < 0:
raise ValueError('number must be nonnegative')
post_data = "x-ctch-request-id: 123456789\r\n" + \
"x-ctch-request-type: classifyurl\r\n" + \
"x-ctch-pver: 1.0\r\n" + \
"\r\nx-ctch-url: %s" % (host + path)
d = client.getPage('http://%s:%d/ctwsd/websec' % (self.category_host, self.category_port),
method="POST",
headers={'User-Agent' : "Hydra"},
postdata=post_data)