#!/usr/bin/perl -w # -*- perl -*- use strict; package CHIRP::CHIRP; use lib::Identify; use lib::Lowercase; use lib::Parse; use lib::WriteConfig; sub GenConfig { my($hostname, $community, $snmp_port, $idfile, $sitefile) = @_; my($config); my($deviceTable) = {}; if(!defined($hostname)) { print STDERR "ERROR: Hostname must be specified in call to CHIRP::GenConfig\n"; return undef; } if(!defined($community)) { $community = "public"; } if(!defined($snmp_port)) { $snmp_port = "161"; } if(!defined($idfile)) { $idfile = "Id.cfg"; } $deviceTable = CHIRP::Identify::Identify($hostname, $community, $snmp_port, $idfile); if(!defined($deviceTable) || !defined($deviceTable->{module}) || !defined($deviceTable->{package}) || !defined($deviceTable->{options})) { print STDERR "ERROR: lib::CHIRP::Identify failed to return valid device table.\n"; return undef; } eval " use $deviceTable->{module}; "; if($@) { print STDERR "ERROR: Failed to load module $deviceTable->{module}\nERROR: Error was " . $@ . "\n" if $@; return undef; } eval " \$config = " . $deviceTable->{package} . "::GenConfig(\$hostname, \$community, \$snmp_port, \$deviceTable->{options});"; print STDERR $@ if $@; if(!defined(CHIRP::Lowercase::LowercaseConfig(\$config))) { print STDERR "ERROR: Failed to properly lowercase configuration\n"; return undef; } if(defined($sitefile)) { if(!defined(CHIRP::Parse::GenConfig(\$config, $sitefile))) { print STDERR "ERROR: Failed to parse file: $sitefile\n"; return undef; } } return $config; } 1;