backend: handle response on the fronted
This commit is contained in:
@@ -90,7 +90,23 @@ func (ds *ZabbixDatasource) ZabbixAPIQuery(ctx context.Context, tsdbReq *datasou
|
||||
resultByte, err := result.MarshalJSON()
|
||||
ds.logger.Debug("ZabbixAPIQuery", "result", string(resultByte))
|
||||
|
||||
return nil, errors.New("ZabbixAPIQuery is not implemented yet")
|
||||
return ds.BuildResponse(result)
|
||||
}
|
||||
|
||||
func (ds *ZabbixDatasource) BuildResponse(result *simplejson.Json) (*datasource.DatasourceResponse, error) {
|
||||
resultByte, err := result.MarshalJSON()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &datasource.DatasourceResponse{
|
||||
Results: []*datasource.QueryResult{
|
||||
&datasource.QueryResult{
|
||||
RefId: "zabbixAPI",
|
||||
MetaJson: string(resultByte),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (ds *ZabbixDatasource) ZabbixRequest(ctx context.Context, dsInfo *datasource.DatasourceInfo, method string, params *simplejson.Json) (*simplejson.Json, error) {
|
||||
|
||||
@@ -40,7 +40,10 @@ export class ZabbixAPIConnector {
|
||||
//////////////////////////
|
||||
|
||||
request(method, params) {
|
||||
this.tsdbRequest(method, params);
|
||||
this.tsdbRequest(method, params).then(response => {
|
||||
const result = this.handleTsdbResponse(response);
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
return this.zabbixAPICore.request(this.url, method, params, this.requestOptions, this.auth)
|
||||
.catch(error => {
|
||||
@@ -79,6 +82,14 @@ export class ZabbixAPIConnector {
|
||||
});
|
||||
}
|
||||
|
||||
handleTsdbResponse(response) {
|
||||
if (!response || !response.data || !response.data.results) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return response.data.results['zabbixAPI'].meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* When API unauthenticated or auth token expired each request produce login()
|
||||
* call. But auth token is common to all requests. This function wraps login() method
|
||||
|
||||
Reference in New Issue
Block a user