forked from curtbraz/WhosHere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckAlerts.php
77 lines (50 loc) · 1.67 KB
/
CheckAlerts.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
<?php
$webhook = 'IFTTT_WEBHOOK_GOES_HERE';
require_once 'dbconfig.php';
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// ADDS NEW ASSETS NOT PREVIOUSLY SEEN
$sql = "CALL AddAssets();";
$result = $conn->query($sql);
// UPDATES LastSeen FOR ALL ASSETS
$sql = "CALL UpdateAssetsLastSeen();";
$result = $conn->query($sql);
// LOOKS FOR RECENT PROBES FOR ASSETS THAT HAVE A NOTIFICATION FLAG SET
$sql = "CALL NotificationLogic();";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$LastSeen = date('h:i:s A', strtotime($row["LastSeen"]));
// SEND NOTIFICATION TO SLACK
$cmd = "curl -X POST -H 'Content-type: application/json' --data '{\"value1\" : \"".$row["Nickname"]."\", \"value2\" : \"".$LastSeen."\", \"value3\" : \"".$row["SignalStrength"]."\"}' ".$webhook;
echo $cmd."/r/n";
// UPDATES LastSeen FOR THIS ASSET
// Create connection
$conn2 = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn2->connect_error) {
die("Connection failed: " . $conn2->connect_error);
}
$sql1 = "CALL UpdateSingleAsset('".$row["MAC"]."');";
$result1 = $conn2->query($sql1);
$conn2->close();
exec($cmd);
}
}
$conn->close();
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// TRUNCATES LOG TABLE FOR PERFORMANCE REASONS
$sql = "CALL PurgeLogs();";
$result = $conn->query($sql);
$conn->close();
?>