Class::DBI method->search confusion (long)

[prev] [thread] [next] [Date index for 2004/06/11]

From: ah71
Subject: Class::DBI method->search confusion (long)
Date: 14:47 on 11 Jun 2004
I've been poring over the docs but I'm having trouble wrapping my brain around this.  Could someone tell me what I'm doing wrong?

Here it is right from the postgresql cli.

nagios=> select * from distinct_services where server = 'server1';
  servicedesc   |  server
----------------+-----------
 POP            | server1
 apan_ping      | server1
 ssh_check_load | server1
(3 rows)

All I want to do is pull the servicedesc into a list.  That's it.  One thing that's happening is, for instance, for server1, instead of producing, POP, apan_ping, and ssh_check_load in a list, it produces POP, POP, POP.  If a server only has two services, say POP and ssh_check_load, it comes back with POP, POP for the list.  The script's purpose is to parse the nagios history logs into a format that orca will be able to use and make graphs from the data.

Here are the relevent code bits.

---> from main

# {{{ data dump
#

if ( $opt_d ) {
    my @servernames = Nagios::History::Servers->list( 'all' );

    if ( @opt_x ) {
        @servernames = excludes( @servernames );
    }

    foreach my $current_server ( @servernames ) {
        my @servicenames = Nagios::History::Services->list( $current_server );
        foreach my $current_service ( @servicenames ) {
            print "   server/service $current_server / $current_service\n";
            # dump_history does nothing at the moment
            Nagios::History->dump_history( $current_server, $current_service );
        }
    }
}

# }}}




---->from the module I starting concocting:

# {{{ Nagios::DBI
#
package Nagios::DBI;

    use base 'Class::DBI::Pg';

    my $user    = "mydbuser";
    my $pw      = "notthepassword" ;
    my $DSN     = "dbi:Pg:dbname=mydb";

    Nagios::DBI->set_db( 'Main', $DSN, $user, $pw, {AutoCommit=>1} ) 
        or die "quitting: $!\n";

# }}}

package Nagios::History;

    use base 'Nagios::DBI';

    sub list {
        my $class = shift;
        __PACKAGE__->table( $class->use_table );
        __PACKAGE__->columns( All => $class->use_columns );
        my $SearchObj;
        my @ServiceList;
        my @returnlist;
        my ( @SearchObj ) = __PACKAGE__->search( server => $_[0] );

    foreach my $iterator ( @SearchObj ) {
        push @ServiceList, $iterator;
    }

    sub dump_history {
        #
        # history dumper
        #
        
        my $class           = shift;
        my $current_server  = shift;
        my $current_service = shift;
        #does nothing right now....
    } 



# {{{ Nagios::History::Servers
#
package Nagios::History::Servers;

    use base 'Nagios::History';

    sub use_table { 'distinct_servers' }
    sub use_columns { qw/server/ }

# }}}


# {{{ Nagios::History::Services
#
package Nagios::History::Services;

    use base 'Nagios::History';

    sub use_table { 'distinct_services' }
    sub use_columns { qw/servicedesc server/ }
    sub use_searchcol { 'server' }

# }}}



Version info:
# perl -v
This is perl, v5.6.1

# uname -sr
FreeBSD 4.9-RELEASE-p4

# postgres --version
postgres (PostgreSQL) 7.3.4

# pkg_info -I -x Class-DBI
p5-Class-DBI-0.95   Simple Database Abstraction
p5-Class-DBI-Pg-0.03_1 Extensions to Class::DBI for PostgreSQL

Class::DBI method->search confusion (long)
ah71 14:47 on 11 Jun 2004

Re: Class::DBI method->search confusion (long)
Perrin Harkins 16:18 on 11 Jun 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52