Tag: rails
Generate all graphs using a rake task
by Lennart on Feb.07, 2010, under ScopePort
Lennart just pushed a new rake task to master: graphfactory[:all|:hosts|:services]
Use it to generate all graphs at once – It is highly recommended to use this task as a cronjob to avoid extremely long page generation times of host and service detail views.
Sample output:
$ rake graphfactory:all === Service 'Google' === Last stored value is from Sun Feb 07 01:29:51 +0100 2010 Inserting 240 values into RRD... === Service 'ScopePort SMTP' === Last stored value is from Sun Feb 07 01:29:36 +0100 2010 Inserting 36 values into RRD... === Service 'ScopePort SSH' === Last stored value is from Sun Feb 07 01:30:47 +0100 2010 Inserting 22 values into RRD... === Host 'scopeport.org' === == Graph: cpuload == Last stored value is from Sat Jan 23 22:16:28 +0100 2010 Inserting 13038 values into RRD... == Graph: disk-read-ops == Last stored value is from Fri Dec 04 03:39:41 +0100 2009 Inserting 4347 values into RRD... == Graph: disk-write-ops == Last stored value is from Fri Dec 04 03:39:41 +0100 2009 Inserting 4347 values into RRD... == Graph: free-memory == Last stored value is from Sat Jan 23 22:19:28 +0100 2010 Inserting 4347 values into RRD... == Graph: open-files == Last stored value is from Sat Jan 23 22:19:28 +0100 2010 Inserting 4346 values into RRD... == Graph: processes == Last stored value is from Sat Jan 23 22:18:28 +0100 2010 Inserting 4347 values into RRD...
How to use Rails SMTP configuration parameters from database
by Lennart on Jul.26, 2009, under Ruby On Rails
Usually the Rails SMTP configuration takes place in config/environment.rb like this:
ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", :port => 587, :domain => "domain.com", :user_name => "user@domain.com", :password => "password", :authentication => :plain }
ScopePort already has a Email settings part in the setup section where all the required SMTP settings are stored. I wanted to fetch the SMTP configuration from the database to avoid double configuration. I stumbled over this blog post after a while: http://broadcast.oreilly.com/2009/03/using-multiple-smtp-accounts-w.html Based on this I developed the following dynamic way to define the SMTP settings:
class EmergencyMailer < ActionMailer::Base def load_settings @@smtp_settings = { :address => Setting.first.mail_server, :port => Setting.first.mail_port, :domain => Setting.first.mail_hostname, :authentication => :plain, :user_name => Setting.first.mail_user, :password =>Setting.first.mail_pass } end def emergency_notification(emergency, email) load_settings recipients email from Setting.first.mail_from subject "[ScopePort] An emergency has been declared!" sent_on Time.now body :emergency => emergency end end
The method load_settings gets called by the delivery method and fills the smtp_settings instance variable with parameters from the database.
Check out this Rails Guide if you want to learn more about ActionMailer: http://guides.rubyonrails.org/action_mailer_basics.html
I can’t believe it’s a remote monitoring system: Emergencies with chat
by Lennart on Jul.22, 2009, under ScopePort
Lennart just commited (1, 2, 3) the new emergency system. In the ScopePort settings defined people will be notified about the emergency if you declare one. You can then coordinate countermeasures with your co-workers in the emergency detail view. There are the common comments (like in the service monitoring module) and even a real time chat! The ScopePort logo is pulsating and there is a big message if there are active emergencies. You just can’t miss them – Even if you don’t check your notifications. (Emergency service, anyone?
)
(The emergency comments are still missing in these screenshots)
extconf.rb:1:in `require’: no such file to load
by Lennart on Jan.09, 2009, under Uncategorized
When a gem installation fails with something like “extconf.rb:1:in `require’: no such file to load” you are probably missing the ruby development packages.
On Ubuntu you can fix this by installing the ruby1.8-dev package. (sudo aptitude install ruby1.8-dev)
Phusion Passenger error “No such file or directory – /nonexistent”
by Lennart on Jan.09, 2009, under Ruby On Rails
When you try to start your Rails application with Passenger/Apache and get an error like “No such file or directory – /nonexistent” make sure that your config/environment.rb file is not owned by root or nobody. Change the owner to e.g. www-data!
How to use the GitHub post-receive JSON API with Rails
by Lennart on Nov.21, 2008, under Ruby On Rails
GitHub offers you a lot of post-receive notifications. This means that some actions are made whenever you commit something. You can e.g. send notifications via Jabber or IRC – Another option is to call a URL with JSON data. This Rails snippet receives the JSON data and stores relevant information in your database:
class TunerController < ApplicationController
# Basic HTTP authentication.
USER, PASSWORD = "github", "secret"
before_filter :authenticate
# Disable need of authenticity token.
skip_before_filter :verify_authenticity_token
def index
# Include JSON. (gem install json)
require 'json'
# Check if the JSON request is in correct format.
if params[:payload].blank?
# Wrong format. Exit.
render :text => "no payload"
return
end
# Parse the JSON request and store resulting hash.
push = JSON.parse(params[:payload])
# Get the "commits" part.
commits = push["commits"]
# Check if there were commits. Yes, there should be some...
if commits.blank?
# No commits found. Strange - Exit!
render :text => "no commits found"
return
end
# Store the interesting information of the last commit-
last_commit_message = commits.last["message"]
last_commit_timestamp = commits.last["timestamp"]
last_commit_author = commits.last["author"]["name"]
# Create a new object to save in databse.
data = Git_Message.new do |d|
d.last_commit_message = last_commit_message
d.last_commit_timestamp = last_commit_timestamp
d.last_commit_author = last_commit_author
end
# Save our commit data in the database!
if !data.save
# Could not save.
render :text => "could not store in database"
return
end
# Everything went well.
render :text => "done"
end
private
def authenticate
authenticate_or_request_with_http_basic "nothing to see here"
do |id, password|
id == USER && password == PASSWORD
end
end
end
Set the GitHub post-receive URL to something like http://github:secret@example.org/tuner – Where “github” is the user and “secret” the password. You can alternatively just enter the URL and remove the authentication methods from the Rails controller.



