-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunctions.php
102 lines (92 loc) · 3.91 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
ex: set tabstop=4 shiftwidth=4 autoindent:
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2024 The Cacti Group |
| |
| 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. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
function plugin_maint_check_cacti_host($host) {
return plugin_maint_check_host(1, $host);
}
function plugin_maint_check_webseer_url($host) {
return plugin_maint_check_host(2, $host);
}
function plugin_maint_check_servcheck_test($host) {
return plugin_maint_check_host(3, $host);
}
function plugin_maint_check_host ($type, $host) {
$schedules = db_fetch_assoc_prepared('SELECT *
FROM plugin_maint_hosts
WHERE TYPE = ?
AND (host = ? OR host = 0)',
array($type, $host));
if (!empty($schedules)) {
foreach ($schedules as $s) {
if (plugin_maint_check_schedule($s['schedule'])) {
return true;
}
}
}
return false;
}
function plugin_maint_check_schedule($schedule) {
$sc = db_fetch_row_prepared('SELECT *
FROM plugin_maint_schedules
WHERE enabled = \'on\' AND id = ?',
array($schedule));
if (!empty($sc)) {
$t = time();
switch ($sc['mtype']) {
case 1:
if ($t > $sc['stime'] && $t < $sc['etime'])
return true;
break;
case 2: // Recurring
/* past, calculate next */
if ($sc['etime'] < $t) {
/* convert start and end to local so that hour stays same for add days across daylight saving time change */
$starttimelocal = (new DateTime('@' . strval($sc['stime'])))->setTimezone( new DateTimeZone( date_default_timezone_get()));
$endtimelocal = (new DateTime('@' . strval($sc['etime'])))->setTimezone( new DateTimeZone( date_default_timezone_get()));
$nowtime = new DateTime();
/* add interval days */
$addday = new DateInterval( 'P' . strval($sc['minterval'] / 86400) . 'D');
while ($endtimelocal < $nowtime) {
$starttimelocal = $starttimelocal->add( $addday );
$endtimelocal = $endtimelocal->add( $addday );
}
$sc['stime'] = $starttimelocal->getTimestamp();
$sc['etime'] = $endtimelocal->getTimestamp();
/* save next interval so not need to recalculate */
db_execute_prepared('UPDATE plugin_maint_schedules
SET stime = ?, etime = ?
WHERE id = ?',
array($sc['stime'], $sc['etime'], $schedule));
/* format yyyy-mm-dd hh:mm */
cacti_log( 'INFO: Maintenance schedule "' . $sc['name'] . '" Next start ' . $starttimelocal->format('Y-m-d H:i') .
' End ' . $endtimelocal->format('Y-m-d H:i'), false, 'MAINT' );
}
if ($t > $sc['stime'] && $t < $sc['etime']) {
return true;
}
break;
}
}
return false;
}