2013-11-07 Axel Amigo <axel.amigo@artica.es>
* pandora_server\lib\PandoraFMS\Config.pm: Added support for SNMP Forwarding tokens pandora_server\lib\PandoraFMS\SNMPServer.pm: Added new SNMP forwarding feature git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9033 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
a1822102db
commit
5d6eb36fc8
|
@ -43,7 +43,7 @@ our @EXPORT = qw(
|
|||
|
||||
# version: Defines actual version of Pandora Server for this module only
|
||||
my $pandora_version = "5.0";
|
||||
my $pandora_build = "131107";
|
||||
my $pandora_build = "131017";
|
||||
our $VERSION = $pandora_version." ".$pandora_build;
|
||||
|
||||
# Setup hash
|
||||
|
@ -329,6 +329,20 @@ sub pandora_load_config {
|
|||
$pa_config->{"agentaccess"} = 1;
|
||||
$pa_config->{"event_storm_protection"} = 0;
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
#SNMP Forwarding tokens
|
||||
$pa_config->{"snmp_forward_trap"}=0;
|
||||
$pa_config->{"snmp_forward_secName"}= '';
|
||||
$pa_config->{"snmp_forward_engineid"}= '';
|
||||
$pa_config->{"snmp_forward_authProtocol"}= '';
|
||||
$pa_config->{"snmp_forward_authPassword"}= '';
|
||||
$pa_config->{"snmp_forward_community"}= 'public';
|
||||
$pa_config->{"snmp_forward_privProtocol"}= '';
|
||||
$pa_config->{"snmp_forward_privPassword"}= '';
|
||||
$pa_config->{"snmp_forward_secLevel"}= '';
|
||||
$pa_config->{"snmp_forward_version"}= 2;
|
||||
$pa_config->{"snmp_forward_ip"}= '';
|
||||
|
||||
|
||||
# Check for UID0
|
||||
if ($pa_config->{"quiet"} != 0){
|
||||
|
@ -705,6 +719,44 @@ sub pandora_load_config {
|
|||
elsif ($parametro =~ m/^event_expiry_window\s+([0-9]*)/i) {
|
||||
$pa_config->{'event_expiry_window'}= clean_blank($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_trap\s+([0-1])/i) {
|
||||
$pa_config->{'snmp_forward_trap'}= safe_input($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_secName\s(.*)/i) {
|
||||
$pa_config->{'snmp_forward_secName'}= safe_input($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_engineid\s(.*)/i) {
|
||||
$pa_config->{'snmp_forward_engineid'}= safe_input($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_authProtocol\s(.*)/i) {
|
||||
$pa_config->{'snmp_forward_authProtocol'}= safe_input($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_authPassword\s(.*)/i) {
|
||||
$pa_config->{'snmp_forward_authPassword'}= safe_input($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_community\s(.*)/i) {
|
||||
$pa_config->{'snmp_forward_community'}= safe_input($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_privProtocol\s(.*)/i) {
|
||||
$pa_config->{'snmp_forward_privProtocol'}= safe_input($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_privPassword\s(.*)/i) {
|
||||
$pa_config->{'snmp_forward_privPassword'}= safe_input($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_secLevel\s(.*)/i) {
|
||||
$pa_config->{'snmp_forward_secLevel'}= safe_input($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_version\s(.*)/i) {
|
||||
$pa_config->{'snmp_forward_version'}= safe_input($1);
|
||||
}
|
||||
elsif ($parametro =~ m/^snmp_forward_ip\s(.*)/i) {
|
||||
$pa_config->{'snmp_forward_ip'}= safe_input($1);
|
||||
if ($pa_config->{'snmp_forward_trap'}==1 && ($pa_config->{'snmp_forward_ip'} eq '127.0.0.1' || $pa_config->{'snmp_forward_ip'} eq 'localhost')) {
|
||||
printf "\n [ERROR] Cannot set snmp_forward_ip to localhost or 127.0.0.1 \n";
|
||||
exit 1;
|
||||
|
||||
}
|
||||
}
|
||||
} # end of loop for parameter #
|
||||
|
||||
# Set to RDBMS' standard port
|
||||
|
|
|
@ -204,7 +204,81 @@ sub pandora_snmptrapd {
|
|||
$AGENTS{$source}{'event'} = 1;
|
||||
next;
|
||||
}
|
||||
|
||||
|
||||
#Trap forwarding
|
||||
if ($pa_config->{'snmp_forward_trap'}==1) {
|
||||
my $trap_data_string = "";
|
||||
|
||||
#We loop through all the custom data of the received trap, creating the $trap_data_string string to forward the trap properly
|
||||
while ($data =~ /([\.\d]+)\s=\s([^:]+):\s([\S ]+)/g) {
|
||||
my ($trap_data, $trap_type, $trap_value) = ($1, $2, $3);
|
||||
if ($trap_type eq "INTEGER") {
|
||||
#FIX for translated traps from IF-MIB.txt MIB
|
||||
$trap_value =~ s/\D//g;
|
||||
$trap_data_string = $trap_data_string . "$trap_data i $trap_value ";
|
||||
}
|
||||
elsif ($trap_type eq "UNSIGNED"){
|
||||
$trap_data_string = $trap_data_string . "$trap_data u $trap_value ";
|
||||
}
|
||||
elsif ($trap_type eq "COUNTER32"){
|
||||
$trap_data_string = $trap_data_string . "$trap_data c $trap_value ";
|
||||
}
|
||||
elsif ($trap_type eq "STRING"){
|
||||
$trap_data_string = $trap_data_string . "$trap_data s $trap_value ";
|
||||
}
|
||||
elsif ($trap_type eq "HEX STRING"){
|
||||
$trap_data_string = $trap_data_string . "$trap_data x $trap_value ";
|
||||
}
|
||||
elsif ($trap_type eq "DECIMAL STRING"){
|
||||
$trap_data_string = $trap_data_string . "$trap_data d $trap_value ";
|
||||
}
|
||||
elsif ($trap_type eq "NULLOBJ"){
|
||||
$trap_data_string = $trap_data_string . "$trap_data n $trap_value ";
|
||||
}
|
||||
elsif ($trap_type eq "OBJID"){
|
||||
$trap_data_string = $trap_data_string . "$trap_data o $trap_value ";
|
||||
}
|
||||
elsif ($trap_type eq "TIMETICKS"){
|
||||
$trap_data_string = $trap_data_string . "$trap_data t $trap_value ";
|
||||
}
|
||||
elsif ($trap_type eq "IPADDRESS"){
|
||||
$trap_data_string = $trap_data_string . "$trap_data a $trap_value ";
|
||||
}
|
||||
elsif ($trap_type eq "BITS"){
|
||||
$trap_data_string = $trap_data_string . "$trap_data b $trap_value ";
|
||||
}
|
||||
}
|
||||
|
||||
#We distinguish between the three different kinds of SNMP forwarding
|
||||
if ($pa_config->{'snmp_forward_version'} eq '3') {
|
||||
system("snmptrap -v $pa_config->{'snmp_forward_version'} -n \"\" -a $pa_config->{'snmp_forward_authProtocol'} -A $pa_config->{'snmp_forward_authPassword'} -x $pa_config->{'snmp_forward_privProtocol'} -X $pa_config->{'snmp_forward_privPassword'} -l $pa_config->{'snmp_forward_secLevel'} -u $pa_config->{'snmp_forward_secName'} -e $pa_config->{'snmp_forward_engineid'} $pa_config->{'snmp_forward_ip'} '' $oid $trap_data_string");
|
||||
}
|
||||
elsif ($pa_config->{'snmp_forward_version'} eq '2' || $pa_config->{'snmp_forward_version'} eq '2c') {
|
||||
system("snmptrap -v 2c -n \"\" -c $pa_config->{'snmp_forward_community'} $pa_config->{'snmp_forward_ip'} '' $oid $trap_data_string");
|
||||
}
|
||||
elsif ($pa_config->{'snmp_forward_version'} eq '1') {
|
||||
#Because of tne SNMP v1 protocol, we must perform additional steps for creating the trap
|
||||
my $value_sending = "";
|
||||
my $type_sending = "";
|
||||
|
||||
if ($value eq ''){
|
||||
$value_sending = "\"\"";
|
||||
}
|
||||
else {
|
||||
$value_sending = $value;
|
||||
$value_sending =~ s/[\$#@~!&*()\[\];.,:?^ `\\\/]+//g;
|
||||
}
|
||||
if ($type eq ''){
|
||||
$type_sending = "\"\"";
|
||||
}
|
||||
else{
|
||||
$type_sending = $type;
|
||||
}
|
||||
|
||||
system("snmptrap -v 1 -c $pa_config->{'snmp_forward_community'} $pa_config->{'snmp_forward_ip'} $oid \"\" $type_sending $value_sending \"\" $trap_data_string");
|
||||
}
|
||||
}
|
||||
|
||||
# Insert the trap into the DB
|
||||
if (! defined(enterprise_hook ('snmp_insert_trap', [$pa_config, $source, $oid, $type, $value, $custom_oid, $custom_value, $custom_type, $timestamp, $self->getServerID (), $dbh]))) {
|
||||
my $trap_id = db_insert ($dbh, 'id_trap', 'INSERT INTO ttrap (timestamp, source, oid, type, value, oid_custom, value_custom, type_custom) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
|
|
Loading…
Reference in New Issue