浏览代码

add toggle for 401 and 403 bypass for healthchecks plugin

CauseFX 4 年之前
父节点
当前提交
ffab588042
共有 2 个文件被更改,包括 26 次插入2 次删除
  1. 3 1
      api/plugins/healthChecks/config.php
  2. 23 1
      api/plugins/healthChecks/plugin.php

+ 3 - 1
api/plugins/healthChecks/config.php

@@ -1,8 +1,10 @@
 <?php
 return array(
 	'HEALTHCHECKS-enabled' => false,
+	'HEALTHCHECKS-401-enabled' => false,
+	'HEALTHCHECKS-403-enabled' => false,
 	'HEALTHCHECKS-Auth-include' => '1',
 	'HEALTHCHECKS-option2-include' => '',
 	'HEALTHCHECKS-all-items' => '',
 	'HEALTHCHECKS-PingURL' => 'https://hc-ping.com/'
-);
+);

+ 23 - 1
api/plugins/healthChecks/plugin.php

@@ -67,6 +67,18 @@ class HealthChecks extends Organizr
 					'help' => 'URL for HealthChecks Ping',
 					'placeholder' => 'HealthChecks Ping URL'
 				),
+				array(
+					'type' => 'switch',
+					'name' => 'HEALTHCHECKS-401-enabled',
+					'label' => '401 Error as Success',
+					'value' => $this->config['HEALTHCHECKS-401-enabled']
+				),
+				array(
+					'type' => 'switch',
+					'name' => 'HEALTHCHECKS-403-enabled',
+					'label' => '403 Error as Success',
+					'value' => $this->config['HEALTHCHECKS-403-enabled']
+				),
 			),
 			'Connection' => array(
 				array(
@@ -123,7 +135,7 @@ class HealthChecks extends Organizr
 	public function _healthCheckPluginTest($url)
 	{
 		$success = false;
-		$options = array('verify' => false, 'verifyname' => false, 'follow_redirects' => true, 'redirects' => 10);
+		$options = array('verify' => false, 'verifyname' => false, 'follow_redirects' => true, 'redirects' => 10, 'timeout' => 60);
 		$headers = array('Token' => $this->config['organizrAPI']);
 		$url = $this->qualifyURL($url);
 		try {
@@ -134,6 +146,16 @@ class HealthChecks extends Organizr
 			if ($response->status_code == 200) {
 				$success = true;
 			}
+			if ($this->config['HEALTHCHECKS-401-enabled']) {
+				if ($response->status_code == 401) {
+					$success = true;
+				}
+			}
+			if ($this->config['HEALTHCHECKS-403-enabled']) {
+				if ($response->status_code == 403) {
+					$success = true;
+				}
+			}
 		} catch (Requests_Exception $e) {
 			$this->writeLog('error', 'HealthChecks Plugin - Error: ' . $e->getMessage(), 'SYSTEM');
 			return false;