Web Site and Server Monitoring with Nagios

Nagios since it’s inception in 1999 has become one of the most popular and open source monitoring system (under the free license GNU General Public License) to monitor IT infrastructure problems.

It alerts you about any critical problem that might occur in your infrastructure through e-mail, SMS and pager.

Installation and configuration of Nagios is comparatively simpler than other infrastructure monitoring tools.

Although numerous plugins are available in the internet to monitor different services and for graphing of the data, plugin can also be customized as per your requirement by using tools like shell scripts, C++, Perl, Ruby, Python, PHP, C#, etc. DuringNagios configuration you have to keep the following in mind.

  • Lines starting with ‘#’ character are considered as comments and are ignored while processing.
  • Inconfiguration lines the characters that appear after a semicolon (;) arealso treated as comments hence are not processed.
  • Directive names are case-sensitive.

To get data from the monitoring host’s you will need aNagios agent. Below are some popular Nagios Agents:

  • NRPE
  • NRDP
  • NSClient++

Below are some protocols used for monitoring:

  • SMTP
  • POP3
  • HTTP
  • NNTP
  • ICMP
  • SNMP
  • FTP
  • SSH

Below are some Host resources which can be monitored:

  • Processor load
  • Disk usage
  • System logs

Kick off Your Small Business with Magento Go

With internet prevailing its effect on every corner, businesses got the chance to spread across the world.

Once a small cotton factory is now the biggest ready-made clothing supplier of the world and this is not a single instance as there are millions like this.

Keeping that legacy alive, Magento development platform launched the online eCommerce building platform Magento Go. It lets you develop an online store for your small business with very much less investment.

And the best thing is you don’t need to be a techno-buff for this due to its simplest operations and easy learning interface.

Magento introduced a SaaS (software-as-a-service) version of its e-commerce platform named Magento Go. It allows small businesses or merchants to build easy-to-use shopping portals for customers around the world.

If you’re thinking of setting up an online store for your various product ranges, then it can help you build your store with your designs.

Magento Go include some basic features like Order Management, Customer Analytics and some cool features like Coupons and Gift Cards, which were not available in the Magento Community edition.

The designs, impressive templates, product flexibility, and search engine friendliness are some of the major features in Magento Go.

Magneto Development team recently updated additional features to Magento Go for merchants of the United Kingdom like Royal Mail Shipping, UK Cookie law compliance, improved PayPal payments, VATs and many more.

A trial out period of 30 days is available which can be then subscribed with fewer cost plans to run your e-commerce business. Customer engagement majors like assisted shopping, product comparisons, and wish lists are also taken to make the interactions more useful.

It Connect which is a market for a place for other Magento Go plug-ins is available for merchants who want to add additional features to their stores.

It is really going to kick off your small business if you know optimal utilization of the resources available to reach the maximum number of people.

At Andolasoft we’ve got expert developers on Magento development who have broad experience over handling individual projects on Magento. We have been developing the best quality, highly scalable websites for small to large scale enterprises.

Whether you’re a start-up eCommerce business or a large retailer switching to eCommerce, we can help you by building search friendly and secure websites as per your requirements.

 

Customizing Error Messages In RAILS

In every application regardless of its complexity we require to customize error messages to make more sense. There are several ways to achieve it in Rails 3 and in Rails 2.3.x which are mentioned specifically and that can be handled either in models or controllers or helpers.

Solution# 1:

If it is needed to be handled in model and message need to be have customized instead of the attribute name. Like if the attribute name is “name” but you want to display messages “Employee name cannot be blank” then we have to install “custom-err-msg” plug-in.

This plugin gives you the option to not have your custom validation error message prefixed with the attribute name. Ordinarily, if you have, say:

validates_acceptance_of : terms, :message => 'Please accept the terms of service'

You’ll get the following error message: Terms Please accept the terms of service

This plugin allows you to omit the attribute name for specific messages. All you have to do is begin the message with a ‘^’ character. Example:

validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'

step# 1

To install the ”custom-err-msg” plug-in you have to use the command.

“ruby script/plugin install https://github.com/gumayunov/custom-err-msg.git”

If you are facing problem by installing the plugin then clone it and just copy the folder (”gumayunov-custom-err-msg-640db42”) inside “Vendor/plugin/” folder

