2012-09-11 Miguel de Dios <miguel.dedios@artica.es>

* lib/PandoraFMS/Core.pm: changed to use own code instead the
	external module Time::Piece.
	
	* lib/PandoraFMS/Tools.pm: added function "month_have_days" for
	to get the count of days for any month in any year.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6955 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-09-11 16:30:55 +00:00
parent cfe6055a0c
commit f7c574f939
3 changed files with 186 additions and 100 deletions

View File

@ -1,3 +1,11 @@
2012-09-11 Miguel de Dios <miguel.dedios@artica.es>
* lib/PandoraFMS/Core.pm: changed to use own code instead the
external module Time::Piece.
* lib/PandoraFMS/Tools.pm: added function "month_have_days" for
to get the count of days for any month in any year.
2012-09-10 Vanessa Gil <vanessa.gil@artica.es>
* lib/PandoraFMS/Core.pm: Added several fields

View File

@ -111,12 +111,6 @@ use HTML::Entities;
use Time::Local;
use POSIX qw(strftime);
#This library need for planned downtimes for periodical weekly and monthly
use Time::Piece;
#And the with $var = localtime();
#print "Day in the week is ", $var1->_wday
#if it is sunday return 0 instead to 7
# Force XML::Simple to use XML::Parser instead SAX to manage XML
# due a bug processing some XML with blank spaces.
# See http://www.perlmonks.org/?node_id=706838
@ -1360,10 +1354,19 @@ Start the planned downtime, the monthly type.
########################################################################
sub pandora_planned_downtime_monthly_start($$) {
my ($pa_config, $dbh) = @_;
my $local_time = localtime();
my $number_day_month = $local_time->mday;
my $number_last_day_month = $local_time->month_last_day;
my $time = $local_time->hms;
#my $local_time = localtime();
my @var_localtime = localtime(time);
my $year = $var_localtime[5] + 1900;
my $month = $var_localtime[4];
#my $number_day_month = $local_time->mday;
my $number_day_month = $var_localtime[3];
#my $number_last_day_month = $local_time->month_last_day;
my $number_last_day_month = month_have_days($month, $year);
#my $time = $local_time->hms;
my $time = $var_localtime[2] . ":" . $var_localtime[1] . ":" . $var_localtime[0];
# Start pending downtimes
my @downtimes = get_db_rows($dbh, 'SELECT *
@ -1374,14 +1377,17 @@ sub pandora_planned_downtime_monthly_start($$) {
foreach my $downtime (@downtimes) {
#Convert to identical type.
my $date_downtime = Time::Piece->strptime(
$downtime->{'periodically_time_from'},
"%H:%M:%S");
my $date_now_time = Time::Piece->strptime(
$time,
"%H:%M:%S");
if ($date_now_time >= $date_downtime) {
#my $date_downtime = Time::Piece->strptime(
# $downtime->{'periodically_time_from'},
# "%H:%M:%S");
#my $date_now_time = Time::Piece->strptime(
# $time,
# "%H:%M:%S");
#
#if ($date_now_time >= $date_downtime) {
if (($time gt $downtime->{'periodically_time_from'})
|| ($time eq $downtime->{'periodically_time_from'})) {
if (!defined($downtime->{'description'})) {
$downtime->{'description'} = "N/A";
@ -1391,7 +1397,7 @@ sub pandora_planned_downtime_monthly_start($$) {
$downtime->{'name'} = "N/A";
}
logger($pa_config, "Starting planned downtime '" . $downtime->{'name'} . "'.", 1);
logger($pa_config, "Starting planned monthly downtime '" . $downtime->{'name'} . "'.", 1);
db_do($dbh, 'UPDATE tplanned_downtime
SET executed = 1
@ -1422,10 +1428,19 @@ Start the planned downtime, the montly type.
########################################################################
sub pandora_planned_downtime_monthly_stop($$) {
my ($pa_config, $dbh) = @_;
my $local_time = localtime();
my $number_day_month = $local_time->mday;
my $number_last_day_month = $local_time->month_last_day;
my $time = $local_time->hms;
#my $local_time = localtime();
my @var_localtime = localtime(time);
my $year = $var_localtime[5] + 1900;
my $month = $var_localtime[4];
#my $number_day_month = $local_time->mday;
my $number_day_month = $var_localtime[3];
#my $number_last_day_month = $local_time->month_last_day;
my $number_last_day_month = month_have_days($month, $year);
#my $time = $local_time->hms;
my $time = $var_localtime[2] . ":" . $var_localtime[1] . ":" . $var_localtime[0];
#With this stop the planned downtime for 31 (or 30) day in months
# with less days.
@ -1451,14 +1466,16 @@ sub pandora_planned_downtime_monthly_stop($$) {
foreach my $downtime (@downtimes) {
#Convert to identical type.
my $date_downtime = Time::Piece->strptime(
$downtime->{'periodically_time_to'},
"%H:%M:%S");
my $date_now_time = Time::Piece->strptime(
$time,
"%H:%M:%S");
if ($date_now_time <= $date_downtime) {
#my $date_downtime = Time::Piece->strptime(
# $downtime->{'periodically_time_to'},
# "%H:%M:%S");
#my $date_now_time = Time::Piece->strptime(
# $time,
# "%H:%M:%S");
#
#if ($date_now_time <= $date_downtime) {
if (($time lt $downtime->{'periodically_time_to'})
|| ($time eq $downtime->{'periodically_time_to'})) {
if (!defined($downtime->{'description'})) {
$downtime->{'description'} = "N/A";
@ -1468,7 +1485,7 @@ sub pandora_planned_downtime_monthly_stop($$) {
$downtime->{'name'} = "N/A";
}
logger($pa_config, "Stopping planned downtime '" . $downtime->{'name'} . "'.", 1);
logger($pa_config, "Stopping planned monthly downtime '" . $downtime->{'name'} . "'.", 1);
db_do($dbh, 'UPDATE tplanned_downtime
SET executed = 0
@ -1498,9 +1515,15 @@ Start the planned downtime, the montly type.
########################################################################
sub pandora_planned_downtime_weekly_start($$) {
my ($pa_config, $dbh) = @_;
my $local_time = localtime();
my $number_day_week = $local_time->_wday;
my $time = $local_time->hms;
#my $local_time = localtime();
my @var_localtime = localtime(time);
#my $number_day_week = $local_time->_wday;
my $number_day_week = $var_localtime[6];
#my $time = $local_time->hms;
my $time = $var_localtime[2] . ":" . $var_localtime[1] . ":" . $var_localtime[0];
my $found = 0;
# Start pending downtimes
@ -1540,16 +1563,22 @@ sub pandora_planned_downtime_weekly_start($$) {
$found = 1;
}
logger($pa_config, "Debug time = " . $time, 5);
logger($pa_config, "Debug periodically_time_to = " .
$downtime->{'periodically_time_to'}, 5);
if ($found) {
#Convert to identical type.
my $date_downtime = Time::Piece->strptime(
$downtime->{'periodically_time_from'},
"%H:%M:%S");
my $date_now_time = Time::Piece->strptime(
$time,
"%H:%M:%S");
if ($date_now_time >= $date_downtime) {
#my $date_downtime = Time::Piece->strptime(
# $downtime->{'periodically_time_from'},
# "%H:%M:%S");
#my $date_now_time = Time::Piece->strptime(
# $time,
# "%H:%M:%S");
#
#if ($date_now_time >= $date_downtime) {
if (($time gt $downtime->{'periodically_time_from'})
|| ($time eq $downtime->{'periodically_time_from'})) {
if (!defined($downtime->{'description'})) {
$downtime->{'description'} = "N/A";
}
@ -1558,7 +1587,7 @@ sub pandora_planned_downtime_weekly_start($$) {
$downtime->{'name'} = "N/A";
}
logger($pa_config, "Starting planned downtime '" . $downtime->{'name'} . "'.", 1);
logger($pa_config, "Starting planned weekly downtime '" . $downtime->{'name'} . "'.", 1);
db_do($dbh, 'UPDATE tplanned_downtime
SET executed = 1
@ -1589,9 +1618,15 @@ Stop the planned downtime, the montly type.
########################################################################
sub pandora_planned_downtime_weekly_stop($$) {
my ($pa_config, $dbh) = @_;
my $local_time = localtime();
my $number_day_week = $local_time->_wday;
my $time = $local_time->hms;
#my $local_time = localtime();
my @var_localtime = localtime(time);
#my $number_day_week = $local_time->_wday;
my $number_day_week = $var_localtime[6];
#my $time = $local_time->hms;
my $time = $var_localtime[2] . ":" . $var_localtime[1] . ":" . $var_localtime[0];
my $found = 0;
# Start pending downtimes
@ -1602,14 +1637,21 @@ sub pandora_planned_downtime_weekly_stop($$) {
foreach my $downtime (@downtimes) {
#Convert to identical type.
my $date_downtime = Time::Piece->strptime(
$downtime->{'periodically_time_to'},
"%H:%M:%S");
my $date_now_time = Time::Piece->strptime(
$time,
"%H:%M:%S");
#my $date_downtime = Time::Piece->strptime(
# $downtime->{'periodically_time_to'},
# "%H:%M:%S");
#my $date_now_time = Time::Piece->strptime(
# $time,
# "%H:%M:%S");
#
#if ($date_now_time <= $date_downtime) {
if ($date_now_time <= $date_downtime) {
logger($pa_config, "Debug time = " . $time, 5);
logger($pa_config, "Debug periodically_time_to = " .
$downtime->{'periodically_time_to'}, 5);
if (($time lt $downtime->{'periodically_time_to'})
|| ($time eq $downtime->{'periodically_time_to'})) {
if (!defined($downtime->{'description'})) {
$downtime->{'description'} = "N/A";
@ -1619,7 +1661,7 @@ sub pandora_planned_downtime_weekly_stop($$) {
$downtime->{'name'} = "N/A";
}
logger($pa_config, "Starting planned downtime '" . $downtime->{'name'} . "'.", 1);
logger($pa_config, "Stopping planned weekly downtime '" . $downtime->{'name'} . "'.", 1);
db_do($dbh, 'UPDATE tplanned_downtime
SET executed = 0

View File

@ -66,6 +66,7 @@ our @EXPORT = qw(
ticks_totime
safe_input
safe_output
month_have_days
);
########################################################################
@ -883,13 +884,13 @@ sub pandora_ping ($$) {
return $output;
}
##############################################################################
########################################################################
=head2 C<< pandora_ping_latency (I<$pa_config>, I<$host>) >>
Ping the given host. Returns the average round-trip time.
=cut
##############################################################################
########################################################################
sub pandora_ping_latency ($$) {
my ($pa_config, $host) = @_;
@ -990,6 +991,41 @@ sub pandora_ping_latency ($$) {
return $output;
}
########################################################################
=head2 C<< month_have_days (I<$month>, I<$year>) >>
Pass a $month (as january 0 number and each month with numbers) and the year
as number (for example 1981). And return the days of this month.
=cut
########################################################################
sub month_have_days($$) {
my $month= shift(@_);
my $year= @_ ? shift(@_) : (1900 + (localtime())[5]);
my @monthDays= qw( 31 28 31 30 31 30 31 31 30 31 30 31 );
if ( $year <= 1752 ) {
# Note: Although September 1752 only had 19 days,
# they were numbered 1,2,14..30!
if (1752 == $year && 9 == $month) {
return 19;
}
if (2 == $month && 0 == $year % 4) {
return 29;
}
}
else {
#Check if Leap year
if (2 == $month && 0 == $year % 4 && 0 == $year%100
|| 0 == $year%400) {
return 29;
}
}
return $monthDays[$month];
}
# End of function declaration
# End of defined Code