[jifty-devel] Jifty::DBI manpage buglet and a candidate for a FAQ
David Good
dgood at willingminds.com
Tue May 22 13:23:05 EDT 2007
On Tue, May 22, 2007 at 02:43:15AM +0200, Andreas J. Koenig wrote:
> I have completed the Jifty::Manual::Tutorial and after that I had the
> desire to see the content of the database with Jifty's own means, not
> in the browser but in perl. So I took the Synopsis of the
> Jifty::DBI::Collection manpage and adjusted the filename and tried to
> guess the rest. Apparently the manpage has the capitalization wrong? I
> then did adjust the driver and database parameters to lowercase but I
> could not figure out how to use Jifty::DBI directly. I won't bother
> you with all the wrong solutions I tried:-/
>
> Can somebody post a solution?
I needed the same thing last week and managed to figure it out by taking
bits and pieces from various places like the jifty script and a couple
of modules. My application is named Threshedit and sets thresholds for
a Nagios installation. In the example below, it uses two tables
implemented as Jifty::Models -- Server and DiskThresh.
Here's what I came up with:
#!/usr/local/bin/perl
use strict;
use warnings;
use UNIVERSAL::require;
use Jifty::ClassLoader ();
use Getopt::Long;
BEGIN {
Jifty::Util->require or die $UNIVERSAL::require::ERROR;
my $root = Jifty::Util->app_root;
unshift @INC, "$root/lib" if ($root);
}
use Jifty;
my $cl = new Jifty::ClassLoader(base => 'ThreshEdit');
$cl->require;
my $j = new Jifty; # sets up database connection and other stuff
my $server = "";
my $disk;
my $warn;
my $crit;
my $inherit;
GetOptions(
"server=s" => \$server,
"disk=s" => \$disk,
"warn=s" => \$warn,
"crit=s" => \$crit,
"inherit!" => \$inherit,
) or die "Usage...\n";
die "Hey, no arguments!\n" if @ARGV;
unless ($server){
die "need a server\n";
}
unless ($disk){
die "need a disk\n";
}
if ((defined($warn) and not defined($crit))
or (defined($crit) and not defined($warn))){
die "If you give me one, you've got to give me the other...\n";
}
if (defined($warn)){
$inherit = 0 unless defined($inherit);
}
else {
$inherit = 1 unless defined($inherit);
}
my $s = ThreshEdit::Model::Server->new(handle => Jifty->handle);
$s->load_by_cols(name => $server);
die "Can't find server '$server'\n" unless $s->id;
my $t = ThreshEdit::Model::DiskThresh->new(handle => Jifty->handle);
my ($id, $status_msg) = $t->create(
server => $s,
disk_label => $disk,
warning => $warn,
critical => $crit,
inherit => $inherit,
);
More information about the jifty-devel
mailing list