Notes on ScopePort

Tag: database

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

1 Comment :, , , , , , more...

How ScopePort helps you find your own programming errors

by Lennart on Jul.12, 2009, under ScopePort

I followed a strange behaviour of the latest HEAD version of  ScopePort a few minutes ago: The services failed one after another with the SERVICE_INTERR status. This means that there has been an internal ScopePort error while checking the service. I took a look at the “Vitals” section in the ScopePort web interface and found out that I must have forgotten a mysql_close() somewhere in my last changes:

How ScopePort helps you find your own programming errors

Well, I also found a Typo… ;)

Leave a Comment :, , , more...

Rails Migrations: How to define an own column as primary key

by Lennart on Nov.09, 2008, under Ruby On Rails

Usually the Ruby On Rails convention to use ID as the primary key of tables is fine. But sometimes you want to use another column as primary key. In my case I wanted to use the column “pid” of the ScopePort table “health” as the primary key. This is the way to do it:

def self.up
  create_table :health, :primary_key => :pid do |t|
    t.integer :threads, :timestamp
    t.boolean :clienthandler
    t.string :vmem, :packetsOK, :packetsERR
  end
end

The first notable point is the create_table option “:primary_key => :pid”. It instructs rake not to create the ID column but to use the column “pid” as primary key. You don’t need to define :pid later – It will be created automatically as an integer.

Leave a Comment :, , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!