step# 2

In view file just display it as mentioned below:

Similarly, it can use in other places like,

validates_presence_of :claim_no, :message => "^Work Order/Claim number cannot be blank!"

The plugin also lets you use procs instead of strings.

Example:

validates_acceptance_of :accepted_terms, :message => Proc.new {|service| "You must accept the terms of the service #{service.name}" }

The above plug-in usage can be avoided by declaring alias for each attribute as mentioned below.
You should have a file named config/locales/en.yml, if not simply create one. There you can add your own custom names.

en:
activerecord:
models:
order: "Order"
attributes:
order:
b_name: "Business Name"

This will replace your attribute “b_name” with “Business Name”

Your Order model in app/models/order.rb should look like:

class Order < ActiveRecord::Base
validates :b_name, :presence => true

The error message will be displayed like

Business Name cannot be blank

Solution# 3:

Another way is to define a method and an error message inside the method in the model.

Class Employee < ActiveRecord::Base
validate :zip_must_be_valid
def zip_must_be_valid
unless zip.map(&:valid?).all?
errors.add_to_base " zip code is invalid"
end
end
end

We can also customize the error messages in Controllers.
Suppose “First Name” cannot be blank to be checked. Then use below code to check for it and show customized messages

if(params[:employee][:first_name].nil?)
flash[:error] = "First name should not be blank.n"
end

Subsequently, if it is required to add other messages to the above for other attributes then it can be written as,

if(params[:employee][:address].nil?)
flash[:error] += Address should not be blank.n"
end

Solution# 5

Customization of error messages can be done in controllers by adding messages to the existing error object’s method “add_to_base”.

