Skip to content

Instantly share code, notes, and snippets.

View bkjones's full-sized avatar

Brian K. Jones bkjones

  • Doylestown, PA USA
View GitHub Profile
@bkjones
bkjones / patcher
Created July 27, 2012 02:24
my context manager was worse off than I thought :(
Original version ('pre' prints the patched callable before entering the 'with' block, and 'post' does the same inside the 'with' block):
.....pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4321796496'>
.pre: <MagicMock name='build_url' id='4321796496'>
post: <MagicMock name='build_url' id='4321825552'>
.pre: <MagicMock name='build_url' id='4321825552'>
post: <MagicMock name='build_url' id='4321871248'>
.pre: <MagicMock name='build_url' id='4321871248'>
post: <MagicMock name='build_url' id='4321904656'>
@bkjones
bkjones / sendgraph.py
Created February 24, 2012 18:08
A script I wrote to allow nagios to send an alert with an attached graphite graph via email.
#!/usr/bin/env python
"""
This takes a recipient email address and a graphite URL and sends a
POST to <graphite host>/dashboard/email with a body that looks like
this:
sender=user%40example.com&recipients=user2%40example.com&subject=foo&message=bar&graph_params=%7B%22target%22%3A%22target%3DdrawAsInfinite(metric.path.in.graphite)%22%2C%22from%22%3A%22-2hours%22%2C%22until%22%3A%22now%22%2C%22width%22%3A600%2C%22height%22%3A250%7D
...which will cause the graphite installation to send an email.
192.168.1.55 [Thu, 11 Aug 2011 12:41:21 -0400] INFO: Processing package[git] action install (git::default line 23)
192.168.1.55 /usr/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/provider/package/yum.rb:69:
192.168.1.55 [BUG]
192.168.1.55 Segmentation fault
DEBUG: Using configuration from /Users/bjones/.chef/knife.rb
Bootstrapping Chef on 192.168.1.55
DEBUG: Looking for bootstrap template in /Library/Ruby/Gems/1.8/gems/chef-0.10.2/lib/chef/knife/bootstrap
DEBUG: Found bootstrap template in /Library/Ruby/Gems/1.8/gems/chef-0.10.2/lib/chef/knife/bootstrap
/Library/Ruby/Gems/1.8/gems/chef-0.10.2/lib/chef/knife/core/bootstrap_context.rb:51:in `read': No such file or directory - ~/.chef/client.pem (Errno::ENOENT)
from /Library/Ruby/Gems/1.8/gems/chef-0.10.2/lib/chef/knife/core/bootstrap_context.rb:51:in `validation_key'
from (erubis):24:in `evaluate'
from /Library/Ruby/Gems/1.8/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `instance_eval'
from /Library/Ruby/Gems/1.8/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `evaluate'
from /Library/Ruby/Gems/1.8/gems/chef-0.10.2/lib/chef/knife/bootstrap.rb:132:in `render_template'