Category Archives: Perl

Perl, the duct tape of the Internet. Posts about Perl development, releases of my CPAN modules, etc.

Nagios plugin to monitor 3ware/LSI RAID

I wrote a basic Nagios plugin named nagios_3ware_raid_check to monitor the status of RAID arrays on 3ware/LSI hardware RAID controllers, but it was pretty limited.

Today I got a chance to improve it as I needed it for some machines at work; it now automatically figures out which card(s) are present, and checks the status of each RAID array on it. This means you don’t need to configure it to know which card number and unit to monitor, it just Does The Right Thing.

It uses the tw_cli utility available from the LSI website, which supports a wide range of 3ware/LSI RAID cards.

Example:

[dave@rasputin:~]$ /usr/local/bin/nagios_3ware_raid_check -v
Card 6 is a 8006-2LP
Unit u0 on card6 is a RAID-1 array of 931 GB and is OK
RAIDCHECK OK - Card 6 unit u0 RAID-1 OK (931GB)

When actually using it from Nagios, don’t use the -v (verbose) option – just use something like the following in nrpe_local.cfg:

# Monitor RAID status
command[check_raid]=/usr/local/bin/nagios_3ware_raid_check

Configuring CPAN.pm to use sudo to install

For security, I like to run CPAN.pm as a normal user so building & testing modules are all performed as a user rather than root, but of course the final installation needs to be done as root so that files can be copied to paths not writeable by normal users.

I always forget the options I need, so for my future reference as well as anyone else who finds it useful:

o conf make_install_make_command 'sudo make'
o conf mbuild_install_build_command 'sudo ./Build'

That means that the actual installation gets run via sudo, with everything else just being done as the user you started the CPAN client as.

(Of course, these days, you could also use cpanm (cpanminus) with its –sudo option…)

Debugging WWW::Mechanize scripts – printing requests and responses

Just for fast and easy reference really, but for easy debugging to find out the exact HTTP requests being sent and HTTP responses received by a web-scraping script using the excellent WWW::Mechanize, you can simply add:


$mech->add_handler("request_send", sub { shift->dump; return });
$mech->add_handler("response_done", sub { shift->dump; return });

This will cause all HTTP requests and responses to be output, so you can see exactly what’s happening.

CPAN Testers FAQ

David Golden recently pointed out (based on an IRC discussion) that the CPAN Testers FAQ isn’t particularly easy to find and doesn’t show up well in search results, so I’m posting this just to do my bit to make it a little easier to find.

It covers such questions as:

  • “How can I indicate that my distribution only works on certain versions of Perl?”
  • “How can I indicate that my distribution only works on a particular operating system?”
  • “How can I stop getting FAIL reports for missing libraries or other non-Perl dependencies?”
  • “How do I contact a tester?”
  • “How do I stop getting these reports?”

So, if you need an answer to any of those questions, head on over to the CPAN Testers FAQ where you’ll find your answer.

It would be helpful if the FAQ contained named anchors so that I could link to the answer for each of those questions above, actually.

Dancer::Plugin::Database 1.00 released

I’ve just released Dancer::Plugin::Database 1.00 to CPAN. This includes Alan Haggai’s patch to supply runtime configuration info to the database keyword as a hashref (thanks, Alan!) which was already released as a developer release, 0.91_01.

I’ve bumped the version to 1.00 to indicate that I consider it stable and ready for use in production, for those users who mistrust any module with a 0.xx version number.

Perl advent calendars

It’s quite common in the Perl community to produce advent calendars, hosting an article per day in the run-up to Christmas – several projects do this, along with a few prolific authors.

This year, the Dancer Perl web micro-framework (a project I contribute to) joins the party, with the PerlDancer Advent Calendar 2010! We decided it would be wrong to not have the Dancer advent calendar powered by a Dancer app – dogfooding in action :)

Here’s other calendars I’m aware of (if you know of any I’m missing, feel free to let me know and I’ll update the post!)

And more that I’m not yet sure are going to run a calendar this year or not:

Dancer::Plugin::MPD released

I recently wrote Dancer::Plugin::MPD, a simple plugin to make it easy to talk to MPD (Music Player Daemon) from Dancer-powered webapps in Perl.

It uses Jerome Quelin’s excellent Audio::MPD – it simply provides an mpd keyword which returns a connected Audio::MPD object (connecting first, if we didn’t have a connection or it went away, otherwise keeping the connected object cached).

It makes for code as simple as this example from DancerJukebox:

get '/control/skip' => sub { mpd->next; redirect '/'; };

Dancer::Plugin::DebugDump released

I recently released a dead-simple plugin for Dancer – Dancer::Plugin::DebugDump.

During development, I fairly often find myself using Data::Dump to dump stuff to the debug log (which I usually have set to ‘console’, so it appears in the terminal I’m running the app from), with code like:

use Data::Dump qw(dump);
debug("Random hashref: " . dump($hashref) );

I got fed up with writing that, so I wrote Dancer::Plugin::DebugDump, which lets you say:

# give it a label and a reference/object:
debug_dump("Random hashref:" => $hashref);
# or just give it a reference/object:
debug_dump($someobject);

It’s not much of a saving, but it scratched an itch, and might possibly be useful to others.

DancerJukebox – music queuing Perl webapp powered by Dancer

I spent some of Friday night hacking on rewriting my music queuing webapp from Catalyst (which I wrote it in ages ago, before I discovered Dancer).

It only took a couple of hours of easy and actually fairly enjoyable coding to get it all ported over, and in the process I released two Dancer plugins – Dancer::Plugin::MPD to handle easily getting a working MPD connection, and Dancer::Plugin::DebugDump to easily dump objects and data structures to the debug log to simplify development.

This time round, the code is up on GitHub – DancerJukebox on GitHub. I never released the previous code, it was developed in a private Subversion repository, and I was never happy enough with it to release it.

The basic idea is that you fill the playlist with decent music and leave MPD playing on random. If people want to hear specific songs, they can use the web app to search for whatever they want and add them to a queue.

Continue reading DancerJukebox – music queuing Perl webapp powered by Dancer