change NAGIOS_PLUGINS by NAGIOS_PLUGIN a cause de WATT
git-svn-id: http://svn.centreon.com/trunk/plugins-2.x@4856 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
parent
d2f4cd03fa
commit
d19d53141e
|
@ -3,7 +3,7 @@ DIR_OREON=@INSTALL_DIR_OREON@/
|
|||
DIR_TRAFFICMAP=@INSTALL_DIR_OREON@/include/trafficMap/average/
|
||||
DIR_NAGIOS=@INSTALL_DIR_NAGIOS@/
|
||||
DIR_RRDTOOL=@INSTALL_DIR_OREON@/rrd/
|
||||
NAGIOS_LIBEXEC=@NAGIOS_PLUGINS@/
|
||||
NAGIOS_PLUGIN=@NAGIOS_PLUGIN@/
|
||||
NAGIOS_ETC=@NAGIOS_ETC@/
|
||||
|
||||
[NT]
|
||||
|
|
|
@ -27,7 +27,7 @@ package centreon;
|
|||
use Exporter ();
|
||||
use FindBin qw($Bin);
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
|
||||
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
@ -62,7 +62,7 @@ my @ds = ("a","b","c","d","e","f","g","h","i","j","k","l");
|
|||
# Get all parameters from the ini file
|
||||
###############################################################################
|
||||
sub get_parameters {
|
||||
$params_file = "@NAGIOS_PLUGINS@/$params_file";
|
||||
$params_file = "@NAGIOS_PLUGIN@/$params_file";
|
||||
unless (-e $params_file) {
|
||||
print "Unknown - In centreon.pm :: $params_file :: $!\n";
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
|
|
|
@ -28,7 +28,7 @@ use strict;
|
|||
use Net::SNMP qw(:snmp oid_lex_sort);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
if (eval "require centreon" ) {
|
||||
use centreon qw(get_parameters);
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
use strict;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
use vars qw($PROGNAME);
|
||||
|
@ -38,7 +38,7 @@ use vars qw($opt_H $opt_p $opt_s $opt_v $opt_V $opt_h $opt_w $opt_c $opt_t $opt_
|
|||
# Plugin var init
|
||||
#
|
||||
|
||||
my $pathtolibexecnt = "@NAGIOS_PLUGINS@/check_nt";
|
||||
my $pathtolibexecnt = "@NAGIOS_PLUGIN@/check_nt";
|
||||
|
||||
my($op_v, $op_d, $op_s, $op_t, $op_l, $port, @values, @test, @test2, @test3, @test4, @test5, $warning, $critical, @w, @c, $uptime);
|
||||
my($warning2, $critical2, $warning3, $critical3, $warning4, $critical4, @output);
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
use strict;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "/srv/nagios/libexec";
|
||||
#use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
if (eval "require centreon" ) {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
||||
#
|
||||
# Developped by : Julien Mathis - Romain Le Merlus
|
||||
# Mathavarajan Sugumaran
|
||||
#
|
||||
###################################################################
|
||||
# This program is free software; you can redistribute it and/or
|
||||
|
@ -27,7 +26,7 @@ use strict;
|
|||
use Net::SNMP qw(:snmp);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
if (eval "require centreon" ) {
|
||||
use centreon qw(get_parameters);
|
||||
|
|
|
@ -27,8 +27,7 @@ use strict;
|
|||
use Net::SNMP qw(:snmp);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "/usr/local/nagios/libexec";
|
||||
#use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
if (eval "require centreon" ) {
|
||||
|
|
|
@ -28,8 +28,7 @@ use strict;
|
|||
use Net::SNMP qw(:snmp);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "/usr/local/nagios/libexec";
|
||||
#use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
if (eval "require centreon" ) {
|
||||
|
|
|
@ -1,25 +1,28 @@
|
|||
#! /usr/bin/perl -w
|
||||
###################################################################
|
||||
# Oreon is developped with GPL Licence 2.0
|
||||
#
|
||||
# $Id: check_grah_real_memory.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $
|
||||
# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
||||
#
|
||||
# Oreon's plugins are developped with GPL Licence :
|
||||
# http://www.fsf.org/licenses/gpl.txt
|
||||
# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier
|
||||
# Developped by : Julien Mathis - Romain Le Merlus
|
||||
# Mathavarajan Sugumaran
|
||||
#
|
||||
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
|
||||
###################################################################
|
||||
# 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.
|
||||
|
||||
##
|
||||
## Plugin init
|
||||
##
|
||||
|
||||
use strict;
|
||||
use Net::SNMP qw(:snmp);
|
||||
|
|
|
@ -28,7 +28,7 @@ use strict;
|
|||
use Net::SNMP qw(:snmp oid_lex_sort);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
if (eval "require centreon" ) {
|
||||
use centreon qw(get_parameters);
|
||||
|
|
|
@ -29,7 +29,7 @@ use Net::SNMP qw(:snmp oid_lex_sort);
|
|||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "/usr/local/nagios/libexec";
|
||||
#use lib "@NAGIOS_PLUGINS@";
|
||||
#use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
if (eval "require centreon" ) {
|
||||
|
@ -56,7 +56,7 @@ use vars qw($opt_V $opt_h $opt_v $opt_C $opt_H $opt_w $opt_c);
|
|||
$PROGNAME = "$0";
|
||||
|
||||
my ($row, @flg_created, @last_check_time, @last_in_errors, @last_out_errors, $result_in, $result_out, @nb_out_errors, @nb_in_errors, $update_time, $db_file);
|
||||
my $pathtolibexecnt = $centreon{NAGIOS_LIBEXEC};
|
||||
my $pathtolibexecnt = $centreon{NAGIOS_PLUGIN};
|
||||
|
||||
sub print_help ();
|
||||
sub print_usage ();
|
||||
|
|
|
@ -28,7 +28,7 @@ use strict;
|
|||
use Net::SNMP qw(:snmp oid_lex_sort);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
if (eval "require centreon" ) {
|
||||
use centreon qw(get_parameters);
|
||||
|
|
|
@ -32,7 +32,7 @@ use Getopt::Long;
|
|||
|
||||
# Nagios specific
|
||||
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw(%ERRORS $TIMEOUT);
|
||||
|
||||
# centreon specific
|
||||
|
|
|
@ -28,7 +28,7 @@ use strict;
|
|||
use Net::SNMP qw(:snmp);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
if (eval "require centreon" ) {
|
||||
|
|
|
@ -29,7 +29,7 @@ use Net::SNMP qw(:snmp oid_lex_sort);
|
|||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "/usr/local/nagios/libexec";
|
||||
#use lib "@NAGIOS_LIBEXEC@";
|
||||
#use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
if (eval "require centreon" ) {
|
||||
use centreon qw(get_parameters);
|
||||
|
|
|
@ -27,7 +27,7 @@ use strict;
|
|||
use Net::SNMP qw(:snmp);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
if (eval "require centreon" ) {
|
||||
|
|
|
@ -28,7 +28,7 @@ use strict;
|
|||
use Net::SNMP qw(:snmp);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
use vars qw($PROGNAME);
|
||||
|
|
|
@ -29,7 +29,7 @@ use DBI;
|
|||
use vars qw($PROGNAME);
|
||||
use Getopt::Long;
|
||||
use vars qw($opt_V $opt_H $opt_h $opt_i);
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
## For Debug mode = 1
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
use strict;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin";
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw($TIMEOUT %ERRORS &print_revision &support);
|
||||
|
||||
if (eval "require centreon" ) {
|
||||
|
@ -45,7 +45,7 @@ use vars qw($opt_H $opt_p $opt_s $opt_v $opt_V $opt_h $opt_w $opt_c $opt_S $opt_
|
|||
|
||||
## Plugin var init
|
||||
|
||||
my $pathtolibexecnt = $centreon{GLOBAL}{NAGIOS_LIBEXEC}."check_nt";
|
||||
my $pathtolibexecnt = $centreon{GLOBAL}{NAGIOS_PLUGIN}."check_nt";
|
||||
my($op_v, $op_d, $op_s, $op_t, $op_l, $port, @values, @test, @test2, @test3, @test4, @test5, $warning, $critical, @w, @c, $uptime);
|
||||
my($warning2, $critical2, $warning3, $critical3, $warning4, $critical4, @output);
|
||||
$PROGNAME = $0;
|
||||
|
|
|
@ -18,7 +18,7 @@ use Getopt::Long;
|
|||
|
||||
# Nagios specific
|
||||
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw(%ERRORS $TIMEOUT);
|
||||
#my $TIMEOUT = 15;
|
||||
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
|
|
|
@ -21,14 +21,14 @@ use Getopt::Long;
|
|||
|
||||
# Nagios specific
|
||||
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw(%ERRORS $TIMEOUT);
|
||||
#my $TIMEOUT = 5;
|
||||
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
|
||||
# centreon specific
|
||||
|
||||
#use lib "@NAGIOS_PLUGINS@";
|
||||
#use lib "@NAGIOS_PLUGIN@";
|
||||
if (eval "require centreon" ) {
|
||||
use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
|
||||
use vars qw($VERSION %centreon);
|
||||
|
|
|
@ -16,7 +16,7 @@ use Getopt::Long;
|
|||
|
||||
# Nagios specific
|
||||
|
||||
use lib "@NAGIOS_PLUGINS@";
|
||||
use lib "@NAGIOS_PLUGIN@";
|
||||
use utils qw(%ERRORS $TIMEOUT);
|
||||
#my $TIMEOUT = 5;
|
||||
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
|
|
|
@ -1,137 +0,0 @@
|
|||
#! /usr/bin/perl -w
|
||||
###################################################################
|
||||
# Oreon is developped with GPL Licence 2.0
|
||||
#
|
||||
# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
||||
#
|
||||
# Developped by : Mathavarajan Sugumaran - msugumaran@merethis.com
|
||||
# Julien Mathis - Romain Le Merlus
|
||||
#
|
||||
###################################################################
|
||||
# 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
|
||||
#
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
use DBI;
|
||||
|
||||
use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd);
|
||||
require "@INSTALL_DIR_OREON@/ODS/etc/conf.pm";
|
||||
|
||||
#########################################
|
||||
## TEST IF OID ALREADY EXISTS IN DATABASE
|
||||
#
|
||||
|
||||
sub existsInDB($$) {
|
||||
my ($dbh, $oid) = @_;
|
||||
my $sth = $dbh->prepare("SELECT traps_id FROM traps WHERE traps_oid = '$oid'");
|
||||
$sth->execute();
|
||||
if (defined($sth->fetchrow_array)) {
|
||||
$sth->finish();
|
||||
return 1;
|
||||
}
|
||||
$sth->finish();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#####################################
|
||||
## RETURN ENUM FROM STRING FOR STATUS
|
||||
#
|
||||
|
||||
sub getStatus($$) {
|
||||
my ($val, $type) = @_;
|
||||
if ($val =~ /[I|i][N|n][F|f][O|o][R|r][M|m][A|a][T|t][I|i][O|o][N|n][A|a][L|l]|[N|n][O|o][R|r][M|m][A|a][L|l]/) {
|
||||
return 0;
|
||||
} elsif ($val =~ /^[W|w][A|a][R|r][N|n][I|i][N|n][G|g]|[M|m][I|i][N|n][O|o][R|r]$/) {
|
||||
return 1;
|
||||
} elsif ($val =~ /^[C|c][R|r][I|i][T|t][I|i][C|c][A|a][L|l]|[M|m][A|a][J|j][O|o][R|r]$/) {
|
||||
return 2;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
################
|
||||
## MAIN FUNCTION
|
||||
#
|
||||
|
||||
sub main($$) {
|
||||
my $manuf = $_[1];
|
||||
|
||||
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])) {
|
||||
print "Cannot open configuration file : $_[0]\n";
|
||||
exit;
|
||||
}
|
||||
my $last_oid = "";
|
||||
while (<FILE>) {
|
||||
if ($_ =~ /^EVENT\ ([a-zA-Z0-9]+)\ ([0-9\.]+)\ (\"[A-Za-z\ ]+\")\ ([a-zA-Z]+)/) {
|
||||
my ($name,$oid,$type,$val) = ($1,$2,$3,$4);
|
||||
if (existsInDB($dbh, $oid)) {
|
||||
print "Trap oid : $name => $oid already exists in database\n";
|
||||
$last_oid = $oid;
|
||||
} else {
|
||||
$val = getStatus($val,$type);
|
||||
my $sth = $dbh->prepare("INSERT INTO `traps` (traps_name, traps_oid, traps_status, manufacturer_id) values ('$name', '$oid', '$val', '$manuf')");
|
||||
$sth->execute();
|
||||
$sth->finish();
|
||||
$last_oid = $oid;
|
||||
}
|
||||
} elsif ($_ =~/^FORMAT\ (.*)/ && $last_oid ne "") {
|
||||
my $sth = $dbh->prepare("UPDATE `traps` set traps_args='$1' WHERE traps_oid = '$last_oid'");
|
||||
$sth->execute();
|
||||
$sth->finish();
|
||||
} elsif ($_ =~ /^SDESC(.*)/ && $last_oid ne "") {
|
||||
my $temp_val = $1;
|
||||
my $desc = "";
|
||||
if (! ($temp_val =~ /\s+/)){
|
||||
$temp_val =~ s/\"/\\\"/g;
|
||||
$temp_val =~ s/\'/\\\'/g;
|
||||
$desc .= $temp_val;
|
||||
}
|
||||
my $found = 0;
|
||||
while (!$found) {
|
||||
my $line = <FILE>;
|
||||
if ($line =~ /^EDESC/) {
|
||||
$found = 1;
|
||||
} else {
|
||||
$line =~ s/\"/\\\"/g;
|
||||
$line =~ s/\'/\\\'/g;
|
||||
$desc .= $line;
|
||||
}
|
||||
}
|
||||
if ($desc ne "") {
|
||||
my $sth = $dbh->prepare("UPDATE `traps` set traps_comments='$desc' where traps_oid='$last_oid'");
|
||||
$sth->execute();
|
||||
$sth->finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
$dbh->disconnect();
|
||||
}
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
my ($opt_f, $opt_m);
|
||||
GetOptions("f|file=s" => \$opt_f, "m|man=s" => \$opt_m);
|
||||
|
||||
if (!$opt_f || !$opt_m) {
|
||||
print "fill_trapDB : Usage : ./fill_trapDB -f configuration_file -m manufacturer_id\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
main($opt_f,$opt_m);
|
||||
|
||||
exit();
|
|
@ -1,134 +0,0 @@
|
|||
#! /usr/bin/perl -w
|
||||
###################################################################
|
||||
# Oreon is developped with GPL Licence 2.0
|
||||
#
|
||||
# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
||||
#
|
||||
# Developped by : Mathavarajan Sugumaran - msugumaran@merethis.com
|
||||
# Julien Mathis - Romain Le Merlus
|
||||
#
|
||||
###################################################################
|
||||
# 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
|
||||
#
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
use DBI;
|
||||
|
||||
use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd);
|
||||
require "@INSTALL_DIR_OREON@/ODS/etc/conf.pm";
|
||||
|
||||
######################################
|
||||
## Get snmptt configuration files path
|
||||
#
|
||||
|
||||
sub getPath($) {
|
||||
my $dbh = shift;
|
||||
my $sth = $dbh->prepare("Select snmp_trapd_path_conf from general_opt");
|
||||
$sth->execute();
|
||||
my $path = $sth->fetchrow_array();
|
||||
$path .= "/" if (!($path =~ /\/$/));
|
||||
$path = "/etc/snmp/" if (!$path);
|
||||
return $path;
|
||||
}
|
||||
|
||||
sub main() {
|
||||
print "Generating SNMPTT configuration files...\n";
|
||||
my ($nbMan, $nbTraps) = (0,0);
|
||||
|
||||
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 $sth = $dbh->prepare("SELECT nagios_path_plugins FROM general_opt LIMIT 1");
|
||||
$sth->execute();
|
||||
my @conf = $sth->fetchrow_array();
|
||||
$sth->finish();
|
||||
my $NAGIOS_TRAPS = $conf[0]."traps/";
|
||||
|
||||
$sth = $dbh->prepare("SELECT id, name from traps_vendor");
|
||||
$sth->execute();
|
||||
my $snmpttIni = "";
|
||||
while (my ($man_id, $man_name) = $sth->fetchrow_array()) {
|
||||
my $sth2 = $dbh->prepare("SELECT traps_name, traps_oid, traps_status, traps_args, traps_comments FROM traps WHERE manufacturer_id = '$man_id'");
|
||||
$sth2->execute();
|
||||
if (!open(FILE, "> ".$confFiles_path."snmptt-".$man_name.".conf")) {
|
||||
print "Cannot open ".$confFiles_path."snmptt-".$man_name.".conf in write mode - Export aborded\n";
|
||||
exit;
|
||||
}
|
||||
$nbMan++ if ($sth2->rows);
|
||||
while (my @values = $sth2->fetchrow_array()) {
|
||||
$nbTraps++;
|
||||
my $args = "";
|
||||
print FILE "EVENT ".$values[0]." ".$values[1]." \"Status Event\" ".$values[2]."\n";
|
||||
if (defined($values[3])) {
|
||||
print FILE "FORMAT ".$values[3]."\n";
|
||||
} else {
|
||||
$values[3] = "no output for trap!";
|
||||
}
|
||||
print FILE "EXEC ".$NAGIOS_TRAPS."trapHandler \$aA \$A \$o \"$values[3]\"\n";
|
||||
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";
|
||||
$sth->finish();
|
||||
$dbh->disconnect();
|
||||
if (!open(FILE, $confFiles_path."snmptt.ini")) {
|
||||
print "Cannot open ".$confFiles_path."snmptt.ini - Export Aborded\n";
|
||||
exit;
|
||||
}
|
||||
if (!open(TEMP, "> /tmp/snmptt.ini.tmp")) {
|
||||
print "Cannot open /tmp/snmptt.ini.tmp in write mode - Export Aborded\n";
|
||||
exit;
|
||||
}
|
||||
my $continue = 1;
|
||||
while ($continue == 1) {
|
||||
my $line = <FILE>;
|
||||
if ($line) {
|
||||
if (!($line =~ /^snmptt\_conf\_files/)) {
|
||||
print TEMP $line;
|
||||
} else {
|
||||
$continue = 0;
|
||||
}
|
||||
} else {
|
||||
$continue = -1;
|
||||
}
|
||||
}
|
||||
if (!$continue) {
|
||||
print TEMP "snmptt_conf_files = <<END\n";
|
||||
print TEMP $snmpttIni."END\n";
|
||||
my $command = "mv /tmp/snmptt.ini.tmp ".$confFiles_path."snmptt.ini";
|
||||
my $mv = `$command`;
|
||||
print "SNMPTT configuration files generated.\n";
|
||||
} else {
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
|
@ -1,179 +0,0 @@
|
|||
#! /usr/bin/perl -w
|
||||
###################################################################
|
||||
# Oreon is developped with GPL Licence 2.0
|
||||
#
|
||||
# GPL License: http://www.gnu.org/licenses/gpl.txt
|
||||
#
|
||||
# Developped by : Mathavarajan Sugumaran - msugumaran@merethis.com
|
||||
# Julien Mathis - Romain Le Merlus
|
||||
#
|
||||
###################################################################
|
||||
# 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
|
||||
#
|
||||
|
||||
use strict;
|
||||
use DBI;
|
||||
|
||||
use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd);
|
||||
require "@INSTALL_DIR_OREON@/ODS/etc/conf.pm";
|
||||
|
||||
###############################
|
||||
## GET HOSTNAME FROM IP ADDRESS
|
||||
#
|
||||
|
||||
sub get_hostinfos($$$){
|
||||
my $sth = $_[0]->prepare("SELECT host_name FROM host WHERE host_address='$_[1]' OR host_address='$_[2]'");
|
||||
$sth->execute();
|
||||
my @host;
|
||||
while (my $temp = $sth->fetchrow_array()) {
|
||||
$host[scalar(@host)] = $temp;
|
||||
}
|
||||
$sth -> finish;
|
||||
return @host;
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
## GET SERVICES FOR GIVEN HOST (GETTING SERVICES TEMPLATES IN ACCOUNT)
|
||||
#
|
||||
|
||||
sub getServicesIncludeTemplate($$$$) {
|
||||
my ($dbh, $sth_st, $host_id, $trap_id) = @_;
|
||||
my @service;
|
||||
$sth_st->execute();
|
||||
while (my @temp = $sth_st -> fetchrow_array()) {
|
||||
my $tr_query = "select traps_id from traps_service_relation where service_id ='".$temp[0]."' and traps_id='".$trap_id."'";
|
||||
my $sth_st3 = $dbh->prepare($tr_query);
|
||||
$sth_st3->execute();
|
||||
my @trap = $sth_st3 -> fetchrow_array();
|
||||
if (defined($trap[0])) {
|
||||
$service[scalar(@service)] = $temp[1];
|
||||
}else {
|
||||
if (defined($temp[2])) {
|
||||
my $found = 0;
|
||||
my $service_template = $temp[2];
|
||||
while (!$found) {
|
||||
my $st1_query = "select service_id, service_template_model_stm_id, service_description from service s where service_id ='".$service_template."'";
|
||||
my $sth_st1 = $dbh->prepare($st1_query);
|
||||
$sth_st1 -> execute();
|
||||
my @st1_result = $sth_st1 -> fetchrow_array();
|
||||
if (defined($st1_result[0])) {
|
||||
my $st2_query = "select traps_id from traps_service_relation where service_id ='".$service_template."' and traps_id='".$trap_id."'";
|
||||
my $sth_st2 = $dbh->prepare($st2_query);
|
||||
$sth_st2 -> execute();
|
||||
my @st2_result = $sth_st2 -> fetchrow_array();
|
||||
if (defined($st2_result[0])) {
|
||||
$found = 1;
|
||||
$service[scalar(@service)] = $temp[1];
|
||||
}else {
|
||||
$found = 1;
|
||||
if (defined($st1_result[1]) && $st1_result[1]) {
|
||||
$service_template = $st1_result[1];
|
||||
$found = 0;
|
||||
}
|
||||
}
|
||||
$sth_st2->finish;
|
||||
}
|
||||
$sth_st1->finish;
|
||||
}
|
||||
}
|
||||
}
|
||||
$sth_st3->finish;
|
||||
}
|
||||
return (@service);
|
||||
}
|
||||
|
||||
##########################
|
||||
## GET SERVICE DESCRIPTION
|
||||
#
|
||||
|
||||
sub get_servicename($$$) {
|
||||
my $query_host = "SELECT host_id from host WHERE host_name ='$_[2]'";
|
||||
my $sth = $_[0]->prepare($query_host);
|
||||
$sth->execute();
|
||||
my $host_id = $sth -> fetchrow_array();
|
||||
exit if (!defined $host_id);
|
||||
$sth->finish();
|
||||
|
||||
my $query_trap = "SELECT traps_id, traps_status from traps where traps_oid='$_[1]'";
|
||||
$sth = $_[0]->prepare($query_trap);
|
||||
$sth->execute();
|
||||
my ($trap_id, $trap_status) = $sth->fetchrow_array();
|
||||
exit if (!defined $trap_id);
|
||||
$sth->finish();
|
||||
|
||||
##
|
||||
### getting all "services by host" for given host
|
||||
##
|
||||
my $st_query = "SELECT s.service_id, service_description, service_template_model_stm_id FROM service s, host_service_relation h";
|
||||
$st_query .= " where s.service_id=h.service_service_id and h.host_host_id='$host_id'";
|
||||
my $sth_st = $_[0]->prepare($st_query);
|
||||
my @service = getServicesIncludeTemplate($_[0], $sth_st, $host_id, $trap_id);
|
||||
$sth_st->finish;
|
||||
|
||||
##
|
||||
### getting all "services by hostgroup" for given host
|
||||
##
|
||||
my $query_hostgroup_services = "SELECT s.service_id, service_description, service_template_model_stm_id FROM hostgroup_relation hgr, service s, host_service_relation hsr";
|
||||
$query_hostgroup_services .= " WHERE hgr.host_host_id = '".$host_id."' AND hsr.hostgroup_hg_id = hgr.hostgroup_hg_id";
|
||||
$query_hostgroup_services .= " AND s.service_id = hsr.service_service_id";
|
||||
$sth_st = $_[0]->prepare($query_hostgroup_services);
|
||||
$sth_st->execute();
|
||||
@service = (@service,getServicesIncludeTemplate($_[0], $sth_st, $host_id, $trap_id));
|
||||
$sth_st->finish;
|
||||
return $trap_status, (@service);
|
||||
}
|
||||
|
||||
#######################################
|
||||
## GET HOSTNAME AND SERVICE DESCRIPTION
|
||||
#
|
||||
|
||||
sub getTrapsInfos($$$$){
|
||||
my $ip = shift;
|
||||
my $hostname = shift;
|
||||
my $oid = shift;
|
||||
my $arguments_line = shift;
|
||||
|
||||
my $dsn = "dbi:mysql:$mysql_database_oreon";
|
||||
my $dbh = DBI->connect($dsn, $mysql_user, $mysql_passwd) or die "Echec de la connexion\n";
|
||||
my @host = get_hostinfos($dbh, $ip, $hostname);
|
||||
foreach(@host) {
|
||||
my $this_host = $_;
|
||||
my ($status, @servicename) = get_servicename($dbh, $oid, $_);
|
||||
foreach (@servicename) {
|
||||
my $this_service = $_;
|
||||
my $datetime=`date +%s`;
|
||||
chomp($datetime);
|
||||
my $sth = $dbh->prepare("SELECT command_file FROM cfg_nagios WHERE nagios_activate = '1' LIMIT 1");
|
||||
$sth->execute();
|
||||
my @conf = $sth->fetchrow_array();
|
||||
$sth->finish();
|
||||
my $submit = `/bin/echo "[$datetime] PROCESS_SERVICE_CHECK_RESULT;$this_host;$this_service;$status;$arguments_line" >> $conf[0]`;
|
||||
}
|
||||
}
|
||||
$dbh->disconnect();
|
||||
exit;
|
||||
}
|
||||
|
||||
##########################
|
||||
## PARSE TRAP INFORMATIONS
|
||||
#
|
||||
if (scalar(@ARGV)) {
|
||||
my $ip = $ARGV[0];
|
||||
my $hostname = $ARGV[1];
|
||||
my $oid = $ARGV[2];
|
||||
my $arguments = $ARGV[3];
|
||||
getTrapsInfos($ip, $hostname, $oid, $arguments);
|
||||
}
|
Loading…
Reference in New Issue