protected function doCheck(CheckEvent $event) { if (empty($event->sensorInstance->objectModel)) { $event->state = static::STATE_CHECK_FAIL; return; } $objectModel = $event->sensorInstance->objectModel; $url = $objectModel->dataObject->object->getTestUrl(); if (!$url || !class_exists('linslin\\yii2\\curl\\Curl')) { $event->state = static::STATE_UNCHECKED; return; } $redirects = 10; $result = $this->testUrl($url, $redirects); $response = $result['response']; $responseCode = $result['responseCode']; if (!$response || $responseCode !== 200) { $event->state = static::STATE_ERROR; $event->verifyState = true; $event->addError("The url '{$url}' returned a response code of {$responseCode}"); } else { $lookFor = $objectModel->dataObject->object->getTestLookFor(); if (!$lookFor || strpos($response, $lookFor) !== false) { $event->state = static::STATE_NORMAL; } else { $event->verifyState = true; $event->state = static::STATE_ERROR; $event->addError("The url '{$url}' did not contain the look for text"); } } }
protected function doCheck(CheckEvent $event) { if ($this->payload === null) { $event->addError('Local sensor did not provide any information'); $event->state = static::STATE_UNCHECKED; } elseif ($this->payload === false) { $event->addError('Local sensor encountered an unknown error when determining its value'); $event->state = static::STATE_CHECK_FAIL; } else { $payload = $this->payload; if (!empty($payload['error'])) { $this->addError($payload['error']); $event->state = static::STATE_CHECK_FAIL; } elseif (isset($payload['state']) && in_array($payload['state'], [static::STATE_ERROR, static::STATE_LOW, static::STATE_NORMAL, static::STATE_HIGH, static::STATE_UNCHECKED])) { $event->state = $payload['state']; $event->dataValue = $this->getDataValue(); } else { $event->addError('Local sensor was expected to provide state information but did not.'); $event->state = static::STATE_ERROR; } } }