This repository was archived by the owner on Apr 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.php
More file actions
83 lines (67 loc) · 2.37 KB
/
check.php
File metadata and controls
83 lines (67 loc) · 2.37 KB
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
<?php
header("Content-type: text/plain; charset=utf-8");
include 'config.inc.php';
if (!isset($_SERVER['argv']) || !isset($_SERVER['argv'][1])) {
die("\nNo arguments\n\n");
}
$result = urldecode($_SERVER['argv'][1]);
$result = json_decode($result);
if (!$result) {
die("\nInvalid arguments\n\n");
}
echo "\nCRON START\n";
echo "\nChecking ".$result->serviceName.(!empty($result->port) ? ' :'.$result->port : '')." response from ".$result->ip."...\n\n";
$check = ServiceCheck::doCheck($result->ip, $result->port);//-- Make check
$now = date('YmdHis');
if ($check->status) {//-- Service is ok
$fields = array(
'updated' => $now,
'next_update' => HelperGuru::getNextUpdate($result->mmi),
'extra' => json_encode($check->msg),
'status' => 1
);
//-- Update the date and msg
new ServiceManagement($result->id);
ServiceManagement::update($fields);
if (empty($result->status)) {//-- If the service was previously down, also send the recovery alert, if set like that, and update the service's history log
if (!empty($result->recovery) && !empty($result->alert)) {
HelperGuru::sendRecoveryAlert($result->alert, $result->id);
}
$fieldsLog = array(
'user' => $result->user,
'server' => $result->server,
'service' => $result->id,
'recovery' => $now
);
ServiceManagement::logRecovery($fieldsLog);
}
ServiceManagement::removeFromAmazonQueue($result->id);
} else {//-- Boo. Service is down, just mark it offline and send the alert, if set like that
$fields = array(
'updated' => $now,
'next_update' => HelperGuru::getNextUpdate($result->mmi),
'extra' => json_encode($check->msg),
'status' => 0
);
//-- Update the date and error
new ServiceManagement($result->id);
ServiceManagement::update($fields);
if (!empty($result->status) && !empty($result->alert)) {//-- If the service wasn't previously down, also send the alert, if set like that, and update the service's history log
HelperGuru::sendAlert($result->alert, $result->id);
$fieldsLog = array(
'user' => $result->user,
'server' => $result->server,
'service' => $result->id,
'error' => $check->msg,
'date' => $now
);
ServiceManagement::logOffline($fieldsLog);
}
ServiceManagement::removeFromAmazonQueue($result->id);
}
echo "\nRESULT:\n\n";
var_dump($check);
echo "\n";
DB::end();
echo "\nCRON END\n\n";
?>