PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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
  2. require_once(dirname(dirname(dirname(__FILE__))).'/global.php');
  3. function updateUrlAggregates($url_id, $measurement_id)
  4. {
  5. # updating latest values for the URL
  6. $query = sprintf("UPDATE urls SET dynatrace_last_id = %d, last_update = now() WHERE id = %d",
  7. mysql_real_escape_string($measurement_id),
  8. mysql_real_escape_string($url_id)
  9. );
  10. $result = mysql_query($query);
  11. if (!$result) {
  12. beaconError(mysql_error());
  13. }
  14. }
  15. $post_data = file_get_contents("php://input");
  16. $post = json_decode($post_data, true);
  17. /*
  18. Only URL and rank will be mandatory - the rest will be optional
  19. */
  20. if (!is_null($post) && array_key_exists('url', $post)
  21. && array_key_exists('rank', $post) && filter_var($post['rank'], FILTER_VALIDATE_INT) !== false)
  22. {
  23. $url_id = getUrlId(urldecode($post['url']));
  24. if (array_key_exists('ranks', $post)) {
  25. $ranks = $post['ranks'];
  26. $cache = array_key_exists('cache', $ranks) && array_key_exists('rank', $ranks['cache']) ?
  27. $ranks['cache']['rank'] : null;
  28. $net = array_key_exists('net', $ranks) && array_key_exists('rank', $ranks['net']) ?
  29. $ranks['net']['rank'] : null;
  30. $server = array_key_exists('server', $ranks) && array_key_exists('rank', $ranks['server']) ?
  31. $ranks['server']['rank'] : null;
  32. $js = array_key_exists('js', $ranks) && array_key_exists('rank', $ranks['js']) ?
  33. $ranks['js']['rank'] : null;
  34. }
  35. # adding new entry
  36. $query = sprintf("INSERT INTO dynatrace (
  37. version, url_id,
  38. rank, cache, net, server, js,
  39. timetoimpression, timetoonload, timetofullload,
  40. reqnumber, xhrnumber, pagesize, cachablesize, noncachablesize,
  41. timeonnetwork, timeinjs, timeinrendering,
  42. details
  43. )
  44. VALUES (
  45. '%s', '%d',
  46. '%d', '%d', '%d', '%d', '%d',
  47. '%d', '%d', '%d',
  48. '%d', '%d', '%d', '%d', '%d',
  49. '%d', '%d', '%d',
  50. '%s'
  51. )",
  52. mysql_real_escape_string(array_key_exists('version', $post) ? $post['version'] : null),
  53. mysql_real_escape_string($url_id),
  54. mysql_real_escape_string($post['rank']),
  55. mysql_real_escape_string($cache),
  56. mysql_real_escape_string($net),
  57. mysql_real_escape_string($server),
  58. mysql_real_escape_string($js),
  59. mysql_real_escape_string(array_key_exists('timetoimpression', $post) ? $post['timetoimpression'] : null),
  60. mysql_real_escape_string(array_key_exists('timetoonload', $post) ? $post['timetoonload'] : null),
  61. mysql_real_escape_string(array_key_exists('timetofullload', $post) ? $post['timetofullload'] : null),
  62. mysql_real_escape_string(array_key_exists('reqnumber', $post) ? $post['reqnumber'] : null),
  63. mysql_real_escape_string(array_key_exists('xhrnumber', $post) ? $post['xhrnumber'] : null),
  64. mysql_real_escape_string(array_key_exists('pagesize', $post) ? $post['pagesize'] : null),
  65. mysql_real_escape_string(array_key_exists('cachablesize', $post) ? $post['cachablesize'] : null),
  66. mysql_real_escape_string(array_key_exists('noncachablesize', $post) ? $post['noncachablesize'] : null),
  67. mysql_real_escape_string(array_key_exists('timeonnetwork', $post) ? $post['timeonnetwork'] : null),
  68. mysql_real_escape_string(array_key_exists('timeinjs', $post) ? $post['timeinjs'] : null),
  69. mysql_real_escape_string(array_key_exists('timeinrendering', $post) ? $post['timeinrendering'] : null),
  70. mysql_real_escape_string($post_data)
  71. );
  72. if (!mysql_query($query))
  73. {
  74. beaconError(mysql_error());
  75. }
  76. updateUrlAggregates($url_id, mysql_insert_id());
  77. } else {
  78. header('HTTP/1.0 400 Bad Request');
  79. ?><html>
  80. <head>
  81. <title>Bad Request: dynaTrace AJAX Edition beacon</title>
  82. </head>
  83. <body>
  84. <h1>Bad Request: dynaTrace AJAX Edition beacon</h1>
  85. <p>This is <a href="http://ajax.dynatrace.com/">dynaTrace AJAX Edition</a> beacon entry point.</p>
  86. <h1>Configure dynaTrace AJAX Edition</h1>
  87. <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>
  88. <p><b>TODO - insert real documentation</b></p>
  89. </body></html>
  90. <?php
  91. exit;
  92. }
  93. header('HTTP/1.0 204 Data accepted');