readable now :)
git-svn-id: http://svn.centreon.com/Plugins/Dev@2440 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
parent
a4c850ab57
commit
6a2dbda407
|
@ -43,7 +43,7 @@ sub set_db {
|
||||||
|
|
||||||
sub existsInDB($$) {
|
sub existsInDB($$) {
|
||||||
my ($dbh, $oid,$manuf) = @_;
|
my ($dbh, $oid,$manuf) = @_;
|
||||||
my $sth = $dbh->prepare("SELECT traps_id from traps where traps_oid='$oid'");
|
my $sth = $dbh->prepare("SELECT traps_id FROM traps WHERE traps_oid = '$oid'");
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
if (defined($sth->fetchrow_array)) {
|
if (defined($sth->fetchrow_array)) {
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
|
@ -95,8 +95,7 @@ sub main($$) {
|
||||||
$last_oid = $oid;
|
$last_oid = $oid;
|
||||||
}
|
}
|
||||||
} elsif ($_ =~/^FORMAT\ (.*)/ && $last_oid ne "") {
|
} elsif ($_ =~/^FORMAT\ (.*)/ && $last_oid ne "") {
|
||||||
my $query = "UPDATE `traps` set traps_args='$1' where traps_oid='$last_oid'";
|
my $sth = $dbh->prepare("UPDATE `traps` set traps_args='$1' WHERE traps_oid = '$last_oid'");
|
||||||
my $sth = $dbh->prepare($query);
|
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
} elsif ($_ =~ /^SDESC(.*)/ && $last_oid ne "") {
|
} elsif ($_ =~ /^SDESC(.*)/ && $last_oid ne "") {
|
||||||
|
|
|
@ -1,134 +1,134 @@
|
||||||
#! /usr/bin/perl -w
|
#! /usr/bin/perl -w
|
||||||
|
###################################################################
|
||||||
|
# Oreon is developped with GPL Licence 2.0
|
||||||
#
|
#
|
||||||
# $Id: genSnmpttConfFile.pl,v 1.0 2007/05/15 17:21:49 Sugumaran Mat $
|
# GPL License: http://www.gnu.org/licenses/gpl.txt
|
||||||
#
|
#
|
||||||
# Oreon's plugins are developped with GPL Licence :
|
# Developped by : Mathavarajan Sugumaran - msugumaran@merethis.com
|
||||||
# http://www.fsf.org/licenses/gpl.txt
|
#
|
||||||
# Developped by : Sugumaran Mathavarajan
|
###################################################################
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# For information : contact@merethis.com
|
||||||
|
####################################################################
|
||||||
|
#
|
||||||
|
# Script init
|
||||||
#
|
#
|
||||||
# The Software is provided to you AS IS and WITH ALL FAULTS.
|
|
||||||
# OREON makes no representation and gives no warranty whatsoever,
|
|
||||||
# whether express or implied, and without limitation, with regard to the quality,
|
|
||||||
# safety, contents, performance, merchantability, non-infringement or suitability for
|
|
||||||
# any particular or intended purpose of the Software found on the OREON web site.
|
|
||||||
# In no event will OREON be liable for any direct, indirect, punitive, special,
|
|
||||||
# incidental or consequential damages however they may arise and even if OREON has
|
|
||||||
# been previously advised of the possibility of such damages.
|
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use DBI;
|
use DBI;
|
||||||
my $NAGIOS_TRAPS = "/srv/nagios/libexec/traps";
|
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
## SET DATABASE CONFIGURATION
|
## SET DATABASE CONFIGURATION
|
||||||
#
|
#
|
||||||
sub set_db
|
|
||||||
{
|
sub set_db {
|
||||||
my $db_name = "oreon"; ## name of your database for oreon
|
require "@OREON_PATH@/ODS/etc/conf.pm"
|
||||||
my $login = "root"; ## user of your database
|
my $dsn = "dbi:mysql:$mysql_database_oreon";
|
||||||
my $mdp = "mysql-password"; ## password for this user
|
return $dsn, $mysql_user, $mysql_passwd;
|
||||||
my $dsn = "dbi:mysql:$db_name";
|
|
||||||
return $dsn, $login, $mdp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
## Get snmptt configuration files path
|
## Get snmptt configuration files path
|
||||||
#
|
#
|
||||||
|
|
||||||
sub getPath($) {
|
sub getPath($) {
|
||||||
my $dbh = shift;
|
my $dbh = shift;
|
||||||
my $query = "Select snmp_trapd_path_conf from general_opt";
|
my $sth = $dbh->prepare("Select snmp_trapd_path_conf from general_opt");
|
||||||
my $sth = $dbh->prepare($query);
|
$sth->execute();
|
||||||
$sth->execute;
|
my $path = $sth->fetchrow_array();
|
||||||
my $path = $sth->fetchrow_array;
|
$path .= "/" if (!($path =~ /\/$/));
|
||||||
if (!($path =~ /\/$/)) {
|
$path = "/etc/snmp/" if (!$path);
|
||||||
$path .= "/";
|
|
||||||
}
|
|
||||||
if (!$path) {
|
|
||||||
$path = "/etc/snmp/";
|
|
||||||
}
|
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 @db = set_db();
|
||||||
my $dbh = DBI->connect($db[0], $db[1], $db[2]) or die "Echec de la connexion mysql\n";
|
my $dbh = DBI->connect($db[0], $db[1], $db[2]) or die "Echec de la connexion mysql\n";
|
||||||
my $confFiles_path = getPath($dbh);
|
my $confFiles_path = getPath($dbh);
|
||||||
my $query = "SELECT id, name from inventory_manufacturer";
|
|
||||||
my $sth = $dbh->prepare($query);
|
my $sth = $_[0]->prepare("SELECT nagios_path_plugins FROM general_opt LIMIT 1");
|
||||||
$sth->execute;
|
$sth->execute();
|
||||||
|
my $conf = $sth->fetchrow_array();
|
||||||
|
$sth->finish();
|
||||||
|
my $NAGIOS_TRAPS = $conf->{'nagios_path_plugins'}."traps/";
|
||||||
|
|
||||||
|
my $sth = $dbh->prepare("SELECT id, name from inventory_manufacturer");
|
||||||
|
$sth->execute();
|
||||||
my $snmpttIni = "";
|
my $snmpttIni = "";
|
||||||
while (my ($man_id, $man_name) = $sth->fetchrow_array) {
|
while (my ($man_id, $man_name) = $sth->fetchrow_array()) {
|
||||||
my $query2 = "SELECT traps_name, traps_oid, traps_status, traps_args, traps_comments";
|
my $sth2 = $dbh->prepare("SELECT traps_name, traps_oid, traps_status, traps_args, traps_comments FROM traps WHERE manufacturer_id = '$man_id'");
|
||||||
$query2 .= " from traps where manufacturer_id='$man_id'";
|
$sth2->execute();
|
||||||
my $sth2 = $dbh->prepare($query2);
|
if (!open(FILE, "> ".$confFiles_path."snmptt-".$man_name.".conf")) {
|
||||||
$sth2->execute;
|
print "Cannot open ".$confFiles_path."snmptt-".$man_name.".conf in write mode - Export aborded\n";
|
||||||
if (!open(FILE, "> ".$confFiles_path."snmptt-".$man_name.".conf")) {
|
exit;
|
||||||
print "Cannot open ".$confFiles_path."snmptt-".$man_name.".conf in write mode - Export aborded\n";
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
if ($sth2->rows) {
|
|
||||||
$nbMan++;
|
|
||||||
}
|
|
||||||
while (my @values = $sth2->fetchrow_array) {
|
|
||||||
$nbTraps++;
|
|
||||||
print FILE "EVENT ".$values[0]." ".$values[1]." \"Status Event\" ".$values[2]."\n";
|
|
||||||
if (defined($values[3])) {
|
|
||||||
print FILE "FORMAT ".$values[3]."\n";
|
|
||||||
}
|
|
||||||
print FILE "EXEC ".$NAGIOS_TRAPS."/trapHandler.pl \$aA \$o \"\$*\"\n";
|
|
||||||
if (defined($values[4])) {
|
|
||||||
print FILE "SDESC\n";
|
|
||||||
print FILE $values[4];
|
|
||||||
if ($values[4] =~ /\n$/) {
|
|
||||||
print FILE "EDESC\n\n";
|
|
||||||
}else {
|
|
||||||
print FILE "\nEDESC\n\n";
|
|
||||||
}
|
}
|
||||||
}else {
|
$nbMan++ if ($sth2->rows);
|
||||||
print FILE "\n";
|
while (my @values = $sth2->fetchrow_array()) {
|
||||||
}
|
$nbTraps++;
|
||||||
}
|
print FILE "EVENT ".$values[0]." ".$values[1]." \"Status Event\" ".$values[2]."\n";
|
||||||
close FILE;
|
print FILE "FORMAT ".$values[3]."\n" if (defined($values[3]));
|
||||||
$snmpttIni .= $confFiles_path."snmptt-".$man_name.".conf\n";
|
print FILE "EXEC ".$NAGIOS_TRAPS."/trapHandler.pl \$aA \$o \"\$*\"\n";
|
||||||
$sth2->finish;
|
if (defined($values[4])) {
|
||||||
|
print FILE "SDESC\n".$values[4];
|
||||||
|
if ($values[4] =~ /\n$/) {
|
||||||
|
print FILE "EDESC\n\n";
|
||||||
|
} else {
|
||||||
|
print FILE "\nEDESC\n\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print FILE "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close FILE;
|
||||||
|
$snmpttIni .= $confFiles_path."snmptt-".$man_name.".conf\n";
|
||||||
|
$sth2->finish();
|
||||||
}
|
}
|
||||||
print "$nbTraps traps for $nbMan manufacturers are defined.\n";
|
print "$nbTraps traps for $nbMan manufacturers are defined.\n";
|
||||||
$sth->finish;
|
$sth->finish();
|
||||||
$dbh->disconnect;
|
$dbh->disconnect();
|
||||||
if (!open(FILE, $confFiles_path."snmptt.ini")) {
|
if (!open(FILE, $confFiles_path."snmptt.ini")) {
|
||||||
print "Cannot open ".$confFiles_path."snmptt.ini - Export Aborded\n";
|
print "Cannot open ".$confFiles_path."snmptt.ini - Export Aborded\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
if (!open(TEMP, "> /tmp/snmptt.ini.tmp")) {
|
if (!open(TEMP, "> /tmp/snmptt.ini.tmp")) {
|
||||||
print "Cannot open /tmp/snmptt.ini.tmp in write mode - Export Aborded\n";
|
print "Cannot open /tmp/snmptt.ini.tmp in write mode - Export Aborded\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
my $continue = 1;
|
my $continue = 1;
|
||||||
while ($continue == 1) {
|
while ($continue == 1) {
|
||||||
my $line = <FILE>;
|
my $line = <FILE>;
|
||||||
if ($line) {
|
if ($line) {
|
||||||
if (!($line =~ /^snmptt\_conf\_files/)) {
|
if (!($line =~ /^snmptt\_conf\_files/)) {
|
||||||
print TEMP $line;
|
print TEMP $line;
|
||||||
}else {
|
} else {
|
||||||
$continue = 0;
|
$continue = 0;
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
$continue = -1;
|
$continue = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$continue) {
|
if (!$continue) {
|
||||||
print TEMP "snmptt_conf_files = <<END\n";
|
print TEMP "snmptt_conf_files = <<END\n";
|
||||||
print TEMP $snmpttIni."END\n";
|
print TEMP $snmpttIni."END\n";
|
||||||
my $command = "mv /tmp/snmptt.ini.tmp ".$confFiles_path."snmptt.ini";
|
my $command = "mv /tmp/snmptt.ini.tmp ".$confFiles_path."snmptt.ini";
|
||||||
my $mv = `$command`;
|
my $mv = `$command`;
|
||||||
print "SNMPTT configuration files generated.\n";
|
print "SNMPTT configuration files generated.\n";
|
||||||
}else {
|
} else {
|
||||||
print "Couldn't export ".$confFiles_path."snmptt.ini, please put these lines at the end of file snmptt.ini :\n";
|
print "Couldn't export ".$confFiles_path."snmptt.ini, please put these lines at the end of file snmptt.ini :\n";
|
||||||
print "snmptt_conf_files = <<END\n".$snmpttIni."END\n";
|
print "snmptt_conf_files = <<END\n".$snmpttIni."END\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
main;
|
|
||||||
|
main();
|
||||||
|
|
|
@ -41,8 +41,7 @@ sub set_db {
|
||||||
#
|
#
|
||||||
|
|
||||||
sub get_hostinfos($$){
|
sub get_hostinfos($$){
|
||||||
my $requete = "SELECT host_name FROM host WHERE host_address='$_[1]' ";
|
my $sth = $_[0]->prepare("SELECT host_name FROM host WHERE host_address='$_[1]' ");
|
||||||
my $sth = $_[0]->prepare($requete);
|
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
my @host;
|
my @host;
|
||||||
while (my $temp = $sth->fetchrow_array()) {
|
while (my $temp = $sth->fetchrow_array()) {
|
||||||
|
@ -55,18 +54,19 @@ sub get_hostinfos($$){
|
||||||
##########################
|
##########################
|
||||||
## GET SERVICE DESCRIPTION
|
## GET SERVICE DESCRIPTION
|
||||||
#
|
#
|
||||||
|
|
||||||
sub get_servicename($$$) {
|
sub get_servicename($$$) {
|
||||||
my $query_host = "SELECT host_id from host WHERE host_name ='$_[2]'";
|
my $query_host = "SELECT host_id from host WHERE host_name ='$_[2]'";
|
||||||
my $sth = $_[0]->prepare($query_host);
|
my $sth = $_[0]->prepare($query_host);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
my $host_id = $sth -> fetchrow_array;
|
my $host_id = $sth -> fetchrow_array();
|
||||||
exit if (!defined $host_id);
|
exit if (!defined $host_id);
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
|
|
||||||
my $query_trap = "SELECT traps_id, traps_args, traps_status from traps where traps_oid='$_[1]'";
|
my $query_trap = "SELECT traps_id, traps_args, traps_status from traps where traps_oid='$_[1]'";
|
||||||
$sth = $_[0]->prepare($query_trap);
|
$sth = $_[0]->prepare($query_trap);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
my ($trap_id,$argument, $trap_status) = $sth -> fetchrow_array;
|
my ($trap_id,$argument, $trap_status) = $sth->fetchrow_array();
|
||||||
exit if (!defined $trap_id);
|
exit if (!defined $trap_id);
|
||||||
|
|
||||||
my $query_services = "SELECT service_description FROM service s, host_service_relation h, traps_service_relation t";
|
my $query_services = "SELECT service_description FROM service s, host_service_relation h, traps_service_relation t";
|
||||||
|
@ -75,7 +75,7 @@ sub get_servicename($$$) {
|
||||||
$sth = $_[0]->prepare($query_services);
|
$sth = $_[0]->prepare($query_services);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
my @service;
|
my @service;
|
||||||
while (my $temp = $sth -> fetchrow_array) {
|
while (my $temp = $sth -> fetchrow_array()) {
|
||||||
$service[scalar(@service)] = $temp;
|
$service[scalar(@service)] = $temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue