hop fonctionnel et nettoyé... automatique a l'install avec fichier de conf pour mysql

git-svn-id: http://svn.centreon.com/Plugins/Dev@2456 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
Julien Mathis 2007-06-06 21:03:35 +00:00
parent c30f7e7d00
commit cebfbab01a
2 changed files with 15 additions and 26 deletions

View File

@ -27,15 +27,8 @@ use strict;
use Getopt::Long; use Getopt::Long;
use DBI; use DBI;
############################# use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd);
## SET DATABASE CONFIGURATION require "@OREON_PATH@/ODS/etc/conf.pm";
#
sub set_db {
require "@OREON_PATH@/ODS/etc/conf.pm"
my $dsn = "dbi:mysql:database=$mysql_database_oreon;host=$mysql_host";
return $dsn, $mysql_user, $mysql_passwd;
}
######################################### #########################################
## TEST IF OID ALREADY EXISTS IN DATABASE ## TEST IF OID ALREADY EXISTS IN DATABASE
@ -72,10 +65,12 @@ sub getStatus($$) {
################ ################
## MAIN FUNCTION ## MAIN FUNCTION
# #
sub main($$) { sub main($$) {
my $manuf = $_[1]; my $manuf = $_[1];
my @db = set_db();
my $dbh = DBI->connect($db[0], $db[1], $db[2]) or die "DB connexion error\n"; my $dsn = "dbi:mysql:$mysql_database_oreon";
my $dbh = DBI->connect($dsn, $mysql_user, $mysql_passwd) or die "Echec de la connexion\n";
if (!open(FILE, $_[0])) { if (!open(FILE, $_[0])) {
print "Cannot open configuration file : $_[0]\n"; print "Cannot open configuration file : $_[0]\n";
exit; exit;

View File

@ -27,15 +27,8 @@ use strict;
use Getopt::Long; use Getopt::Long;
use DBI; use DBI;
############################# use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd);
## SET DATABASE CONFIGURATION require "@OREON_PATH@/ODS/etc/conf.pm";
#
sub set_db {
require "@OREON_PATH@/ODS/etc/conf.pm"
my $dsn = "dbi:mysql:database=$mysql_database_oreon;host=$mysql_host";
return $dsn, $mysql_user, $mysql_passwd;
}
###################################### ######################################
## Get snmptt configuration files path ## Get snmptt configuration files path
@ -54,17 +47,18 @@ sub getPath($) {
sub main() { sub main() {
print "Generating SNMPTT configuration files...\n"; print "Generating SNMPTT configuration files...\n";
my ($nbMan, $nbTraps) = (0,0); my ($nbMan, $nbTraps) = (0,0);
my @db = set_db();
my $dbh = DBI->connect($db[0], $db[1], $db[2]) or die "Echec de la connexion mysql\n"; my $dsn = "dbi:mysql:$mysql_database_oreon";
my $dbh = DBI->connect($dsn, $mysql_user, $mysql_passwd) or die "Echec de la connexion\n";
my $confFiles_path = getPath($dbh); my $confFiles_path = getPath($dbh);
my $sth = $_[0]->prepare("SELECT nagios_path_plugins FROM general_opt LIMIT 1"); my $sth = $dbh->prepare("SELECT nagios_path_plugins FROM general_opt LIMIT 1");
$sth->execute(); $sth->execute();
my $conf = $sth->fetchrow_array(); my @conf = $sth->fetchrow_array();
$sth->finish(); $sth->finish();
my $NAGIOS_TRAPS = $conf->{'nagios_path_plugins'}."traps/"; my $NAGIOS_TRAPS = $conf[0]."traps/";
my $sth = $dbh->prepare("SELECT id, name from inventory_manufacturer"); $sth = $dbh->prepare("SELECT id, name from inventory_manufacturer");
$sth->execute(); $sth->execute();
my $snmpttIni = ""; my $snmpttIni = "";
while (my ($man_id, $man_name) = $sth->fetchrow_array()) { while (my ($man_id, $man_name) = $sth->fetchrow_array()) {