Monitors.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace Cloudflare\User\LoadBalancers;
  3. use Cloudflare\Api;
  4. use Cloudflare\User;
  5. /**
  6. * CloudFlare API wrapper
  7. *
  8. * CTM Monitors
  9. * Cloud Traffic Manager Monitor
  10. *
  11. * @author James Bell <james@james-bell.co.uk>
  12. *
  13. * @version 1
  14. */
  15. class Monitors extends Api
  16. {
  17. /**
  18. * List monitors
  19. * List configured monitors for a user
  20. */
  21. public function monitors()
  22. {
  23. return $this->get('/user/load_balancers/monitors');
  24. }
  25. /**
  26. * Create a monitor
  27. * Create a configured monitor
  28. *
  29. * @param string $expected_body A case-insensitive substring to match in the body of the probe
  30. * response to declare an origin as up
  31. * @param string $expected_codes The expected HTTP response code or code range for the probe
  32. * @param string|null $method The HTTP method to use for the health check.
  33. * @param int|null $timeout The timeout (in seconds) before marking the health check as failed
  34. * @param string|null $path The endpoint path to health check against.
  35. * @param int|null $interval The interval between each health check. Shorter intervals may improve failover
  36. * time, but will increase load on the origins as we check from multiple locations.
  37. * @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin
  38. * as unhealthy. Retries are attempted immediately.
  39. * @param array|null $header The HTTP request headers to send in the health check. It is recommended you set
  40. * a Host header by default. The User-Agent header cannot be overridden.
  41. * @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are
  42. * 'HTTP' and 'HTTPS'.
  43. * @param string|null $description Object description
  44. */
  45. public function create($expected_body, $expected_codes, $method = null, $timeout = null, $path = null, $interval = null, $retries = null, $header = null, $type = null, $description = null)
  46. {
  47. $data = [
  48. 'expected_body' => $expected_body,
  49. 'expected_codes' => $expected_codes,
  50. 'method' => $method,
  51. 'timeout' => $timeout,
  52. 'path' => $path,
  53. 'interval' => $interval,
  54. 'retries' => $retries,
  55. 'header' => $header,
  56. 'type' => $type,
  57. 'description' => $description,
  58. ];
  59. return $this->post('/user/load_balancers/monitors', $data);
  60. }
  61. /**
  62. * Monitor details
  63. * List a single configured CTM monitor for a user
  64. *
  65. * @param string $identifier
  66. */
  67. public function details($identifier)
  68. {
  69. return $this->get('/user/load_balancers/monitors/'.$identifier);
  70. }
  71. /**
  72. * Modify a monitor
  73. * Modify a configured monitor
  74. *
  75. * @param string $identifier
  76. * @param string $expected_body A case-insensitive substring to match in the body of the probe
  77. * response to declare an origin as up
  78. * @param string $expected_codes The expected HTTP response code or code range for the probe
  79. * @param string|null $method The HTTP method to use for the health check.
  80. * @param int|null $timeout The timeout (in seconds) before marking the health check as failed
  81. * @param string|null $path The endpoint path to health check against.
  82. * @param int|null $interval The interval between each health check. Shorter intervals may improve failover
  83. * time, but will increase load on the origins as we check from multiple locations.
  84. * @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin
  85. * as unhealthy. Retries are attempted immediately.
  86. * @param array|null $header The HTTP request headers to send in the health check. It is recommended you set
  87. * a Host header by default. The User-Agent header cannot be overridden.
  88. * @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are
  89. * 'HTTP' and 'HTTPS'.
  90. * @param string|null $description Object description
  91. */
  92. public function update($identifier, $expected_body, $expected_codes, $method = null, $timeout = null, $path = null, $interval = null, $retries = null, $header = null, $type = null, $description = null)
  93. {
  94. $data = [
  95. 'expected_body' => $expected_body,
  96. 'expected_codes' => $expected_codes,
  97. 'method' => $method,
  98. 'timeout' => $timeout,
  99. 'path' => $path,
  100. 'interval' => $interval,
  101. 'retries' => $retries,
  102. 'header' => $header,
  103. 'type' => $type,
  104. 'description' => $description,
  105. ];
  106. return $this->patch('/user/load_balancers/monitors/'.$identifier, $data);
  107. }
  108. /**
  109. * Delete a monitor
  110. * Delete a configured monitor
  111. *
  112. * @param string $identifier
  113. */
  114. public function delete_monitor($identifier)
  115. {
  116. return $this->delete('/user/load_balancers/monitors/'.$identifier);
  117. }
  118. }