Data_Warehouse/getDBLog.php

35 lines
1.4 KiB
PHP
Raw Normal View History

2021-03-19 17:26:42 +00:00
<?php
ini_set("memory_limit","8024M");
header('Access-Control-Allow-Origin: *');
date_default_timezone_set('UTC');
$api_key = "cC7d2DHDnEwJTwiHLakhyjZGKLyWR";
if( isset($_REQUEST['apiKey']) && $_REQUEST['apiKey'] == $api_key && isset($_REQUEST['timestamp']) && is_numeric($_REQUEST['timestamp']) ) {
$connect = mysqli_connect ('example-cluster-1.cluster-xxxxxxxxxx.ca-central-1.rds.amazonaws.com', 'dbuser', 'password');
mysqli_select_db ( $connect,'mysql');
$output = '{ "message": "", "data": { "transactions": [';
// Get the data from the current log
$query = 'select UNIX_TIMESTAMP(event_time) as event_time,argument from mysql.general_log where (upper(argument) like "%INSERT %" or upper(argument) like "%UPDATE %" or upper(argument) like "%CREATE %") and argument NOT LIKE "%mysql.rds_heartbeat2%" AND argument NOT LIKE "%INFORMATION_SCHEMA.GLOBAL_STATUS%"';
$result = mysqli_query ( $connect, $query);
while ($thedata = mysqli_fetch_assoc($result)) {
$output = $output . '{"event_time" : "' . str_replace('"', '\"', $thedata["event_time"]) . '","argument" : "' . str_replace('"', '\"', str_replace('\"', '\\\"', str_replace("\'", "'", $thedata["argument"]))) . '"},';
}
$output = rtrim($output, ",");
$output = $output . ']}}';
// Rotate the general log table
$query = 'CALL mysql.rds_rotate_general_log';
$result = mysqli_query ( $connect, $query);
echo $output;
}else{
echo '{ "message": "Invalid post variables", "data": {}}';
}
?>