<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Notes on ScopePort &#187; rails</title>
	<atom:link href="http://blog.scopeport.org/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.scopeport.org</link>
	<description>The ScopePort Blog</description>
	<lastBuildDate>Sun, 07 Feb 2010 01:08:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Generate all graphs using a rake task</title>
		<link>http://blog.scopeport.org/scopeport/generate-graphs-rake-task/</link>
		<comments>http://blog.scopeport.org/scopeport/generate-graphs-rake-task/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 01:08:43 +0000</pubDate>
		<dc:creator>Lennart</dc:creator>
				<category><![CDATA[ScopePort]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[task]]></category>

		<guid isPermaLink="false">http://blog.scopeport.org/?p=348</guid>
		<description><![CDATA[Lennart just pushed a new rake task to master: graphfactory[:all&#124;:hosts&#124;:services]
Use it to generate all graphs at once &#8211; 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 [...]]]></description>
			<content:encoded><![CDATA[<p>Lennart just <a href="http://github.com/lennartkoopmann/scopeport-web-interface/commit/819c6a4dcbae2928ca80843054ec70a8dc00b665" target="_blank">pushed a new rake task to master</a>: <em>graphfactory[:all|:hosts|:services]</em></p>
<p>Use it to generate all graphs at once &#8211; It is highly recommended  to use this task as a cronjob to avoid extremely long page generation times of host and service detail views.</p>
<p><strong>Sample output:</strong></p>
<pre>
$ 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...
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.scopeport.org/scopeport/generate-graphs-rake-task/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to use Rails SMTP configuration parameters from database</title>
		<link>http://blog.scopeport.org/ruby-on-rails/rails-smtp-configuration-parameters-database/</link>
		<comments>http://blog.scopeport.org/ruby-on-rails/rails-smtp-configuration-parameters-database/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 01:08:34 +0000</pubDate>
		<dc:creator>Lennart</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[actionmailer]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[settings]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://blog.scopeport.org/?p=270</guid>
		<description><![CDATA[Usually the Rails SMTP configuration takes place in config/environment.rb like this:

ActionMailer::Base.smtp_settings = &#123;
  :address =&#62; &#34;smtp.gmail.com&#34;,
  :port =&#62; 587,
  :domain =&#62; &#34;domain.com&#34;,
  :user_name =&#62; &#34;user@domain.com&#34;,
  :password =&#62; &#34;password&#34;,
  :authentication =&#62; :plain
&#125;

ScopePort already has a Email settings part in the setup section where all the required SMTP settings are stored. [...]]]></description>
			<content:encoded><![CDATA[<p>Usually the Rails SMTP configuration takes place in <em>config/environment.rb</em> like this:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>.<span style="color:#9900CC;">smtp_settings</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:address</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;smtp.gmail.com&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:port</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">587</span>,
  <span style="color:#ff3333; font-weight:bold;">:domain</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;domain.com&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:user_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;user@domain.com&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;password&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:authentication</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:plain</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>ScopePort already has a <em>Email settings</em> 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: <a href="http://broadcast.oreilly.com/2009/03/using-multiple-smtp-accounts-w.html" target="_blank">http://broadcast.oreilly.com/2009/03/using-multiple-smtp-accounts-w.html</a> Based on this I developed the following dynamic way to define the SMTP settings:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> EmergencyMailer <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>   
  <span style="color:#9966CC; font-weight:bold;">def</span> load_settings
    @@smtp_settings = <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:address</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> Setting.<span style="color:#5A0A0A; font-weight:bold;">first</span>.<span style="color:#9900CC;">mail_server</span>,
      <span style="color:#ff3333; font-weight:bold;">:port</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> Setting.<span style="color:#5A0A0A; font-weight:bold;">first</span>.<span style="color:#9900CC;">mail_port</span>,
      <span style="color:#ff3333; font-weight:bold;">:domain</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> Setting.<span style="color:#5A0A0A; font-weight:bold;">first</span>.<span style="color:#9900CC;">mail_hostname</span>,
      <span style="color:#ff3333; font-weight:bold;">:authentication</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:plain</span>,
      <span style="color:#ff3333; font-weight:bold;">:user_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> Setting.<span style="color:#5A0A0A; font-weight:bold;">first</span>.<span style="color:#9900CC;">mail_user</span>,
      <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span>Setting.<span style="color:#5A0A0A; font-weight:bold;">first</span>.<span style="color:#9900CC;">mail_pass</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> emergency_notification<span style="color:#006600; font-weight:bold;">&#40;</span>emergency, email<span style="color:#006600; font-weight:bold;">&#41;</span>
    load_settings
    recipients  email
    from        Setting.<span style="color:#5A0A0A; font-weight:bold;">first</span>.<span style="color:#9900CC;">mail_from</span>
    subject     <span style="color:#996600;">&quot;[ScopePort] An emergency has been declared!&quot;</span>
    sent_on     <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
    body        <span style="color:#ff3333; font-weight:bold;">:emergency</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> emergency
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The method <em>load_settings</em> gets called by the delivery method and fills the <em>smtp_settings</em> instance variable with parameters from the database.</p>
<p>Check out this Rails Guide if you want to learn more about ActionMailer: <a href="http://guides.rubyonrails.org/action_mailer_basics.html" target="_blank">http://guides.rubyonrails.org/action_mailer_basics.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.scopeport.org/ruby-on-rails/rails-smtp-configuration-parameters-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>I can&#8217;t believe it&#8217;s a remote monitoring system: Emergencies with chat</title>
		<link>http://blog.scopeport.org/scopeport/remote-monitoring-system-emergencies-chat/</link>
		<comments>http://blog.scopeport.org/scopeport/remote-monitoring-system-emergencies-chat/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 01:40:08 +0000</pubDate>
		<dc:creator>Lennart</dc:creator>
				<category><![CDATA[ScopePort]]></category>
		<category><![CDATA[chat]]></category>
		<category><![CDATA[emergencies]]></category>
		<category><![CDATA[emergency]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[real time]]></category>

		<guid isPermaLink="false">http://blog.scopeport.org/?p=255</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>Lennart just commited (<a href="http://github.com/lennartkoopmann/scopeport-web-interface/commit/c77c7ddc0b714658b071ee30ec7eeb832b2823e1" target="_blank">1</a>, <a href="http://github.com/lennartkoopmann/scopeport-web-interface/commit/e3574c6c8a93333961348813952a34eabdc8c228" target="_blank">2</a>, <a href="http://github.com/lennartkoopmann/scopeport-web-interface/commit/b46713700ee1c1a73b13dbe2cb4524bbe15b6c49" target="_blank">3</a>) 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&#8217;t miss them &#8211; Even if you don&#8217;t check your notifications. (Emergency service, anyone? <img src='http://blog.scopeport.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' title="I cant believe its a remote monitoring system: Emergencies with chat" /> )</p>
<div id="attachment_259" class="wp-caption aligncenter" style="width: 560px"><a href="http://blog.scopeport.org/wp-content/uploads/2009/07/scopeport-declare-emergency.png" target="_blank"><img class="size-full wp-image-259 " title="scopeport-declare-emergency_small" src="http://blog.scopeport.org/wp-content/uploads/2009/07/scopeport-declare-emergency_small.png" alt="I cant believe its a remote monitoring system: Emergencies with chat" width="550" height="344" /></a><p class="wp-caption-text">Declaring an emergency</p></div>
<p style="text-align: center;">
<div id="attachment_263" class="wp-caption aligncenter" style="width: 562px"><a href="http://blog.scopeport.org/wp-content/uploads/2009/07/scopeport-emergency-chat.png"><img class="size-full wp-image-263 " title="scopeport-emergency-chat_small" src="http://blog.scopeport.org/wp-content/uploads/2009/07/scopeport-emergency-chat_small.png" alt="Emergency detail view with active chat" width="552" height="345" /></a><p class="wp-caption-text">Emergency detail view with active chat</p></div>
<p>(The emergency comments are still missing in these screenshots)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.scopeport.org/scopeport/remote-monitoring-system-emergencies-chat/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>extconf.rb:1:in `require&#8217;: no such file to load</title>
		<link>http://blog.scopeport.org/uncategorized/extconfrb1in-require-file-load/</link>
		<comments>http://blog.scopeport.org/uncategorized/extconfrb1in-require-file-load/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 20:28:02 +0000</pubDate>
		<dc:creator>Lennart</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[abort]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[require]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.scopeport.org/?p=150</guid>
		<description><![CDATA[When a gem installation fails with something like &#8220;extconf.rb:1:in `require&#8217;: no such file to load&#8221; 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)
]]></description>
			<content:encoded><![CDATA[<p>When a gem installation fails with something like &#8220;extconf.rb:1:in `require&#8217;: no such file to load&#8221; you are probably missing the ruby development packages.</p>
<p>On Ubuntu you can fix this by installing the ruby1.8-dev package. (sudo aptitude install ruby1.8-dev)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.scopeport.org/uncategorized/extconfrb1in-require-file-load/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Phusion Passenger error &#8220;No such file or directory &#8211; /nonexistent&#8221;</title>
		<link>http://blog.scopeport.org/ruby-on-rails/phusion-passenger-error-file-directory-nonexistent/</link>
		<comments>http://blog.scopeport.org/ruby-on-rails/phusion-passenger-error-file-directory-nonexistent/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 16:25:36 +0000</pubDate>
		<dc:creator>Lennart</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[environment.rb]]></category>
		<category><![CDATA[nonexistent]]></category>
		<category><![CDATA[owner]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[permission]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[phusion]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[root]]></category>

		<guid isPermaLink="false">http://blog.scopeport.org/?p=147</guid>
		<description><![CDATA[When you try to start your Rails application with Passenger/Apache and get an error like &#8220;No such file or directory &#8211; /nonexistent&#8221; make sure that your config/environment.rb file is not owned by root or nobody. Change the owner to e.g. www-data!
]]></description>
			<content:encoded><![CDATA[<p>When you try to start your Rails application with Passenger/Apache and get an error like &#8220;No such file or directory &#8211; /nonexistent&#8221; make sure that your config/environment.rb file is not owned by root or nobody. Change the owner to e.g. www-data!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.scopeport.org/ruby-on-rails/phusion-passenger-error-file-directory-nonexistent/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How to use the GitHub post-receive JSON API with Rails</title>
		<link>http://blog.scopeport.org/ruby-on-rails/how-to-use-the-github-post-receive-json-api-rails/</link>
		<comments>http://blog.scopeport.org/ruby-on-rails/how-to-use-the-github-post-receive-json-api-rails/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 15:08:02 +0000</pubDate>
		<dc:creator>Lennart</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[commit]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[information]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[post-receive]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://blog.scopeport.org/?p=131</guid>
		<description><![CDATA[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 &#8211; 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 < [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.github.com">GitHub</a> 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 &#8211; Another option is to call a URL with <a href="http://en.wikipedia.org/wiki/JSON">JSON</a> data. This <a href="http://www.rubyonrails.com">Rails</a> snippet receives the <a href="http://en.wikipedia.org/wiki/JSON">JSON</a> data and stores relevant information in your database:</p>
<pre>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 &#038;&#038; password == PASSWORD
		end
	end

end
</pre>
<p>Set the <a href="http://www.github.com">GitHub</a> post-receive URL to something like http://github:secret@example.org/tuner &#8211; Where &#8220;github&#8221; is the user and &#8220;secret&#8221; the password. You can alternatively just enter the URL and remove the authentication methods from the <a href="http://www.rubyonrails.com">Rails</a> controller.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.scopeport.org/ruby-on-rails/how-to-use-the-github-post-receive-json-api-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
