PageRenderTime 163ms CodeModel.GetById 80ms app.highlight 7ms RepoModel.GetById 74ms app.codeStats 0ms

/beacon/dynatrace/index.php

http://showslow.googlecode.com/
PHP | 108 lines | 91 code | 12 blank | 5 comment | 12 complexity | a8e8690716fbd31ff31fa30250eac210 MD5 | raw file
  1<?php 
  2require_once(dirname(dirname(dirname(__FILE__))).'/global.php');
  3
  4function updateUrlAggregates($url_id, $measurement_id)
  5{
  6	# updating latest values for the URL
  7	$query = sprintf("UPDATE urls SET dynatrace_last_id = %d, last_update = now() WHERE id = %d",
  8		mysql_real_escape_string($measurement_id),
  9		mysql_real_escape_string($url_id)
 10	);
 11
 12	$result = mysql_query($query);
 13
 14	if (!$result) {
 15		beaconError(mysql_error());
 16	}
 17}
 18
 19$post_data = file_get_contents("php://input");
 20$post = json_decode($post_data, true);
 21
 22/*
 23	Only URL and rank will be mandatory - the rest will be optional
 24*/
 25if (!is_null($post) && array_key_exists('url', $post)
 26	&& array_key_exists('rank', $post) && filter_var($post['rank'], FILTER_VALIDATE_INT) !== false)
 27{
 28	$url_id = getUrlId(urldecode($post['url']));
 29
 30	if (array_key_exists('ranks', $post)) {
 31		$ranks = $post['ranks'];
 32
 33		$cache	= array_key_exists('cache', $ranks) && array_key_exists('rank', $ranks['cache']) ?
 34				$ranks['cache']['rank'] : null;
 35		$net	= array_key_exists('net', $ranks) && array_key_exists('rank', $ranks['net']) ?
 36				$ranks['net']['rank'] : null;
 37		$server	= array_key_exists('server', $ranks) && array_key_exists('rank', $ranks['server']) ?
 38				$ranks['server']['rank'] : null;
 39		$js	= array_key_exists('js', $ranks) && array_key_exists('rank', $ranks['js']) ?
 40				$ranks['js']['rank'] : null;
 41	}
 42
 43	# adding new entry
 44	$query = sprintf("INSERT INTO dynatrace (
 45		version, url_id,
 46		rank, cache, net, server, js,
 47		timetoimpression, timetoonload, timetofullload,
 48		reqnumber, xhrnumber, pagesize, cachablesize, noncachablesize,
 49		timeonnetwork, timeinjs, timeinrendering,
 50		details
 51	)
 52	VALUES (
 53		'%s', '%d',
 54		'%d', '%d', '%d', '%d', '%d',
 55		'%d', '%d', '%d',
 56		'%d', '%d', '%d', '%d', '%d',
 57		'%d', '%d', '%d',
 58		'%s'
 59	)",
 60		mysql_real_escape_string(array_key_exists('version', $post) ? $post['version'] : null),
 61		mysql_real_escape_string($url_id),
 62		mysql_real_escape_string($post['rank']),
 63		mysql_real_escape_string($cache),
 64		mysql_real_escape_string($net),
 65		mysql_real_escape_string($server),
 66		mysql_real_escape_string($js),
 67		mysql_real_escape_string(array_key_exists('timetoimpression', $post) ? $post['timetoimpression'] : null),
 68		mysql_real_escape_string(array_key_exists('timetoonload', $post) ? $post['timetoonload'] : null),
 69		mysql_real_escape_string(array_key_exists('timetofullload', $post) ? $post['timetofullload'] : null),
 70		mysql_real_escape_string(array_key_exists('reqnumber', $post) ? $post['reqnumber'] : null),
 71		mysql_real_escape_string(array_key_exists('xhrnumber', $post) ? $post['xhrnumber'] : null),
 72		mysql_real_escape_string(array_key_exists('pagesize', $post) ? $post['pagesize'] : null),
 73		mysql_real_escape_string(array_key_exists('cachablesize', $post) ? $post['cachablesize'] : null),
 74		mysql_real_escape_string(array_key_exists('noncachablesize', $post) ? $post['noncachablesize'] : null),
 75		mysql_real_escape_string(array_key_exists('timeonnetwork', $post) ? $post['timeonnetwork'] : null),
 76		mysql_real_escape_string(array_key_exists('timeinjs', $post) ? $post['timeinjs'] : null),
 77		mysql_real_escape_string(array_key_exists('timeinrendering', $post) ? $post['timeinrendering'] : null),
 78		mysql_real_escape_string($post_data)
 79	);
 80
 81	if (!mysql_query($query))
 82	{
 83		beaconError(mysql_error());
 84	}
 85
 86	updateUrlAggregates($url_id, mysql_insert_id());
 87} else {
 88	header('HTTP/1.0 400 Bad Request');
 89
 90	?><html>
 91<head>
 92<title>Bad Request: dynaTrace AJAX Edition beacon</title>
 93</head>
 94<body>
 95<h1>Bad Request: dynaTrace AJAX Edition beacon</h1>
 96<p>This is <a href="http://ajax.dynatrace.com/">dynaTrace AJAX Edition</a> beacon entry point.</p>
 97
 98<h1>Configure dynaTrace AJAX Edition</h1>
 99<p><b style="color: red">WARNING! Only use this beacon If you're OK with all your dynaTrace AJAX Edition data to be recorded by this instance of ShowSlow and displayed at <a href="<?php echo $showslow_base?>"><?php echo $showslow_base?></a><br/>You can also <a href="http://www.showslow.org/Installation_and_configuration">install ShowSlow on your own server</a> to limit the risk.</b></p>
100
101<p><b>TODO - insert real documentation</b></p>
102
103</body></html>
104<?php
105	exit;
106}
107
108header('HTTP/1.0 204 Data accepted');