Tag Results
6 posts tagged rails
6 posts tagged rails
I wrote and published a gem that you can load as Rack middleware in your Rails application. It transparently fetches all your Exceptions (and throws them back to the application so it does not affect your own Exception handling) and sends them as a GELF message to your Graylog2 installation.
Install the gem. It has my GELF gem as dependency and will install it automatically:
lennart ~$ sudo gem install graylog2_exceptions
Successfully installed gelf-0.9.1
Successfully installed graylog2_exceptions-0.5.3
Now open your config/environment.rb and add the gem as Rack middleware: (Make sure to require 'graylog2_exceptions' before.)
config.middleware.use "Graylog2Exceptions", { :host => '127.0.0.1', :port => '12201', :local_app_name => 'mama' }
Parameter explanation:
That’s it: Restart your app and all your Exceptions will be logged to Graylog2!

The guide has moved here: https://github.com/Graylog2/graylog2-web-interface/wiki/Installing-the-web-interface-on-Debian-5.0
I wrote a shell script that lets me easily create new Graylog2 releases. It bundles Rails with all required gems, configures the release, works on some files and creates a nice .tar.gz package I can test and upload as release.
lennart@sundaysister:~/workspace/graylog2-web-interface/build$ time sudo ./build_release.sh 0.8.2
BUILDING graylog2-web-interface-0.8.2
Copying files ...
Configuring release ...
Freezing Rails and gems ...
Building Tarball ...
DONE! Created Graylog2 release graylog2-web-interface-0.8.2 on Thu Jul 29 21:05:17 CEST 2010
real 0m7.105s
user 0m5.800s
sys 0m1.200s
The script source is available in the graylog2-web-interface GitHub repository: http://github.com/lennartkoopmann/graylog2-web-interface/blob/master/build/build_release.sh
MongoMapper is a great project but missing a lot of documentation in some core parts. I wanted to find out how to connect to a MongoDB instance that requires authentication and this is how I did it:
# config/database.yml
mongodb:
hostname: localhost
database: graylog2
port: 27017
authenticate: true
username: graylog2user
password: graylog2pw
I just wrote a Graylog2 rake task that can be used as Nagios check. It checks if the number of new log messages exceeds a given limit:
lennart@lennart-t61:~/workspace/graylog2-web-interface$ rake nagios:check minutes=10 messages=100
(in /home/lennart/workspace/graylog2-web-interface)
status: okay
The rake task code: (Interesting if you want to pass parameters to rake tasks)
In Rails, the h() method is an alias of the html_escape() ERB method and can’t be accessed in your controllers. Use CGI.escapeHTML() instead:
render :text => CGI.escapeHTML(some_string)