Category Archives: Computers

Network and Server Monitoring

One of my passions is automated monitoring and correction of network and server problems. I have the most experience with SiteScope (primarily a commercial website monitoring tool that has branched out to include protocols, application stacks, and whatever custom stuf you want) and Nagios, which is free and open source, and very very configurable.

I would LOVE to form a company implementing these or similar monitoring tools. I’ve done this a lot at work, and a little bit on the side for a few friends and their companies.

I’ve been looking around, and it seems that in addition to Nagios, two other contenders are Zenoss and Cacti. I’ve heard good things about Zenoss, specifically how it is easier to set up than Nagios. I think I may check it out, though I am a fan of Nagios’s flexibility.

Apache: Convert uppercase to lowercase

We had a requirement from a client whose windows website we were migrating to UNIX that the new site be able to handle mixed case tickers, ie, /pwc, /Pwc, /PWC, /pwC, etc. Using mod_rewrite, it was doable:

 # Take any mixed or uppercase ticker and set to lower
 RewriteMap lowercase int:tolower
 RewriteRule ^(/[A-Z]...?)$ ${lowercase:$1} [R,L]
 RewriteRule ^(/.[A-Z]..?)$ ${lowercase:$1} [R,L]
 RewriteRule ^(/..[A-Z].?)$ ${lowercase:$1} [R,L]
 RewriteRule ^(/...[A-Z])$ ${lowercase:$1} [R,L] 

This case conversion will be true for any 3 or 4 char URI with an uppercase letter. (It would probably be better to replace the “.” above with [a-zA-Z], as it’s likely intended for only chars to replace. Above will transform /a/BB as well, which is probably not desired.)

Neat Linux tip

Lots of times I have a need to make a backup of a file or such that I end up forgetting about and it sits around taking up disk space. Sometimes in annoyance of this, I have simply skipped making the backup, and have been burned by it. Finally I came up with this alternative:

  1. Make a directory on your desktop called DeleteIn2Weeks. In my case, the full path was /home/guytonw/Desktop/DeleteIn2Weeks
  2. Create the following cron entries:
    0 1 * * * find /home/guytonw/Desktop/DeleteIn2Weeks -mtime +14 -type f -exec echo Deleting {} \;
    1 1 * * * find /home/guytonw/Desktop/DeleteIn2Weeks -mtime +14 -type f -exec rm {} \;

This is nice because any files put in there will automatically be swept away after a sufficient amount of time. (Hopefully I won’t need the backup after 2 weeks’ time!)

Computer games from the past

Lately I’ve been playing Diablo 2 a lot. It came out in the year 2000, and is still selling on shelves today. Nicely enough, Blizzard has released patches over time that have added items and special game events for really high level characters, not to mention changing the dynamics of skill points. OK, OK, I’m geeking out here.

The main reason I started playing was because I did not want to buy a new laptop to play some of the newer games. One day I’ll break down, but it’s not necessary just yet… At any rate, it’s a lot of fun playing online!

Mod_perl2, apache2.2, and CGI::Ajax notes…

Following along in my mod_perl2 notes, I wanted to document how to get CGI::Ajax working with mod_perl2. I hit a couple of snags along the way that are worth noting. First, the generated javascript for my functions was calling httpd? + vars, rather than my URI /modperl_handler/ajax? + vars. This was frustrating, but I determined that it was grabbing httpd from $0, so I changed it locally and the script worked after that. The second snag I hit was because I was instantiating my CGImodule globally instead of locally, and I would get segfaults now and then. Instantiating it inside the handler was the right way to go. Here is a working example:

package AjaxTest;

use CGI;
use CGI::Ajax;

use Apache2::RequestRec();
use Apache2::RequestIO();
use Apache2::Const -compile => qw(OK);

sub handler {
    my ($r) = @_;

    my $cgi = new CGI;  # had this outside the handler and was getting segfaults

    # Have to redefine $0 for CGI::Ajax because it's used to call further URLs from
    # javascript ajax functions.  (otherwise it did "httpd?"...)
    local $0 = $ENV{"REQUEST_URI"};
    $0 =~ s/?.*//;

    # Start Ajax stuff
    my $pjx = new CGI::Ajax("test_ajax" => &test_ajax);
    # Don't compress javascript (1 for user fcns only, 2 for all)
    $pjx->JSDEBUG(1);
    # Send stderr to web logs
    $pjx->DEBUG(1);

    print $pjx->build_html( $cgi, &base_page);
    return Apache2::Const::OK;
}

sub base_page {
    return "Ajax mod_perl testmod_perl 2.0.2 on apache 2.2.2 rocks! <p><div id="test">Change me</div><p>nn";
}

sub test_ajax {
    my $time = time();
    return "Test successful; $time<p>";
}

1;