From e86389d7be5cd9e780b3b7d04316133bbbaafacf Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 29 Mar 2006 12:34:16 +0000 Subject: [PATCH] Begin moving passwords etc. into a common module. --- clients/snmpfetch.pl | 6 ++++-- include/config.pm | 14 ++++++++++++++ include/nms.pm | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 include/config.pm create mode 100644 include/nms.pm diff --git a/clients/snmpfetch.pl b/clients/snmpfetch.pl index fa50f60..b02f021 100755 --- a/clients/snmpfetch.pl +++ b/clients/snmpfetch.pl @@ -8,11 +8,13 @@ use strict; use warnings; require 'SNMP_Session.pm'; +use lib '../include'; +use nms; + my $password = 'removed'; my $timeout = 15; -my $dbh = DBI->connect("dbi:Pg:dbname=nms;host=localhost", "nms", "nms") - or die "Couldn't connect to database"; +my $dbh = nms::db_connect(); $dbh->{AutoCommit} = 0; # normal mode: fetch switches from the database diff --git a/include/config.pm b/include/config.pm new file mode 100644 index 0000000..af5fa79 --- /dev/null +++ b/include/config.pm @@ -0,0 +1,14 @@ +#! /usr/bin/perl +use strict; +use warnings; +use DBI; +package nms::config; + +# Don't change this file for your local setup; use config.local.pm instead. + +our $db_name = "nms"; +our $db_host = "localhost"; +our $db_username = "nms"; +our $db_password = "nms"; + +1; diff --git a/include/nms.pm b/include/nms.pm new file mode 100644 index 0000000..bfb88ad --- /dev/null +++ b/include/nms.pm @@ -0,0 +1,24 @@ +#! /usr/bin/perl +use strict; +use warnings; +use DBI; +package nms; + +BEGIN { + require "config.pm"; + eval { + require "config.local.pm"; + }; +} + +sub db_connect { + my $dbh = DBI->connect("dbi:Pg:" . + "dbname=" . $nms::config::db_name . + ";host=" . $nms::config::db_host, + $nms::config::db_username, + $nms::config::db_password) + or die "Couldn't connect to database"; + return $dbh; +} + +1; -- 2.39.2