The URI of TUHH Docker Registry changed from "docker.rz.tu-harburg.de:5000" to "docker.rz.tu-harburg.de". Please update your gitlab-ci.yml files if you use images from this registry.

Commit c2d2f142 authored by Tobias Zeumer's avatar Tobias Zeumer

Monitoring: Add a most primitive logging mechanism; #34

parent 9918f036
node_modules
logs/*.log
\ No newline at end of file
......@@ -6,6 +6,7 @@
// Config vars
var pathJsSavePng = 'node_modules/save-svg-as-png/lib/saveSvgAsPng.js';
var screenSaverTime = 5 * 60 * 1000; // Reset page after 5 minutes
var allow_logging = true; // Requires php. Logs field:value with /logger.php
// Language and URL
var lang = new Lang();
......@@ -1042,3 +1043,66 @@ function search(input_value) {
}
}
/**
* Shorthand to log "field":"value" with ajax_request()
*
* @param {string} field Logging vector name
* @param {string} data Data to log
*
* @return {void}
*/function log(field, data) {
// Loggin allowed in settings?
if (allow_logging) {
let qryData = new FormData();
qryData.append(field, data);
ajax_request(qryData);
}
}
/**
* Simply send some data to the server without requiring a response
*
* Initial purpose: Logging what people use the search field for - what are they
* expecting?
*
* @param {obj} data A FormData object
* @param {string} url Submit url; defaults to logger.php
* @param {string} callback (Future use for callback function)
*
* @return {void}
*/
function ajax_request(data, url, callback) {
if (url === undefined) url = 'logger.php';
var xhr = new XMLHttpRequest();
// set a handler for changes in ready state
if (callback !== undefined) {
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
// check for HTTP status of OK
if (xhr.status == 200) {
try {
callback(JSON.parse(xhr.responseText));
}
catch(e) {
console.log(xhr.responseText); // for debug
console.log("AJAX request incomplete:\n" + e.toString());
}
}
else if (xhr.status == 0) {
// ignore firefox
}
else {
console.log("AJAX request failed: " + xhr.status);
}
}
};
}
// open connection and send payload
xhr.open("POST", url);
// The data sent is what the user provided (in the form)
xhr.send(data);
}
<?php
// Config
$request = array();
$dir = 'logs';
$host = $_SERVER['SERVER_NAME'];
$valid_req = array_flip(array('searchterm', 'wakeup'));
// Clean any $_POST
if (isset($_POST)) {
filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$request = $_POST;
}
// Just log the $_POST['field'] = val to file
// Append hostname to file so it's not unintentionally overwritten when uploading
// new map version
if (count($request) > 0) {
foreach ($request as $watch => $data) {
// Only log what we allow
if (isset($valid_req[$watch])) {
$file_log_alltime = "$dir/$watch-$host.log";
$file_log_today = "$dir/".date('Y-m-d')."-$watch-$host.log";
$entry = date('Y-m-d H:i:s').":\t".$data."\n";
file_put_contents($file_log_alltime, $entry, FILE_APPEND);
file_put_contents($file_log_today, $entry, FILE_APPEND);
}
}
}
// Otherwise list files
else {
$loglist = scandir($dir);
unset($loglist[0]); // "."
unset($loglist[1]); // ".."
echo '<ul>';
foreach ($loglist as $file) {
$path = $dir.'/'.$file;
echo '<li><a href="'.$path.'">'.$file.'</a></li>';
}
echo '</ul>';
}
?>
\ No newline at end of file
# Changes in these folder/files should reasonably never be tracked/pushed
vendor/*
composer.lock
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment