コード例 #1
0
ファイル: put.php プロジェクト: oliver/gatemon-html
    header('Status: 400 Bad Request');
    error_log('UUID is not valid');
    exit(2);
}
// Check for time deviation larger 1 minute
if (abs(strtotime($json_decoded['lastupdated']) - time()) > 90) {
    header('Status: 400 Bad Request');
    error_log('Node date deviation too large');
    exit(2);
}
// Overwrite lastupdated with servers time to make timestamps comparable
$json_decoded['lastupdated'] = time();
// Store JSON
file_put_contents($data_dir . '/' . preg_replace('/[^\\da-z]/i', '', substr($json_decoded['uuid'], 0, 30)) . '.json', $json);
$summarizer = new Summarizer();
// Clean up old files and sum up results
foreach (glob($data_dir . '/*') as $file) {
    if (basename($file) == 'merged.json' || basename($file) == 'overall.json') {
        continue;
    }
    if (filemtime($file) < strtotime('-8 hours')) {
        unlink($file);
        continue;
    }
    $json = json_decode(file_get_contents($file));
    $json_merged[] = $json;
    $summarizer->addMonitorResults($json);
}
file_put_contents($data_dir . '/merged.json', json_encode($json_merged));
$overall_state = $summarizer->getSummary();
file_put_contents($data_dir . '/overall.json', json_encode($overall_state));