android (3)
ant (2)
beautifulsoup (1)
debian (1)
decorators (1)
django (9)
dovecot (1)
encryption (1)
fix (4)
gotcha (2)
hobo (1)
htmlparser (1)
imaplib (2)
java (1)
json (2)
kerberos (2)
linux (7)
lxml (5)
markdown (4)
mechanize (6)
multiprocessing (1)
mysql (2)
nagios (2)
new_features (3)
open_source (5)
optparse (2)
parsing (1)
perl (2)
postgres (1)
preseed (1)
pxe (4)
pyqt4 (1)
python (41)
raid (1)
rails (1)
red_hat (1)
reportlab (4)
request_tracker (2)
rt (2)
ruby (1)
scala (1)
screen_scraping (7)
shell_scripting (8)
soap (1)
solaris (3)
sql (2)
sqlalchemy (2)
tips_and_tricks (1)
twitter (2)
ubuntu (1)
vmware (2)
windows (1)
zimbra (2)

Nagios is a systems monitor that uses a variety of clients, pings, and port scans to check up on systems. Configuring Nagios can seem like daunting task at first glance because Nagios is so extensive. It's not hard as I'll show you.

I'm assuming that you've already downloaded, compiled, and installed Nagios and Nagios Plugins. If you haven't, consult this guide.

After installation, the first file you'll want to edit is main nagios.cfg, /usr/local/nagios/etc/nagios.cfg. You will add these three lines:


If you have a large amount of hosts, you may want to look into using the cfg_dir directive, with which you can specify a directory in which all files should be parsed as configuration files.

We'll now want to create /usr/local/nagios/etc/hostgroups.cfg. Hostgroups are logical groupings of hosts. They affect how hosts are displayed on the monitor's views and can also be used to attach monitoring for services common to the group. Let's create a few.

