Merge pull request 'fixed error of getting detail info of alert history' (#20) from fixed_alert into master
This commit is contained in:
commit
c40b665ac8
|
@ -24,24 +24,29 @@ func (h *AlertAPI) getAlert(w http.ResponseWriter, req *http.Request, ps httprou
|
||||||
obj := alerting.Alert{}
|
obj := alerting.Alert{}
|
||||||
obj.ID = id
|
obj.ID = id
|
||||||
|
|
||||||
exists, err := orm.Get(&obj)
|
q := orm.Query{
|
||||||
if !exists || err != nil {
|
WildcardIndex: true,
|
||||||
|
Size: 1,
|
||||||
|
}
|
||||||
|
q.Conds = orm.And(orm.Eq("id", id))
|
||||||
|
err, result := orm.Search(obj, &q)
|
||||||
|
if err != nil {
|
||||||
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(result.Result) == 0 {
|
||||||
h.WriteJSON(w, util.MapStr{
|
h.WriteJSON(w, util.MapStr{
|
||||||
"_id": id,
|
"_id": id,
|
||||||
"found": false,
|
"found": false,
|
||||||
}, http.StatusNotFound)
|
}, http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
log.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
h.WriteJSON(w, util.MapStr{
|
h.WriteJSON(w, util.MapStr{
|
||||||
"found": true,
|
"found": true,
|
||||||
"_id": id,
|
"_id": id,
|
||||||
"_source": obj,
|
"_source": result.Result[0],
|
||||||
}, 200)
|
}, 200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue