bug fix : gestion des hosts recu par IP ou hostname

git-svn-id: http://svn.centreon.com/Plugins/Dev@3047 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
Mat Sugumaran 2007-08-24 16:15:58 +00:00
parent 1266d25472
commit 2c01040c24
2 changed files with 144 additions and 141 deletions

View File

@ -2,7 +2,7 @@
################################################################### ###################################################################
# Oreon is developped with GPL Licence 2.0 # Oreon is developped with GPL Licence 2.0
# #
# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt # GPL License: http://www.gnu.org/licenses/gpl.txt
# #
# Developped by : Mathavarajan Sugumaran - msugumaran@merethis.com # Developped by : Mathavarajan Sugumaran - msugumaran@merethis.com
# Julien Mathis - Romain Le Merlus # Julien Mathis - Romain Le Merlus
@ -79,7 +79,7 @@ sub main() {
}else { }else {
$values[3] = "no output for trap!"; $values[3] = "no output for trap!";
} }
print FILE "EXEC ".$NAGIOS_TRAPS."trapHandler \$aA \$o \"$values[3]\"\n"; print FILE "EXEC ".$NAGIOS_TRAPS."trapHandler \$aA \$A \$o \"$values[3]\"\n";
if (defined($values[4])) { if (defined($values[4])) {
print FILE "SDESC\n".$values[4]; print FILE "SDESC\n".$values[4];
if ($values[4] =~ /\n$/) { if ($values[4] =~ /\n$/) {
@ -132,3 +132,4 @@ sub main() {
} }
main(); main();

View File

@ -34,8 +34,8 @@ require "@INSTALL_DIR_OREON@/ODS/etc/conf.pm";
## GET HOSTNAME FROM IP ADDRESS ## GET HOSTNAME FROM IP ADDRESS
# #
sub get_hostinfos($$){ sub get_hostinfos($$$){
my $sth = $_[0]->prepare("SELECT host_name FROM host WHERE host_address='$_[1]' "); my $sth = $_[0]->prepare("SELECT host_name FROM host WHERE host_address='$_[1]' OR host_address='$_[2]'");
$sth->execute(); $sth->execute();
my @host; my @host;
while (my $temp = $sth->fetchrow_array()) { while (my $temp = $sth->fetchrow_array()) {
@ -140,14 +140,15 @@ sub get_servicename($$$) {
## GET HOSTNAME AND SERVICE DESCRIPTION ## GET HOSTNAME AND SERVICE DESCRIPTION
# #
sub getTrapsInfos($$$){ sub getTrapsInfos($$$$){
my $ip = shift; my $ip = shift;
my $hostname = shift;
my $oid = shift; my $oid = shift;
my $arguments_line = shift; my $arguments_line = shift;
my $dsn = "dbi:mysql:$mysql_database_oreon"; my $dsn = "dbi:mysql:$mysql_database_oreon";
my $dbh = DBI->connect($dsn, $mysql_user, $mysql_passwd) or die "Echec de la connexion\n"; my $dbh = DBI->connect($dsn, $mysql_user, $mysql_passwd) or die "Echec de la connexion\n";
my @host = get_hostinfos($dbh, $ip); my @host = get_hostinfos($dbh, $ip, $hostname);
foreach(@host) { foreach(@host) {
my $this_host = $_; my $this_host = $_;
my ($status, @servicename) = get_servicename($dbh, $oid, $_); my ($status, @servicename) = get_servicename($dbh, $oid, $_);
@ -171,7 +172,8 @@ sub getTrapsInfos($$$){
# #
if (scalar(@ARGV)) { if (scalar(@ARGV)) {
my $ip = $ARGV[0]; my $ip = $ARGV[0];
my $oid = $ARGV[1]; my $hostname = $ARGV[1];
my $arguments = $ARGV[2]; my $oid = $ARGV[2];
getTrapsInfos($ip, $oid, $arguments); my $arguments = $ARGV[3];
getTrapsInfos($ip, $hostname, $oid, $arguments);
} }