naChoZ has asked for the wisdom of the Perl Monks concerning the following question:

Update: marked "solved"

I'm writing some perl to parse nagios logs and populate a postgresql db. It's not working, the db does not populate, but it does not generate any error messages at all.

Here's the relevent code. I left some of the commented lines to demonstrate some of the things I've tried. (Yes, I'm aware of the deficiencies like the column types, sequences, etc, I'm just trying to get this working first with a minimum of distractions.)

./Nagios.pm

package Nagios::DBI; use base 'Class::DBI::Pg'; # tried w/ and w/out the Pg Nagios::DBI->set_db('Main', 'dbi:Pg:dbname=nagios', 'nagios', 'notthep +assword') or die "quitting: $!\n"; package Nagios::History; use base 'Nagios::DBI'; Nagios::History->table('history'); Nagios::History->columns( Primary => qw/serial/ ); Nagios::History->columns( Other => qw/server epoch servicedesc plugino +utput/ ); #Nagios::History->columns( All => qw/serial server epoch servicedesc p +luginoutput/ ); 1;

#!/usr/local/bin/perl -w use strict; use Data::Dumper; $Data::Dumper::Indent = 1; use File::Slurp "read_file"; require "./Nagios.pm"; my $logfile = "/usr/local/var/nagios/archives/nagios-05-26-2004-00.log +"; my @dataLofH = read_data( $logfile ) or die "Can't read data from $logfile: $!\n"; #print $dataLofH[3]->{'pluginoutput'}; foreach ( @dataLofH ) { #print "********************\n::begin foreach>>>>>>>>>\n"; #print "::begin show vars in default hash::\n>>>>>>>>\n"; #print $_->{'serial'}, "::end ser::\n"; #print $_->{'epoch'}, "::end epoch::\n"; #print $_->{'server'}, "::end server::\n"; #print $_->{'pluginoutput'}, "::end pluginoutput::\n"; #print $_->{'servicedesc'}, "::end servicedesc::\n"; #print "\n<<<<<<<<<\n::end show vars in default hash::\n"; print "::begin default deref before update::\n>>>>>>>>>>>>\n"; print Dumper( %{$_} ); print "<<<<<<<<<<<<<<\n::end default deref ::\n"; #my $history_entry = Nagios::History->create({ # serial => $_->{'serial'}, # epoch => $_->{'epoch'}, # server => $_->{'server'}, # pluginoutput => $_->{'pluginoutput'}, # servicedesc => $_->{'servicedesc'} #}) or die "can't do create: $!\n"; my $history_entry = Nagios::History->create({ %{$_} }); #tried throwing in the update method to see if that helped. It di +dn't. print "::begin history_entry before update::\n>>>>>>>>>>>>\n"; print Dumper( $history_entry ); print "::end history_entry before update::\n<<<<<<<<<<<<\n"; $history_entry->update or die "can't do update: $!\n"; print "::begin history_entry after update ::\n>>>>>>>>>>>>\n"; print Dumper( $history_entry ); print "::end history_entry after update::\n<<<<<<<<<<<<\n"; print "::<<<<<<<<<<<<<end foreach::\n**************\n\n\n\n"; }

And some sample output...

******************** ::begin foreach>>>>>>>>> ::begin default deref before update:: >>>>>>>>>>>> $VAR1 = 'serial'; $VAR2 = 110; $VAR3 = 'pluginoutput'; $VAR4 = '2.00 1.99 1.82'; $VAR5 = 'servicedesc'; $VAR6 = 'ssh_check_load'; $VAR7 = 'epoch'; $VAR8 = '1085543957'; $VAR9 = 'server'; $VAR10 = 'hephaestus.gwi.net'; <<<<<<<<<<<<<< ::end default deref :: ::begin history_entry before update:: >>>>>>>>>>>> $VAR1 = bless( { 'serial' => 110 }, 'Nagios::History' ); ::end history_entry before update:: <<<<<<<<<<<< ::begin history_entry after update :: >>>>>>>>>>>> $VAR1 = bless( { 'serial' => 110, '__Changed' => {} }, 'Nagios::History' ); ::end history_entry after update:: <<<<<<<<<<<< ::<<<<<<<<<<<<<end foreach:: **************

Oh, and the database info:

nagios=> \dt List of relations Schema | Name | Type | Owner --------+------------------+-------+-------- public | history | table | nagios nagios=> \dhistory Table "public.history" Column | Type | Modifiers --------------+-------------------+----------- server | character varying | servicedesc | character varying | pluginoutput | character varying | epoch | character varying | serial | character varying | not null Indexes: history_pkey primary key btree (serial) nagios=> select * from history; server | servicedesc | pluginoutput | epoch | serial --------+-------------+--------------+-------+-------- (0 rows)

And some version info:

# uname -sr FreeBSD 4.9-RELEASE-p4 # perl -v This is perl, v5.6.1 built for i386-freebsd # pkg_info -I -x postgres postgresql-7.3.4_1 # pkg_info -I -x Class-DBI p5-Class-DBI-0.95 p5-Class-DBI-Pg-0.03_1 # pkg_info -I -x p5-DBI p5-DBI-1.42

Anyone able to see what I might be doing wrong?

--
Diplomacy is the art of saying "Nice doggie" until you can find a rock.
naChoZ

Replies are listed 'Best First'.
Re: Class::DBI trouble with create method
by perrin (Chancellor) on Jun 03, 2004 at 15:48 UTC
    I don't see you calling commit anywhere. Add a call to Nagios::History->dbi_commit() and see if that does it.

      Well, when you run commit, it says it's deprecated and to use update. update still didn't do anything for me, though. However, I found the wiki and solution #2 did the trick.

      --
      Diplomacy is the art of saying "Nice doggie" until you can find a rock.
      naChoZ

        No, not commit, dbi_commit.
Re: Class::DBI trouble with create method
by eXile (Priest) on Jun 03, 2004 at 15:50 UTC
    Maybe some troubleshooting tips will help you going:

    perl -d: Set a breakpoint ('b <linenumber>' in the debugger) just before the  $history_entry = Nagios::History->create({ %{$_} }); statement, and singlestep ('s' in the debugger) to see what is happening in detail.

    dbi profiling: DBI profiling can be 'misused' to see if any queries go to the database. Read the DBI::Profile manpage for details, or just do DBI_PROFILE=2 script.pl. This should give you some output on the queries that are done to the database.