Compare commits

...

2 Commits

Author SHA1 Message Date
tomsun28
b16307b14b [manager]调整API监控类型参数位置 2022-02-12 16:45:15 +08:00
random-chat
e8729f831d 增加post内容 2022-02-12 15:56:14 +08:00
7 changed files with 86 additions and 6 deletions

View File

@@ -25,10 +25,12 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder; import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.util.StringUtils;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import java.io.IOException; import java.io.IOException;
@@ -296,6 +298,7 @@ public class HttpCollectImpl extends AbstractCollect {
log.error("not support the http method: {}.", httpProtocol.getMethod()); log.error("not support the http method: {}.", httpProtocol.getMethod());
return null; return null;
} }
// params // params
Map<String, String> params = httpProtocol.getParams(); Map<String, String> params = httpProtocol.getParams();
if (params != null && !params.isEmpty()) { if (params != null && !params.isEmpty()) {
@@ -303,6 +306,7 @@ public class HttpCollectImpl extends AbstractCollect {
requestBuilder.addParameter(param.getKey(), param.getValue()); requestBuilder.addParameter(param.getKey(), param.getValue());
} }
} }
// headers // headers
Map<String, String> headers = httpProtocol.getHeaders(); Map<String, String> headers = httpProtocol.getHeaders();
if (headers != null && !headers.isEmpty()) { if (headers != null && !headers.isEmpty()) {
@@ -332,7 +336,11 @@ public class HttpCollectImpl extends AbstractCollect {
String value = DispatchConstants.BEARER + " " + httpProtocol.getAuthorization().getBearerTokenToken(); String value = DispatchConstants.BEARER + " " + httpProtocol.getAuthorization().getBearerTokenToken();
requestBuilder.addHeader(HttpHeaders.AUTHORIZATION, value); requestBuilder.addHeader(HttpHeaders.AUTHORIZATION, value);
} }
// todo 处理请求内容 body 暂不支持body
// 请求内容会覆盖post协议的params
if(StringUtils.hasLength(httpProtocol.getPayload())){
requestBuilder.setEntity(new StringEntity(httpProtocol.getPayload(),"UTF-8"));
}
// uri // uri
if (IpDomainUtil.isHasSchema(httpProtocol.getHost())) { if (IpDomainUtil.isHasSchema(httpProtocol.getHost())) {

View File

@@ -45,6 +45,11 @@ public class HttpProtocol {
* http请求携带查询参数 eg: localhost:80/api?paramKey=value * http请求携带查询参数 eg: localhost:80/api?paramKey=value
*/ */
private Map<String, String> params; private Map<String, String> params;
/**
* http请求携带的请求体
*/
private String payload;
/** /**
* 认证信息 * 认证信息
*/ */

View File

@@ -169,6 +169,7 @@ public class MonitorServiceImpl implements MonitorService {
} }
param.setType(CommonConstants.PARAM_TYPE_NUMBER); param.setType(CommonConstants.PARAM_TYPE_NUMBER);
break; break;
case "textarea":
case "text": case "text":
Short limit = paramDefine.getLimit(); Short limit = paramDefine.getLimit();
if (limit != null) { if (limit != null) {

View File

@@ -20,6 +20,10 @@ configmap:
type: 1 type: 1
- key: password - key: password
type: 2 type: 2
- key: contentType
type: 1
- key: payload
type: 1
# 指标组列表 # 指标组列表
metrics: metrics:
# 第一个监控指标组 cpu # 第一个监控指标组 cpu
@@ -48,6 +52,10 @@ metrics:
method: ^_^method^_^ method: ^_^method^_^
# 是否启用ssl/tls,即是http还是https,默认false # 是否启用ssl/tls,即是http还是https,默认false
ssl: ^_^ssl^_^ ssl: ^_^ssl^_^
payload: ^_^payload^_^
# 请求头内容
headers:
content-type: ^_^contentType^_^
# 认证 # 认证
authorization: authorization:
# 认证方式: Basic Auth, Digest Auth, Bearer Token # 认证方式: Basic Auth, Digest Auth, Bearer Token

View File

@@ -16,6 +16,7 @@ param:
# 当type为number时,用range表示范围 # 当type为number时,用range表示范围
range: '[0,65535]' range: '[0,65535]'
required: true required: true
defaultValue: 80
- field: uri - field: uri
name: 相对路径 name: 相对路径
type: text type: text
@@ -37,6 +38,11 @@ param:
value: PUT value: PUT
- label: DELETE请求 - label: DELETE请求
value: DELETE value: DELETE
- field: ssl
name: 启用HTTPS
# 当type为boolean时,前端用switch展示开关
type: boolean
required: true
- field: username - field: username
name: 用户名 name: 用户名
type: text type: text
@@ -47,8 +53,13 @@ param:
name: 密码 name: 密码
type: password type: password
required: false required: false
- field: ssl - field: contentType
name: 启用HTTPS name: Content-Type
# 当type为boolean时,前端用switch展示开关 type: text
type: boolean placeholder: '请求BODY资源类型'
required: true required: false
- field: payload
name: 请求BODY
type: textarea
placeholder: 'POST PUT请求时有效'
required: false

View File

@@ -63,6 +63,30 @@
/> />
</nz-form-control> </nz-form-control>
<nz-form-label
*ngIf="paramDefine.type === 'textarea'"
nzSpan="7"
[nzRequired]="paramDefine.required"
[nzFor]="paramDefine.field"
>{{ paramDefine.name }}
</nz-form-label>
<nz-form-control
*ngIf="paramDefine.type === 'textarea'"
nzSpan="8"
[nzErrorTip]="'validation.required' | i18n"
>
<textarea
nz-input
[(ngModel)]="params[i].value"
[required]="paramDefine.required"
[name]="paramDefine.field"
[id]="paramDefine.field"
[placeholder]="paramDefine.placeholder ? paramDefine.placeholder : ''"
rows="3"
></textarea>
</nz-form-control>
<nz-form-label *ngIf="paramDefine.type === 'password'" nzSpan="7" [nzRequired]="paramDefine.required" [nzFor]="paramDefine.field" <nz-form-label *ngIf="paramDefine.type === 'password'" nzSpan="7" [nzRequired]="paramDefine.required" [nzFor]="paramDefine.field"
>{{ paramDefine.name }} >{{ paramDefine.name }}
</nz-form-label> </nz-form-label>

View File

@@ -72,6 +72,29 @@
/> />
</nz-form-control> </nz-form-control>
<nz-form-label
*ngIf="paramDefine.type === 'textarea'"
nzSpan="7"
[nzRequired]="paramDefine.required"
[nzFor]="paramDefine.field"
>{{ paramDefine.name }}
</nz-form-label>
<nz-form-control
*ngIf="paramDefine.type === 'textarea'"
nzSpan="8"
[nzErrorTip]="'validation.required' | i18n"
>
<textarea
nz-input
[(ngModel)]="params[i].value"
[required]="paramDefine.required"
[name]="paramDefine.field"
[id]="paramDefine.field"
[placeholder]="paramDefine.placeholder ? paramDefine.placeholder : ''"
rows="3"
></textarea>
</nz-form-control>
<nz-form-label *ngIf="paramDefine.type === 'password'" nzSpan="7" [nzRequired]="paramDefine.required" [nzFor]="paramDefine.field" <nz-form-label *ngIf="paramDefine.type === 'password'" nzSpan="7" [nzRequired]="paramDefine.required" [nzFor]="paramDefine.field"
>{{ paramDefine.name }} >{{ paramDefine.name }}
</nz-form-label> </nz-form-label>