api.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="plugins-healthchecks",
  5. * description="Healthchecks.io Ping Plugin"
  6. * )
  7. */
  8. /**
  9. * @OA\Schema(
  10. * schema="healthChecksRun",
  11. * type="object",
  12. * @OA\Property(
  13. * property="response",
  14. * type="object",
  15. * @OA\Property(
  16. * property="result",
  17. * description="success or error",
  18. * type="string",
  19. * example="success",
  20. * ),
  21. * @OA\Property(
  22. * property="message",
  23. * description="success or error message",
  24. * type="string",
  25. * example=null,
  26. * ),
  27. * @OA\Property(
  28. * property="data",
  29. * description="data from api",
  30. * type="array",
  31. * @OA\Items({
  32. * @OA\Property(
  33. * property="Service Name",
  34. * type="string",
  35. * example="Radarr",
  36. * ),
  37. * @OA\Property(
  38. * property="UUID",
  39. * type="string",
  40. * example="883f0097-8f4c-4ca5-a9cf-053cfab8e334",
  41. * ),
  42. * @OA\Property(
  43. * property="External URL",
  44. * type="string",
  45. * example="https://radarr.com",
  46. * ),
  47. * @OA\Property(
  48. * property="Internal URL",
  49. * type="string",
  50. * example="http://radarr:7878",
  51. * ),
  52. * @OA\Property(
  53. * property="Enabled",
  54. * type="string",
  55. * example="true",
  56. * ),
  57. * @OA\Property(
  58. * property="results",
  59. * type="array",
  60. * @OA\Items({
  61. * @OA\Property(
  62. * property="internal",
  63. * type="string",
  64. * example="Success",
  65. * ),
  66. * @OA\Property(
  67. * property="external",
  68. * type="string",
  69. * example="Success",
  70. * ),
  71. *
  72. * }),
  73. * ),
  74. * })
  75. * ),
  76. * ),
  77. * )
  78. */
  79. $app->get('/plugins/healthchecks/settings', function ($request, $response, $args) {
  80. /**
  81. * @OA\Get(
  82. * tags={"plugins-healthchecks"},
  83. * path="/api/v2/plugins/healthchecks/settings",
  84. * summary="Get settings",
  85. * @OA\Response(
  86. * response="200",
  87. * description="Success",
  88. * @OA\JsonContent(ref="#/components/schemas/pluginSettingsPage"),
  89. * ),
  90. * @OA\Response(response="401",description="Unauthorized"),
  91. * security={{ "api_key":{} }}
  92. * )
  93. */
  94. $HealthChecks = new HealthChecks();
  95. if ($HealthChecks->checkRoute($request)) {
  96. if ($HealthChecks->qualifyRequest(1, true)) {
  97. $GLOBALS['api']['response']['data'] = $HealthChecks->_healthCheckPluginGetSettings();
  98. }
  99. }
  100. $response->getBody()->write(jsonE($GLOBALS['api']));
  101. return $response
  102. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  103. ->withStatus($GLOBALS['responseCode']);
  104. });
  105. $app->get('/plugins/healthchecks/run', function ($request, $response, $args) {
  106. /**
  107. * @OA\Get(
  108. * tags={"plugins-healthchecks"},
  109. * path="/api/v2/plugins/healthchecks/run",
  110. * summary="Run Healthchecks.io plugin",
  111. * @OA\Response(
  112. * response="200",
  113. * description="Success",
  114. * @OA\JsonContent(ref="#/components/schemas/healthChecksRun"),
  115. * ),
  116. * @OA\Response(response="401",description="Unauthorized"),
  117. * security={{ "api_key":{} }}
  118. * )
  119. */
  120. $HealthChecks = new HealthChecks();
  121. if ($HealthChecks->checkRoute($request)) {
  122. if ($HealthChecks->qualifyRequest($HealthChecks->config['HEALTHCHECKS-Auth-include'], true)) {
  123. $HealthChecks->_healthCheckPluginRun();
  124. }
  125. }
  126. $response->getBody()->write(jsonE($GLOBALS['api']));
  127. return $response
  128. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  129. ->withStatus($GLOBALS['responseCode']);
  130. });