本文整理汇总了Golang中github.com/skyrings/skyring-common/models.AppEvent.UserAckComment方法的典型用法代码示例。如果您正苦于以下问题:Golang AppEvent.UserAckComment方法的具体用法?Golang AppEvent.UserAckComment怎么用?Golang AppEvent.UserAckComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skyrings/skyring-common/models.AppEvent
的用法示例。
在下文中一共展示了AppEvent.UserAckComment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PatchEvent
func PatchEvent(w http.ResponseWriter, r *http.Request) {
ctxt, err := GetContext(r)
if err != nil {
logger.Get().Error("Error Getting the context. error: %v", err)
}
var m map[string]interface{}
vars := mux.Vars(r)
event_id_str := vars["event-id"]
event_id, err := uuid.Parse(event_id_str)
if err != nil {
logger.Get().Error("%s-Error parsing event id: %s", ctxt, event_id_str)
HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing event id: %s", event_id_str))
return
}
body, err := ioutil.ReadAll(r.Body)
if err != nil {
logger.Get().Error("%s-Error parsing http request body:%s", ctxt, err)
HandleHttpError(w, err)
return
}
if err = json.Unmarshal(body, &m); err != nil {
logger.Get().Error("%s-Unable to Unmarshall the data:%s", ctxt, err)
HandleHttpError(w, err)
return
}
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_APP_EVENTS)
var event models.AppEvent
if err := collection.Find(bson.M{"eventid": *event_id}).One(&event); err == mgo.ErrNotFound {
HttpResponse(w, http.StatusBadRequest, "Event not found")
logger.Get().Error("%s-Event: %v not found. error: %v", ctxt, *event_id, err)
return
} else if err != nil {
logger.Get().Error("%s-Error getting the event detail for %v. error: %v", ctxt, *event_id, err)
HttpResponse(w, http.StatusBadRequest, "Event finding the record")
return
}
if event.Severity == models.ALARM_STATUS_CLEARED {
logger.Get().Error("%s-Cannot ack an event with severity: %s", ctxt, event.Severity.String())
HttpResponse(w, http.StatusBadRequest, "Event with this severity cannot be acked. ")
return
}
if event.Acked {
logger.Get().Error("%s-Cannot ack this event as its already acked", ctxt)
HttpResponse(w, http.StatusBadRequest, "Event Cannot be acked as its already acked.")
return
}
if val, ok := m["acked"]; ok {
event.Acked = val.(bool)
} else {
logger.Get().Error("%s-Insufficient details for patching event: %v", ctxt, *event_id)
HandleHttpError(w, errors.New("insufficient detail for patching event"))
return
}
if val, ok := m["ackcomment"]; ok {
event.UserAckComment = val.(string)
}
event.AckedByUser = strings.Split(ctxt, ":")[0]
event.UserAckedTime = time.Now()
err = collection.Update(bson.M{"eventid": *event_id}, bson.M{"$set": event})
if err != nil {
logger.Get().Error(fmt.Sprintf("%s-Error updating record in DB for event: %v. error: %v", ctxt, event_id_str, err))
HttpResponse(w, http.StatusInternalServerError, err.Error())
}
clearedSeverity := event.Severity
event.Severity = models.ALARM_STATUS_CLEARED
common_event.UpdateAlarmCount(event, clearedSeverity, ctxt)
return
}