diff --git a/src/Agent/AgentClient.php b/src/Agent/AgentClient.php index 897424a..fe50972 100644 --- a/src/Agent/AgentClient.php +++ b/src/Agent/AgentClient.php @@ -17,6 +17,8 @@ */ use DCarbone\PHPConsulAPI\AbstractClient; +use DCarbone\PHPConsulAPI\Consul; +use DCarbone\PHPConsulAPI\Error; use DCarbone\PHPConsulAPI\Request; /** @@ -199,7 +201,7 @@ public function serviceDeregister($serviceID) { * @return \DCarbone\PHPConsulAPI\Error|null */ public function passTTL($checkID, $note) { - return $this->updateTTL($checkID, $note, 'passing'); + return $this->updateTTL($checkID, $note, 'pass'); } /** @@ -210,7 +212,7 @@ public function passTTL($checkID, $note) { * @return \DCarbone\PHPConsulAPI\Error|null */ public function warnTTL($checkID, $note) { - return $this->updateTTL($checkID, $note, 'warning'); + return $this->updateTTL($checkID, $note, 'warn'); } /** @@ -221,7 +223,7 @@ public function warnTTL($checkID, $note) { * @return \DCarbone\PHPConsulAPI\Error|null */ public function failTTL($checkID, $note) { - return $this->updateTTL($checkID, $note, 'critical'); + return $this->updateTTL($checkID, $note, 'fail'); } /** @@ -233,6 +235,27 @@ public function failTTL($checkID, $note) { * @return \DCarbone\PHPConsulAPI\Error|null */ public function updateTTL($checkID, $output, $status) { + switch ($status) { + case Consul::HealthPassing: + case Consul::HealthWarning: + case Consul::HealthCritical: + break; + case 'pass': + $status = Consul::HealthPassing; + break; + case 'warn': + $status = Consul::HealthWarning; + break; + case 'fail': + $status = Consul::HealthCritical; + break; + default: + return new Error(sprintf( + '%s is not a valid status. Allowed: ["pass", "warn", "fail"]', + is_string($status) ? $status : gettype($status) + )); + } + $r = new Request('put', sprintf('v1/agent/check/update/%s', $checkID), $this->c, diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index 7f3cdef..3728f76 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -41,6 +41,12 @@ class AgentServiceCheck extends AbstractModel { public $TCP = ''; /** @var string */ public $Status = ''; + /** @var string */ + public $Notes = ''; + /** @var bool */ + public $TLSSkipVerify = false; + /** @var string */ + public $DeregisterCriticalServiceAfter = ''; /** * @return string @@ -185,4 +191,52 @@ public function setStatus($Status) { $this->Status = $Status; return $this; } + + /** + * @return string + */ + public function getNotes() { + return $this->Notes; + } + + /** + * @param string $Notes + * @return \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck + */ + public function setNotes($Notes) { + $this->Notes = $Notes; + return $this; + } + + /** + * @return bool + */ + public function isTLSSkipVerify() { + return $this->TLSSkipVerify; + } + + /** + * @param bool $TLSSkipVerify + * @return \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck + */ + public function setTLSSkipVerify($TLSSkipVerify) { + $this->TLSSkipVerify = $TLSSkipVerify; + return $this; + } + + /** + * @return string + */ + public function getDeregisterCriticalServiceAfter() { + return $this->DeregisterCriticalServiceAfter; + } + + /** + * @param string $DeregisterCriticalServiceAfter + * @return \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck + */ + public function setDeregisterCriticalServiceAfter($DeregisterCriticalServiceAfter) { + $this->DeregisterCriticalServiceAfter = $DeregisterCriticalServiceAfter; + return $this; + } } \ No newline at end of file diff --git a/src/Consul.php b/src/Consul.php index 324c730..8f52025 100644 --- a/src/Consul.php +++ b/src/Consul.php @@ -39,6 +39,12 @@ class Consul { const HTTPSSLEnvName = 'CONSUL_HTTP_SSL'; const HTTPSSLVerifyEnvName = 'CONSUL_HTTP_SSL_VERIFY'; + const HealthAny = 'any'; + const HealthPassing = 'passing'; + const HealthWarning = 'warning'; + const HealthCritical = 'critical'; + const HealthMaint = 'maintenance'; + /** @var \DCarbone\PHPConsulAPI\KV\KVClient */ public $KV; /** @var \DCarbone\PHPConsulAPI\Agent\AgentClient */ diff --git a/src/Error.php b/src/Error.php index e82873c..9db36a0 100644 --- a/src/Error.php +++ b/src/Error.php @@ -24,54 +24,48 @@ */ class Error implements \JsonSerializable { /** @var DateTime */ - private $_timestamp; + private $time; /** @var string */ - private $_message; + private $message; /** * Error constructor. * @param string $message */ public function __construct($message) { - $this->_timestamp = new DateTime(); - $this->_message = $message; + $this->time = new DateTime(); + $this->message = $message; } /** * @return DateTime */ - public function getTimestamp() { - return $this->_timestamp; + public function getTime() { + return $this->time; } /** * @return string */ public function getMessage() { - return $this->_message; + return $this->message; } /** - * Specify data which should be serialized to JSON - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php - * @return mixed data which can be serialized by json_encode, which is a value of any type other than a resource. + * @return array */ public function jsonSerialize() { - return array( - 'message' => $this->_message, - 'timestamp' => $this->_timestamp - ); + return [ + 'message' => $this->message, + 'timestamp' => $this->time + ]; } /** * @return string */ public function __toString() { - return sprintf( - '[error] - %s - %s', - $this->_timestamp, - $this->_message - ); + return $this->message; } } \ No newline at end of file