if email_data[:"email_no_#{i}"] != "" && email_data[:"email_no_#{i}"] !~ /^([^@s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i
valid_params = false
@company_info_new.errors.add_to_base( "Invalid Email Id!" )
End

In views it can be displayed by writing below code:

0 %>
nil, :message => nil >

Solution# 6

The customization that can be handled in views using

“error_message_on” helpers (Rails 2.3.8)”

In case you wish to show one error message in a specific location that relates to a specific validation then use “error_message_on” helper. You might have used “error_message_on” to display field-specific error messages. Here is an example that would display an error message on a name field:

Solution# 7

You can also use “error_message_on”(Rails 2.3.8) to display non-field-specific error messages.

class User < ActiveRecord:Base
validate :user_is_active
private
def user_is_active
if self.is_active != true
errors.add : user_is_active, 'User must be active to continue'
end
end
end

Now, to display this custom validation error message with “error_message_on”, we simply need to reference “:user_is_active” when we call the helper. Consider this implementation:

Solutions# 8

class User < ActiveRecord::Base validates_presence_of :email validates_uniqueness_of :email validates_format_of :email, :with => /^[wd]+$/ :on => :create, :message => "is invalid"
end

In Rails 3 it’s possible to call a validate method and pass it a hash of attributes to define the validations instead of defining each validation separately as mentioned above.
/app/models/user.rb

class User < ActiveRecord::Base validates :email, :presence => true,
:uniqueness => true,
:format => { :with => /^([^@s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i }
end

In the User model we’re still validating that the field has a value and that the value is unique. For validating the format there are a number of options we can pass so we use a secondary hash to define those.

We can supply any number of validations for an attribute with a single command. While this is useful it can become cumbersome if there are a large number of validations but for most situations, it works nicely.

We can make the “:format” option more concise and clean it up a little. We often want to validate email addresses and having the same long regular expression in each validator is a little ugly and introduces repetition into the code. We can extract this out into a separate validation by creating a new class in our application’s /lib directory. We’ll call the file email_format_validator.rb.

class EmailFormatValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value)
unless value =~ /^([^@s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i object.errors[attribute] << (options[:message] || "is not formatted properly")
end
end
end

The EmailFormatValidator class inherits from ActiveModel:: EachValidator. We have to define one method in the class “validate_each”, that takes three parameters called object, attribute and value. The method then checks that the value matches the regular expression we’re using to validate an email address and if not it will add the attribute to the objects errors.

We can use this technique to define any kind of validation we like. Now that we have our custom validator we can update the validator in the “User” model to use it.
/app/models/user.rb

class User < ActiveRecord::Base
validates :email,
:presence => true,
:uniqueness => true,
:format => { :with => /^([^@s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i }
end

Having an email_format key in the “validates” hash means that the validator will look for a class called email_format_validator and passes the validation behavior into the custom class that we just wrote.
If we try to create a new user now and enter an invalid email address we’ll see the expected error message.

If you have some trick to share, do it in the comments.

How to add AJAX Pagination using jQuery in Rails3

Ruby_on_railsAjax pagination will do the same functionality of pagination without refreshing the page. It calls the action through jQuery to display the results per page.

This example demonstrates the implementation of ajax pagination in Rails3. However the same can be used with Rails2.3.x.

Remember to add jQuery to your paths.

Step#1

Add the following gem to your Gemfile

gem 'will_paginate'
Run bundle install

Step#2

Include the following code in the controller you want to paginate, For example, I have used Posts controller.

class PostsController < ApplicationController
  def index
    @posts = Post.paginate(page: params[:page], per_page: 10)
  end
end

Step#3

Add this in the view “posts/index.html.erb” file

<div id=”post_id”>
<%=render partial:’posts’%>
</div>

Encapsulate the order list in the partial view “posts/_posts.html.erb”

<ul>
<% @posts.each do |post|%>
<li>
<!-- Show post data -->
</li>
<% end %>
</ul>
<% = will_paginate(@posts,:id=>”ajax_paginate”)%>
 
<script>
 
$(document).ready(function() {
$(“#ajax_paginate”).find(“a”).each(function(){
var linkElement = $(this);
var paginationURL = linkElement.attr(“href”);
linkElement.attr({“url”:paginationURL, “href”: ”#”});
linkElement.click(function(){
$(“#post_id”).html(‘<div align= “center”><br/>
<img src=”/images/loader.gif”/></div>’)
$(“#post_id”).load($(this).attr(‘url’));
Return false;
});
});
});
 
</script>

The last line “”ajax_paginate”) %>” will generate your pagination links

Voila, You are done!

Polymorphic Associations in Rails3

ror31In polymorphic associations, a model can belong to more than one model, on a single association.

Here is an example where a model is associated with two other models in Rails3. For example we have Events and Article model which have comments. So the “Comment” model is common between the “Event” and “Article” model. Here are the steps to implement the polymorphic association between these three models.

Step#1
Let’s create a resource “Comment” by rails generator.

rails g scaffold Comment content:text

Step#2

Add associations in the models as below

Comment model:

class Comment < ActiveRecord::Base
attr_accessible :commentable_id, :commentable_type, :content
belongs_to :commentable, :polymorphic => true  #Now, it is acted as polymorphic
end

Event model:

class Event < ActiveRecord::Base
attr_accessible :name
has_many :comments, :as => :commentable
end

Article model:

class Article < ActiveRecord::Base
attr_accessible :name
has_many :comments, :as => :commentable
end

Step#3

Add the following attributes in the migration files of the comment model

Look for newly created file under “db/migrate” folder

class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.text :content
t.references :commentable, :polymorphic => true
t.timestamps
end
end
end

Then execute rake db: migrate in the command line

Step#4

Add nested resources inside the “config/routes.rb” file

resources :events  do
resources :comments
end
resources :articles do
resources :comments
end

Step#5

Add link to add new comments in view page of article and events as follows

In “/app/views/events/show.html.erb”

<%= link_to 'New comment', new_event_comment_path(@event)  %>

In /app/views/articles/show.html.erb

<%= link_to 'New comment', new_article_comment_path(@article)  %>

Step#6

Changing the form_for tag in new comment page

In “/app/views/comments/_form.html.erb”

Before

<%= form_for (@comment) do |f| %>

After

<%= form_for [@commentable, @comment] do |f| %>

Add following codes in both “Articles” & “Events” controllers to get the comments individually

In “/app/controllers/events_controller.rb”

def show
@event = Event.find(params[:id])
@comments= @event.comments #added to view all the comments for the selected event
respond_to do |format|
format.html # show.html.erb
format.json { render json: @event }
end
end

In “/app/controllers/articles_controller.rb”

def show
@article = Article.find(params[:id])
@comments= @article.comments #added to view all the comments for the selected article
respond_to do |format|
format.html # show.html.erb
format.json { render json: @article }
end
end

Step#8

Add the following codes to “Comments” controller to creating a comment

In “/app/controllers/comments_controller.rb”

class CommentsController < ApplicationController
def new
@commentable = find_commentable
@comment = Comment.new
end
def create
@commentable = find_commentable
@comment = @commentable.comments.build(params[:comment])
if @comment.save
flash[:notice] = "Successfully created comment."
redirect_to :id => nil
else
render :action => 'new'
end
end
 
private
 
def find_commentable
params.each do |name, value|
if name =~ /(.+)_id$/
return $1.classify.constantize.find(value)
end
end
nil
end
end

Now the comment model will work as a polymorphic association between article and event model.

How to cut down Amazon Web Services (AWS) billing?

Amazon_S3_online_servicesAndolasoft is specialized in providing Cloud Computing services to its customers. Here we have a huge team of skilled personnel to provide monitoring and support services for 24×7 across the world.

As a technology partner with Amazon Web Services, we would like to share some features as well as some useful tips about controlling the AWS billing cost.

What is Cloud Computing?

Integrating computing resources with World Wide Web to provide remote IT Infrastructure facilities is Cloud Computing. It’s an option to replace traditional IT infrastructures with virtual networking for faster job processing and higher productivity at lower costs.

What is AWS?

Amazon is providing similar IT infrastructure services as a web service, popularly known as Amazon Web Services or AWS. Currently it is providing services to millions of businesses in more than 190 countries.
Features that makes AWS unique in public cloud

  • Auto Scaling

Number of Amazon EC2 instances can be scaled dynamically or by user defined schedule to increase or decrease them automatically depending on the demand. You will receive notifications to initiate Auto Scaling actions, or when Auto Scaling completes an action. Auto scaling feature can be used via APIs or Command Line Tools with no additional fees.

  • Amazon Cloud Front and it’s Functionalities

Amazon Cloud Front is a web service to distribute contents to end users at high speed .Here you can store the original version of your files on one or more origin servers and configure them by using URL pattern matches to specify which origin has what contents. You can use distribution’s domain name in your web pages or application so when users request an object using this domain name, they are automatically routed to the nearest location to deliver your contents.

  • AWS Identity and Access Management (IAM)

Manage IAM users and their access- Identity and Access Management (IAM) offers greater security, flexibility, and control when using AWS. IAM enables you to create users in AWS and manage access to AWS services and resources for your users. It also enables you to grant access to users managed outside AWS. You can assign individual security credentials (access keys, password, Authentication devices) or request temporary security credentials to provide users access to AWS services.

Manage IAM roles and their permissions- You can create roles in IAM and manage permissions to grant specific operations to the entities.Manage access for federated users- You can enable identity federation to allow users to access the AWS Management Console, without creating an IAM user for each identity. It is done by requesting temporary security credentials. This temporary security credentials are comprised of short lived access keys and session tokens associated with them. Users can use the access keys the same way as before, but they also have to pass the token . They can further be restricted by specifying explicit permissions while creating them. Any number of temporary security credentials can be issued.

  • IAM provides the following access controls:

Fine-grained access control to your AWS resources: IAM enables you to add specific conditions to control how a user can use AWS, such as time of day, their IP address, by using SSL, or authenticating with a Multi-Factor Authenticationdevice.Identity federation between your enterprise and AWS services: IAM can be used to grant employees, and applications access to AWS Management Console and AWS service APIs, using existing identity systems.

Mobile and browser-based applications: Mobile and browser-based applications can also be enabled to access specific AWS resources using temporary security credentials for a configurable period of time.

Tips to cut down AWS Billing:

  • Use AWS reserved instance for long running projects and spot instances for short term projects.
  • Use AWS private IP for data transfer between instances.
  • Use AWS Rout53 DNS to reduce Elastic IP usages.
  • Use Linux based Instances.
  • AWS recently lunched Glacier which offers $0.01 per GB / month only. Use Glacier for data storage instead of S3 to reduce the price of S3.

Planning anything on AWS? Talk to our Experts