-
Notifications
You must be signed in to change notification settings - Fork 5
/
cron.php
72 lines (52 loc) · 2.07 KB
/
cron.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
<?php
include 'pages/functions.php';
if (php_sapi_name() == "cli") { //Make sure you can only run it, with "php cron.php" localy
//Cleanup Data which is older then 4 Days
$query = "SELECT id,server_timestamp FROM servers_data ORDER by id";
if ($result = $mysqli->query($query)) {
/* fetch object array */
while ($row = $result->fetch_row()) {
$time = time();
$delete = strtotime('+4 day', $row[1]);
if ($time > $delete) {
$stmt = $mysqli->prepare("DELETE FROM servers_data WHERE id = ?");
$stmt->bind_param('i', $row[0]);
$stmt->execute();
$stmt->close();
}
}
/* free result set */
$result->close();
}
//Downtime Check
$query = "SELECT id,last_update,offline_alert,offline_alert_send,server_name FROM servers ORDER by id";
if ($result = $mysqli->query($query)) {
/* fetch object array */
while ($row = $result->fetch_row()) {
$last_run = strtotime('+2 minutes', $row['1']);
if ($row['2'] == 1 AND $row['3'] == 0 AND $last_run < time() AND $row['1'] != NULL) {
$msg = "Alert: The Server ". escape($row['4']) . " has gone offline.";
$headers = "From: "._email_sender."\r\n";
mail(_email_target,"Ariane - Downtime Alert - " . escape($row['4']),$msg,$headers);
$send = 1;
$stmt = $mysqli->prepare("UPDATE servers SET offline_alert_send = ? WHERE id = ?");
$stmt->bind_param('ii',$send,$row['0']);
$stmt->execute();
$stmt->close();
} elseif ($row['2'] == 1 AND $row['3'] == 1 AND $last_run > time() AND $row['1'] != NULL) {
$msg = "Alert: The Server ". escape($row['4']) . " is back Online.";
$headers = "From: "._email_sender."\r\n";
mail(_email_target,"Ariane - Uptime Alert - " . escape($row['4']),$msg,$headers);
$send = 0;
$stmt = $mysqli->prepare("UPDATE servers SET offline_alert_send = ? WHERE id = ?");
$stmt->bind_param('ii',$send,$row['0']);
$stmt->execute();
$stmt->close();
}
}
/* free result set */
$result->close();
}
echo "ok";
}
?>