mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
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:
parent
0643e26f02
commit
fe7bd3cad4
@ -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>
|
2012-09-10 Vanessa Gil <vanessa.gil@artica.es>
|
||||||
|
|
||||||
* lib/PandoraFMS/Core.pm: Added several fields
|
* lib/PandoraFMS/Core.pm: Added several fields
|
||||||
|
@ -111,12 +111,6 @@ use HTML::Entities;
|
|||||||
use Time::Local;
|
use Time::Local;
|
||||||
use POSIX qw(strftime);
|
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
|
# Force XML::Simple to use XML::Parser instead SAX to manage XML
|
||||||
# due a bug processing some XML with blank spaces.
|
# due a bug processing some XML with blank spaces.
|
||||||
# See http://www.perlmonks.org/?node_id=706838
|
# 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($$) {
|
sub pandora_planned_downtime_monthly_start($$) {
|
||||||
my ($pa_config, $dbh) = @_;
|
my ($pa_config, $dbh) = @_;
|
||||||
my $local_time = localtime();
|
#my $local_time = localtime();
|
||||||
my $number_day_month = $local_time->mday;
|
my @var_localtime = localtime(time);
|
||||||
my $number_last_day_month = $local_time->month_last_day;
|
my $year = $var_localtime[5] + 1900;
|
||||||
my $time = $local_time->hms;
|
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
|
# Start pending downtimes
|
||||||
my @downtimes = get_db_rows($dbh, 'SELECT *
|
my @downtimes = get_db_rows($dbh, 'SELECT *
|
||||||
@ -1374,14 +1377,17 @@ sub pandora_planned_downtime_monthly_start($$) {
|
|||||||
|
|
||||||
foreach my $downtime (@downtimes) {
|
foreach my $downtime (@downtimes) {
|
||||||
#Convert to identical type.
|
#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'})) {
|
if (!defined($downtime->{'description'})) {
|
||||||
$downtime->{'description'} = "N/A";
|
$downtime->{'description'} = "N/A";
|
||||||
@ -1391,7 +1397,7 @@ sub pandora_planned_downtime_monthly_start($$) {
|
|||||||
$downtime->{'name'} = "N/A";
|
$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
|
db_do($dbh, 'UPDATE tplanned_downtime
|
||||||
SET executed = 1
|
SET executed = 1
|
||||||
@ -1422,10 +1428,19 @@ Start the planned downtime, the montly type.
|
|||||||
########################################################################
|
########################################################################
|
||||||
sub pandora_planned_downtime_monthly_stop($$) {
|
sub pandora_planned_downtime_monthly_stop($$) {
|
||||||
my ($pa_config, $dbh) = @_;
|
my ($pa_config, $dbh) = @_;
|
||||||
my $local_time = localtime();
|
#my $local_time = localtime();
|
||||||
my $number_day_month = $local_time->mday;
|
my @var_localtime = localtime(time);
|
||||||
my $number_last_day_month = $local_time->month_last_day;
|
my $year = $var_localtime[5] + 1900;
|
||||||
my $time = $local_time->hms;
|
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 this stop the planned downtime for 31 (or 30) day in months
|
||||||
# with less days.
|
# with less days.
|
||||||
@ -1451,14 +1466,16 @@ sub pandora_planned_downtime_monthly_stop($$) {
|
|||||||
|
|
||||||
foreach my $downtime (@downtimes) {
|
foreach my $downtime (@downtimes) {
|
||||||
#Convert to identical type.
|
#Convert to identical type.
|
||||||
my $date_downtime = Time::Piece->strptime(
|
#my $date_downtime = Time::Piece->strptime(
|
||||||
$downtime->{'periodically_time_to'},
|
# $downtime->{'periodically_time_to'},
|
||||||
"%H:%M:%S");
|
# "%H:%M:%S");
|
||||||
my $date_now_time = Time::Piece->strptime(
|
#my $date_now_time = Time::Piece->strptime(
|
||||||
$time,
|
# $time,
|
||||||
"%H:%M:%S");
|
# "%H:%M:%S");
|
||||||
|
#
|
||||||
if ($date_now_time <= $date_downtime) {
|
#if ($date_now_time <= $date_downtime) {
|
||||||
|
if (($time lt $downtime->{'periodically_time_to'})
|
||||||
|
|| ($time eq $downtime->{'periodically_time_to'})) {
|
||||||
|
|
||||||
if (!defined($downtime->{'description'})) {
|
if (!defined($downtime->{'description'})) {
|
||||||
$downtime->{'description'} = "N/A";
|
$downtime->{'description'} = "N/A";
|
||||||
@ -1468,7 +1485,7 @@ sub pandora_planned_downtime_monthly_stop($$) {
|
|||||||
$downtime->{'name'} = "N/A";
|
$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
|
db_do($dbh, 'UPDATE tplanned_downtime
|
||||||
SET executed = 0
|
SET executed = 0
|
||||||
@ -1498,9 +1515,15 @@ Start the planned downtime, the montly type.
|
|||||||
########################################################################
|
########################################################################
|
||||||
sub pandora_planned_downtime_weekly_start($$) {
|
sub pandora_planned_downtime_weekly_start($$) {
|
||||||
my ($pa_config, $dbh) = @_;
|
my ($pa_config, $dbh) = @_;
|
||||||
my $local_time = localtime();
|
#my $local_time = localtime();
|
||||||
my $number_day_week = $local_time->_wday;
|
my @var_localtime = localtime(time);
|
||||||
my $time = $local_time->hms;
|
|
||||||
|
#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;
|
my $found = 0;
|
||||||
|
|
||||||
# Start pending downtimes
|
# Start pending downtimes
|
||||||
@ -1540,16 +1563,22 @@ sub pandora_planned_downtime_weekly_start($$) {
|
|||||||
$found = 1;
|
$found = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger($pa_config, "Debug time = " . $time, 5);
|
||||||
|
logger($pa_config, "Debug periodically_time_to = " .
|
||||||
|
$downtime->{'periodically_time_to'}, 5);
|
||||||
|
|
||||||
if ($found) {
|
if ($found) {
|
||||||
#Convert to identical type.
|
#Convert to identical type.
|
||||||
my $date_downtime = Time::Piece->strptime(
|
#my $date_downtime = Time::Piece->strptime(
|
||||||
$downtime->{'periodically_time_from'},
|
# $downtime->{'periodically_time_from'},
|
||||||
"%H:%M:%S");
|
# "%H:%M:%S");
|
||||||
my $date_now_time = Time::Piece->strptime(
|
#my $date_now_time = Time::Piece->strptime(
|
||||||
$time,
|
# $time,
|
||||||
"%H:%M:%S");
|
# "%H:%M:%S");
|
||||||
|
#
|
||||||
if ($date_now_time >= $date_downtime) {
|
#if ($date_now_time >= $date_downtime) {
|
||||||
|
if (($time gt $downtime->{'periodically_time_from'})
|
||||||
|
|| ($time eq $downtime->{'periodically_time_from'})) {
|
||||||
if (!defined($downtime->{'description'})) {
|
if (!defined($downtime->{'description'})) {
|
||||||
$downtime->{'description'} = "N/A";
|
$downtime->{'description'} = "N/A";
|
||||||
}
|
}
|
||||||
@ -1558,7 +1587,7 @@ sub pandora_planned_downtime_weekly_start($$) {
|
|||||||
$downtime->{'name'} = "N/A";
|
$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
|
db_do($dbh, 'UPDATE tplanned_downtime
|
||||||
SET executed = 1
|
SET executed = 1
|
||||||
@ -1589,9 +1618,15 @@ Stop the planned downtime, the montly type.
|
|||||||
########################################################################
|
########################################################################
|
||||||
sub pandora_planned_downtime_weekly_stop($$) {
|
sub pandora_planned_downtime_weekly_stop($$) {
|
||||||
my ($pa_config, $dbh) = @_;
|
my ($pa_config, $dbh) = @_;
|
||||||
my $local_time = localtime();
|
#my $local_time = localtime();
|
||||||
my $number_day_week = $local_time->_wday;
|
my @var_localtime = localtime(time);
|
||||||
my $time = $local_time->hms;
|
|
||||||
|
#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;
|
my $found = 0;
|
||||||
|
|
||||||
# Start pending downtimes
|
# Start pending downtimes
|
||||||
@ -1602,14 +1637,21 @@ sub pandora_planned_downtime_weekly_stop($$) {
|
|||||||
|
|
||||||
foreach my $downtime (@downtimes) {
|
foreach my $downtime (@downtimes) {
|
||||||
#Convert to identical type.
|
#Convert to identical type.
|
||||||
my $date_downtime = Time::Piece->strptime(
|
#my $date_downtime = Time::Piece->strptime(
|
||||||
$downtime->{'periodically_time_to'},
|
# $downtime->{'periodically_time_to'},
|
||||||
"%H:%M:%S");
|
# "%H:%M:%S");
|
||||||
my $date_now_time = Time::Piece->strptime(
|
#my $date_now_time = Time::Piece->strptime(
|
||||||
$time,
|
# $time,
|
||||||
"%H:%M:%S");
|
# "%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'})) {
|
if (!defined($downtime->{'description'})) {
|
||||||
$downtime->{'description'} = "N/A";
|
$downtime->{'description'} = "N/A";
|
||||||
@ -1619,7 +1661,7 @@ sub pandora_planned_downtime_weekly_stop($$) {
|
|||||||
$downtime->{'name'} = "N/A";
|
$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
|
db_do($dbh, 'UPDATE tplanned_downtime
|
||||||
SET executed = 0
|
SET executed = 0
|
||||||
|
@ -66,6 +66,7 @@ our @EXPORT = qw(
|
|||||||
ticks_totime
|
ticks_totime
|
||||||
safe_input
|
safe_input
|
||||||
safe_output
|
safe_output
|
||||||
|
month_have_days
|
||||||
);
|
);
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
@ -883,13 +884,13 @@ sub pandora_ping ($$) {
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################################################
|
########################################################################
|
||||||
=head2 C<< pandora_ping_latency (I<$pa_config>, I<$host>) >>
|
=head2 C<< pandora_ping_latency (I<$pa_config>, I<$host>) >>
|
||||||
|
|
||||||
Ping the given host. Returns the average round-trip time.
|
Ping the given host. Returns the average round-trip time.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
##############################################################################
|
########################################################################
|
||||||
sub pandora_ping_latency ($$) {
|
sub pandora_ping_latency ($$) {
|
||||||
my ($pa_config, $host) = @_;
|
my ($pa_config, $host) = @_;
|
||||||
|
|
||||||
@ -990,6 +991,41 @@ sub pandora_ping_latency ($$) {
|
|||||||
return $output;
|
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 function declaration
|
||||||
# End of defined Code
|
# End of defined Code
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user