Fabric task for notifying New Relic of a code deploy
We’ve been doing some playing around with New Relic lately at Pathwright. One of the neat things it does is track when code deploys happen, and how they affect responsiveness and resource consumption.
In order to notify New Relic when a deploy happens, you simply POST to their web-based API with the information you’d like to include (change logs, commit hashes, etc).
We currently do this via a Fabric task, which I figured I’d share. We tend to run this from our deploy task. Enjoy!
import socket
import requests
from fabric.api import run, cd
def notify_newrelic_of_deploy(old_commit_hash):
"""
New Relic tracks deploy events. Send a notification via their HTTP API.
:param str old_commit_hash: The previously deployed git hash. This is
easily retrieved on a remote machine by running 'git rev-parse HEAD'.
"""
with cd(env.REMOTE_CODEBASE_PATH):
new_commit_hash = run('git rev-parse HEAD')
changes = run('git --no-pager log %s..HEAD' % old_commit_hash)
headers = {
# Adjust this to reflect your API key.
'x-api-key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
}
payload = {
'deployment[app_name]': 'Your App Name',
# This is also very important to update with your own value.
'application_id': '1234567',
'deployment[description]': 'Fabric deploy is fun deploy',
'deployment[revision]': new_commit_hash,
'deployment[changelog]': changes,
'deployment[user]': '%s@%s' % (LOCAL_USERNAME, socket.gethostname()),
}
requests.post("https://rpm.newrelic.com/deployments.xml",
data=payload, headers=headers)
Switched to Pelican
For the last four years, my blog has been powered by Django. As I have found myself becoming more and more busy, I have stopped wanting to hassle with keeping things up to date on the server and the application.
After a weekend of tinkering and conversions, I’m now ...
read moreAnsible first impressions
Amazon Elastic Transcoder Review
Amazon Elastic Transcoder was released just a few short days ago. Given that we do a lot of encoding at Pathwright, this was of high interest to us. A year or two ago, we wrote media-nommer which is similar to Amazon’s Transcoder, and it has worked well for us ...
read morepython-route53 released!
After some more time in the cooker, python-route53 1.0 has landed on PyPi. This is a stand-alone Route 53 package, independent from the one in boto. The major hilights are:
- Python 2.7 and 3.x compatibility.
- Extremely simple API
- Powered by requests
Read the documentation, see the source ...
read morepython-route53 feedback wanted
Late last night (or early this morning), I finished the draft of python-route53, a stand-alone Route 53 module with Python 3.x and Python 2.7 compatibility. Route 53 is an excellent DNS service offered by Amazon Web Services. It exposes everything through an API.
My intentions with python-route53 are ...
read moreEvennia MUD server gets BSD’d
As of a few days ago, the Evennia MUD server has been re-licensed under the BSD License. We feel like this will knock down another barrier for those considering running a game with Evennia. I can’t recommend this codebase enough for anyone who may have caught the MUD development ...
read morepython-fedex and colormath re-licensed under BSD
I am happy to announce that python-fedex and python-colormath have been re-licensed under the BSD License. At the time these two packages were created, there were reasons for GPL’ing these. However, said reasons have long since been removed, so it’s BSD time!
My involvement with both of these ...
read morepython-bluefin 1.3 released
python-bluefin 1.3 has been released, now with improved error handling. The major feature in this release is that we have smoothed over some inconsistencies in Bluefin’s error handling.
Instead of setting an HTTP status code indicating an error like they do for most of the Bluefin API errors ...
read morepython-bluefin 1.2 released, sans urllib2
python-bluefin 1.2 has been released. python-bluefin is a very thin wrapper around the Bluefin payment gateway’s API. The two major changes are:
- urllib2 has been removed, with the excellent requests taking its place.
- We now check directmode’s status_code for known failure codes and raise exceptions based on ...