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', 'notthepassword') 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 pluginoutput/ ); #Nagios::History->columns( All => qw/serial server epoch servicedesc pluginoutput/ ); 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 didn'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 "::<<<<<<<<<<<<## ******************** ::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:: <<<<<<<<<<<< ::<<<<<<<<<<<<## 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) #### # 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