In this blog post, we’re going to demonstrate a simple shell script we cooked up to extract errors from logs sitting in an Elasticsearch database and then send those errors to Airbrake.
We’ve been experimenting with options to show you what your errors would look like in Airbrake. In this guide you’ll be able to login and see a glimpse of what your monitoring would look like on Airbrake, without adding any code to your application or installing a Logstash plugin.
The use cases we see for this are situations where the code you want to monitor is hard to change. Maybe this code is mission critical and the permissions are pretty locked down. In other cases, the approval process for new code could be quite time consuming. There’s a number of situations where we see that it’s more efficient to look at your logs to figure out if things are failing, and we’re investigating ways to enable this workflow within Airbrake.
If you find this useful, and want continuous monitoring instead of this one-time glimpse, we definitely suggest you integrate one of the many client libraries we have available. Check out all of our supported languages here: https://redesign.airbrake.io/languages
Ok! Let’s get started.
First we’re going to setup a new project in airbrake. From your settings page, click “Create New Project” in the top right, and follow the instructions in the window to create a new project:
Now we want to write down a few things for later use in our shell script. We’ll navigate to the project settings and write down our “Project Key” and “Project Id”.
Now we’re going to go and retrieve the Elasticsearch query we’re going to use to extract your errors. This is going to be different depending on how you view and log your errors, so you’ll need to play with this until you can find a query that accurately describes everything you’d want to be monitored by Airbrake. Internally, we use Kibana 3 to view our logs and our backend errors are logged to a specific file, so for us, this process looks like this:
Once you create a query that only shows your errors, we want to save the JSON of this query to a local file called “queryData.json”. In Kibana 3, there’s a little “i” button that allows you to see a curl request for the current page’s data. We’re going to copy the “query” field of the JSON in this curl call and save that to a file called “queryData.json”:
Now we’re going to download a shell script that will put it all together and send our errors to airbrake. This script was written on an OSX machine, so windows users will need to install cygwin or some equivalent to run this locally.
wget -O ./logstashToAirbrake.sh https://gist.githubusercontent.com/zachgoldstein/d6ed2c1376ec3c04eda4ab61633a623a/raw/9fd6df78c84a8a85e49a77ed59509cbf0835722f/logstashToAirbrake.sh
brew install jq
On other systems, see https://github.com/stedolan/jq/wiki/Installation
Depending on your default permissions, you may also need to make sure the shell script you just downloaded is executable. You can do this by running:
chmod +x ./logstashToAirbrake.sh
Now we can run it!
You will be prompted to input your elasticsearch credentials, elasticsearch domain, your airbrake project key, and airbrake project id.
You should see output….
Make sure queryData.json is also downloaded Great, jq is installed Loading error logs from elasticsearch Now sending errors to airbrake, this process is slowed to 1 error/sec to stay under rate limits Sent 10 errors to airbrake Done!
Now go to the airbrake interface and you should see your errors!
During this process we didn’t touch a single line of your code, and now you can see your errors shown inside Airbrake. With this in hand we hope you explore the interface and see how great life is when error monitoring has your back. This is a bit of an experiment for us at Airbrake, and if we see people find it useful, we’d love to streamline it even more.
If you enjoy using Airbrake, the next steps would be to properly integrate one of our many client libraries to get continuous monitoring and notifications from Airbrake. Installation and docs can be found here: https://redesign.airbrake.io/docs/. If you don’t yet have an Airbrake account, you can create a free basic account here: https://redesign.airbrake.io/account/new/free