-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_outages.php
executable file
·53 lines (42 loc) · 1.29 KB
/
find_outages.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
#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once('common.php');
$query = 'SELECT id, name FROM sensor_values';
$data = db_query($query);
$values = array();
foreach($data as $row) {
$values[$row['id']] = $row['name'];
}
$query = 'SELECT id, sensor, description FROM sensors';
$data = db_query($query);
foreach($data as $row) {
$sensor = $row['sensor'];
$description = $row['description'];
if($description == '') {
$description = "Sensor $sensor";
}
$sensors[$row['id']] = $description;
}
$query = 'SELECT sensor, what FROM sensor_data GROUP BY sensor, what';
$data = db_query($query);
foreach($data as $row) {
$sensor = $row['sensor'];
$what = $row['what'];
echo $sensors[$sensor] . ', ' . $values[$what] . "\n";
$query2 = 'SELECT UNIX_TIMESTAMP(timestamp) timestamp FROM sensor_data WHERE sensor = ? AND what = ? ORDER BY id ASC';
$data2 = db_query($query2, array($sensor, $what));
$previous_timestamp = intval($data2[0]['timestamp']);
for($a=1; $a<count($data2); $a++) {
$timestamp = intval($data2[$a]['timestamp']);
if($timestamp-$previous_timestamp > $config['outage_period']) {
echo 'Outage from ';
echo date('Y-m-d H:i', $previous_timestamp);
echo ' to ';
echo date('Y-m-d H:i', $timestamp);
echo "\n";
}
$previous_timestamp = $timestamp;
}
echo "\n";
}