define hostgroup{
    hostgroup_name    linux-servers
    alias    Linux Servers

define hostgroup{
    hostgroup_name    windows-servers
    alias    Windows Servers

define hostgroup{
    hostgroup_name    web-servers
    alias    Web Servers

The hostgroup_name is what will be used to reference the hostgroup in the configuration. The alias is what appears on the web interface.

We have some hostsgroups define so we can attach templates to them. Edit /usr/local/nagios/etc/objects/templates.cfg. This file holds template definitions that we will use shortly to define hosts. Find linux-server in this file. It will looks like this:

define host{
    name    linux-server ; The name of this host template
    use    generic-host ; This template inherits other values from the generic-host template
    check_period    24x7 ; By default, Linux hosts are checked round the clock
    check_interval    5 ; Actively check the host every 5 minutes
    retry_interval    1 ; Schedule host check retries at 1 minute intervals
    max_check_attempts    10  ; Check each Linux host 10 times (max)
    check_command    check-host-alive ; Default command to check Linux hosts
    notification_interval    120 ; Resend notifications every 2 hours
    notification_options    d,u,r ; Only send notifications for specific host states
    contact_groups    admins ; Notifications get sent to the admins by default

Add this line within the curly braces:

hostgroups linux-servers

Every host we make using the linux-server template, will be a member of the linux-servers hostgroup. Find the windows-servers host and add a hostgroup windows-servers line to it as well.

We're ready to define hosts now.

Open /usr/local/nagios/etc/hosts.cfg and add these few lines:

define host{
    use linux-server
    hostgroups web-servers

define host{
    use windows-server

With use, we tell Nagios to implement a specific template when creating a host. The host_name is the host_name of the system. Nagios will do DNS lookups if no address is defined. You can define addition hostgroups the machine should belong to here or you can do it in the hostgroups.cfg with the members directive. You'll probably want to define your own hosts here instead of using my example hosts.

We almost have something useful. The last step is defining services and attaching them to hosts and hostgroups.

Create the /usr/local/nagios/etc/services.cfg and add these lines:

define service{
    use generic-service
    hostgroup_name linux-servers
    service_description SSH
    check_command check_ssh

define service{
    use generic-service
    hostgroup_name web-servers
    service_description HTTP
    check_command check_http

define service{
    use generic-service
    hostgroup_name windows-servers
    service_description RDP
    check_command check_tcp!3389

The hostgroup linux-servers is attached to the service SSH and Nagios will use check_ssh to monitor the service. This service will use the generic-service template, which defines items like timeouts. You may not be running ssh on the default port. You can tell check_ssh to use another port by giving it a -p argument, like so check_command check_ssh!-p 12345. Commands are defined in /usr/local/nagios/etc/objects/commands.cfg and the documentation for the plugins used in these commands is documented in man pages and on the Nagios Plugins site. You should be able to understand the rest of the service, as they don't vary much from SSH.

You have something functional. Before you go reloading the Nagios service, use this command to check your configuration syntax:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

The hardest part of Nagios is that it can be time consuming to define all the hosts and host-specific services to monitor. Using templates and hostgroups will save you hours.

Posted by Tyler Lesmann on November 24, 2008 at 7:57
Tagged as: linux nagios

In Request Tracker, a.k.a. RT, tickets that have a lot of correspondence tend to get long and hard to view with redundant email quotes. It's not hard to modify RT to make the quoted text collapsed. Here's how I did it with RT 3.8.3.

The first file to change is /opt/rt3/share/html/Ticket/Elements/ShowTransactionAttachments. Find these two lines and comment them out. RT handles quotes with arrow brackets and more with Text::Quoted by default. The handling is not appropriate as it will make too many levels in the quotes to handle easily. Commenting this code turns that off.

eval { require Text::Quoted;  $content = Text::Quoted::extract($content); };
if ($@) { $RT::Logger->warning( "Text::Quoted failed: $@" ) }

The next step is extending MakeClicky. Place the following code in /opt/rt3/local/html/Callbacks/MyCallbacks/Elements/MakeClicky/Default:

$types   => []
$actions => {}
my $web_path = RT->Config->Get('WebPath');

$actions->{'truncate_quotes'} = sub {
    my %args = @_;
    my $rid = int(rand(100000));
    my $color = 'A22';
    return '
        <a href="" id="show'.$rid.
        '" style="color: #'.$color.
        '; font-weight: bold;" onclick="Effect.toggle(\'quote'.$rid.
        '\', \'slide\'); return false;">Toggle quoted message</a>
        <div id="quote'.$rid.'" style="display: none;">'.$args{value}.'</div>

my @customtypes = (
        name   => "httpurl",
        regex  => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}/,
        action => "url",
        name   => "httpurl_overwrite",
        regex  => qr/$RE{URI}{HTTP}{-keep}{-scheme => 'https?'}/,
        action => "url_overwrite",
        name   => 'truncate_arrowq',
        regex  => qr/(^|\s)[>].*$/s,
        action => 'truncate_quotes',
        name   => 'truncate_outlookq',
        regex  => qr/\s-----Original Message-----.*$/s,
        action => 'truncate_quotes',
        name   => 'truncate_underscoreq',
        regex  => qr/\s_{5,}.*$/s,
        action => 'truncate_quotes',

push(@$types, @customtypes);

This is the bit that will wrap the quoted text in a hidden div that can be toggled to be shown by the user. This uses RT's own install of scriptaculous to add toggle effects.

Almost done. The last part is telling RT we what to use the clickable link extensions. You'll do this in the /opt/rt3/etc/ Just add this line to turn on the changes we made.

Set(@Active_MakeClicky, qw(truncate_arrowq truncate_outlookq truncate_underscoreq));

Restart the web server and you'll now have more manageable quotes.

UPDATE: No longer as much of a hack. I found notes on extending MakeClicky. RT has yet to update its documentation to say that the custom actions go in /opt/rt3/local/html/Callbacks/MyCallbacks/Elements/MakeClicky/Default.

Posted by Tyler Lesmann on November 21, 2008 at 7:55 and commented on 1 time
Tagged as: perl request_tracker rt