Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL-question in netdisco

Status
Not open for further replies.

hanzonizer

Programmer
Joined
Apr 16, 2007
Messages
10
Location
SE
Hi!
I don´t know if anyone has worked with netdisco (open source webbased networkdatabase), but I´m having problem writing a code that can ask a SQL-question (Postgre SQL) and retrieve the answer to a file. So far I have written this code:
Code:
#! /usr/bin/perl -w
#
# Usage: 
# Fetch IP-adresses from routers that the script
# show_mac_ip needs to be run on (for reading MAC-adresses to netdisco)
#

use netdisco qw/:all/;
use netdisco::DB;


$matches = sql_rows('device_port',['ip'],{'up' => 'up'});
print $matches;

The intention is to write a SQL-question like: SELECT ip FROM device_port WHERE up = "up" AND vlan IS NOT NULL
(vlan = IS NOT NULL is not included here) but I only get an errormessage saying:
Can't locate netdisco/DB.pm in @INC (@INC contains: /etc/perl /usr/local/lib/per l/5.8.7 /usr/local/share/perl/5.8.7 /usr/lib/perl5 /usr/share/perl5 /usr/lib/per l/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at ./get_ip_adresses.pl li ne 9.
BEGIN failed--compilation aborted at ./get_ip_adresses.pl line 9.

I came to realize that the directories it searches DB.pm in does not exist on my installation of netdisco. How can you fix this? can u just move DB.pm to a valid directory, or do you need to specify it? I´m kind of new to this, and NOT a linux hacker, so please keep it simple :)

Regards /Jimmy
 
Forgot to mention this, but the reason I´m posting this question here is that the mailing list and documentation of netdiscos system and management isn´t that good. Mailing list posts at most one message a week, so I´m hoping for a quicker answer here...
 
Unfortunately that didn´t work. The lib pragma does it´s job, and the directory I added does contain DB.pm but the error message still tells me that it can´t locate DB.pm despite the fact that @INC now contains the directory where it is located.
Can there be any other problems with the code? Something other that I need to make it work.
 
Maybe you are getting the path wrong. Is DB.pm in the netdisco folder or in the netdisco/DB folder?

use lib "path/to/netdisco";
use DB;








------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hmm, I think it´s something of a path problem. My netdisco installation is in /usr/local/netdisco folder, although my DB.pm is not in the netdisco folder it is located in /usr/share/perl/5.8.7 (like most of all the other .pm-files) I have tried adding the last mentioned directory to @INC with the lib pragma, but I still get the same error message. Is it possible to move DB.pm to the netdisco-folder and see if it works there? *Confused*
 
I would think this should work:

use lib "/usr/share/perl/5.8.7"
use DB;

if not I am unsure why, maybe someone else will know something.





------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hmm.. tried to alter the code to see what happend, and the error message disappeared, but I get another one instead:

dbh() - db_Pg not found in config info.

The code now looks like this:

Code:
#! /usr/bin/perl 
#
# Usage: 
# Fetch IP-adresses from routers that the script
# show_mac_ip needs to be run on (for reading MAC-adresses to netdisco)
#

use warnings;
use lib "/usr/share/perl/5.8.7";
use netdisco qw/:all/;

$data = sql_rows('device_port',['ip'],{'up' => 'up'});
print $data;

Does anyone who have worked with netdisco know what I´m doing wrong?

 
I got help from another forum, but thanks for all the tips anyway!

/Jimmy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top