From b6f5e9996ce6b3926f51eaece42deacb48425926 Mon Sep 17 00:00:00 2001 From: slerena Date: Fri, 22 Oct 2010 14:03:49 +0000 Subject: [PATCH] 2010-10-22 Sancho Lerena * Config.pm: Parsing for mta_from doesn't remove blanks, allowing to use a Normal name + Email address in the from. * Tools.pm: Email output is parsed with a html decode first. Added timeticks option for tools (intented to use in the future). * pandora_server.conf: Example of usage in the mta_from with a fully composed email address. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3452 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 11 +++++++ pandora_server/conf/pandora_server.conf | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 3 +- pandora_server/lib/PandoraFMS/Tools.pm | 44 +++++++++++++++++++++---- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 79e4c67e0a..c0b10456cc 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,14 @@ +2010-10-22 Sancho Lerena + + * Config.pm: Parsing for mta_from doesn't remove blanks, allowing to + use a Normal name + Email address in the from. + + * Tools.pm: Email output is parsed with a html decode first. + Added timeticks option for tools (intented to use in the future). + + * pandora_server.conf: Example of usage in the mta_from with a fully + composed email address. + 2010-10-22 Junichi Satoh * lib/PandoraFMS/NetworkServer.pm: Deleted Solaris specific SNMPGET diff --git a/pandora_server/conf/pandora_server.conf b/pandora_server/conf/pandora_server.conf index 5ffa8566d5..39cf2c0820 100755 --- a/pandora_server/conf/pandora_server.conf +++ b/pandora_server/conf/pandora_server.conf @@ -190,7 +190,7 @@ mta_address localhost # mta_from Email address that sends the mail, by default is pandora@localhost # probably you need to change it to avoid problems with your antispam -#mta_from pandora@sampledomain.com +#mta_from Pandora FMS # xprobe2: Optional package to detect OS types using advanced TCP/IP # fingerprinting tecniques, much more accurates than stadard nmap. diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 8c9ad8aeba..218b170e1e 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -376,7 +376,7 @@ sub pandora_load_config { $pa_config->{'mta_auth'}= clean_blank($1); } elsif ($parametro =~ m/^mta_from\s(.*)/i) { - $pa_config->{'mta_from'}= clean_blank($1); + $pa_config->{'mta_from'}= $1; } elsif ($parametro =~ m/^snmp_logfile\s(.*)/i) { $pa_config->{'snmp_logfile'}= clean_blank($1); @@ -570,7 +570,6 @@ sub pandora_load_config { } } # end of loop for parameter # - if (($pa_config->{"verbosity"} > 4) && ($pa_config->{"quiet"} == 0)){ if ($pa_config->{"PID"} ne ""){ print " [*] PID File is written at ".$pa_config->{'PID'}."\n"; diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index dbebaaf0a3..0a42636df1 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -21,8 +21,11 @@ use warnings; use Time::Local; use POSIX qw(setsid strftime); use POSIX; -use PandoraFMS::Sendmail; # New in 2.0. Used to sendmail internally, without external scripts -#use Module::Loaded; +use PandoraFMS::Sendmail; +use HTML::Entities; + +# New in 3.2. Used to sendmail internally, without external scripts +# use Module::Loaded; # Used to calculate the MD5 checksum of a string use constant MOD232 => 2**32; @@ -55,6 +58,7 @@ our @EXPORT = qw( md5_init pandora_ping pandora_ping_latency + ticks_totime ); ########################################################################## @@ -166,15 +170,15 @@ sub pandora_daemonize { ########################################################################## sub pandora_sendmail { - - #WARNING: To use MTA Auth is needed v0.79_16 or higer of Mail:Sendmail - #http://cpansearch.perl.org/src/MIVKOVIC/Mail-Sendmail-0.79_16/Sendmail.pm my $pa_config = $_[0]; my $to_address = $_[1]; my $subject = $_[2]; my $message = $_[3]; + $subject = decode_entities ($subject); + $message = decode_entities ($message); + my %mail = ( To => $to_address, Message => $message, Subject => $subject, @@ -192,7 +196,9 @@ sub pandora_sendmail { return; } else { logger ($pa_config, "[ERROR] Sending email to $to_address with subject $subject", 1); - logger ($pa_config, "ERROR Code: $Mail::Sendmail::error", 5); + if (defined($Mail::Sendmail::error)){ + logger ($pa_config, "ERROR Code: $Mail::Sendmail::error", 5); + } } } @@ -551,6 +557,32 @@ sub free_mem { return $free_mem; } +########################################################################## +## SUB ticks_totime + # Transform a snmp timeticks count in a date +########################################################################## + +sub ticks_totime ($){ + + # Calculate ticks per second, minute, hour, and day + my $TICKS_PER_SECOND = 100; + my $TICKS_PER_MINUTE = $TICKS_PER_SECOND * 60; + my $TICKS_PER_HOUR = $TICKS_PER_MINUTE * 60; + my $TICKS_PER_DAY = $TICKS_PER_HOUR * 24; + + my $ticks = shift; + + if (!defined($ticks)){ + return ""; + } + + my $seconds = int($ticks / $TICKS_PER_SECOND) % 60; + my $minutes = int($ticks / $TICKS_PER_MINUTE) % 60; + my $hours = int($ticks / $TICKS_PER_HOUR) % 24; + my $days = int($ticks / $TICKS_PER_DAY); + + return "$days days, $hours hours, $minutes minutes, $seconds seconds"; +} ############################################################################## =head2 C<< pandora_ping (I<$pa_config>, I<$host>) >>