Пример #1
0
func QDataGet(c *gin.Context) []*cmodel.GraphQueryResponse {
	log := logger.Logger()
	startTmp := c.DefaultQuery("startTs", string(time.Now().Unix()-(86400)))
	startTmp2, _ := strconv.Atoi(startTmp)
	startTs := int64(startTmp2)
	endTmp := c.DefaultQuery("endTs", string(time.Now().Unix()))
	endTmp2, _ := strconv.Atoi(endTmp)
	endTs := int64(endTmp2)
	consolFun := c.DefaultQuery("consolFun", "AVERAGE")
	stepTmp := c.DefaultQuery("step", "60")
	step, _ := strconv.Atoi(stepTmp)
	counter := c.DefaultQuery("counter", "cpu.idle")
	endpoints := model.EndpointQuery()
	var result []*cmodel.GraphQueryResponse
	for _, enp := range endpoints {
		q := cmodel.GraphQueryParam{
			Start:     startTs,
			End:       endTs,
			ConsolFun: consolFun,
			Step:      step,
			Endpoint:  enp,
			Counter:   counter,
		}
		res, _ := graph.QueryOne(q)
		log.Debug(fmt.Sprintf("%v, %v, %v", res.Counter, res.Endpoint, len(res.Values)))
		result = append(result, res)
	}
	log.Debug(fmt.Sprintf("%s: %d", "openfaclon query got", len(result)))
	return result
}
Пример #2
0
func queryAlerts(templateIDs string, result map[string]interface{}) []interface{} {
	mylog := logger.Logger()
	alerts := []interface{}{}
	if templateIDs == "" {
		return alerts
	}
	notes := getNotes(result)
	o := orm.NewOrm()
	var rows []orm.Params
	sqlcmd := "SELECT id, endpoint, metric, note, priority, status, timestamp, template_id, tpl_creator, process_status "
	sqlcmd += "FROM falcon_portal.event_cases "
	if templateIDs != "*" {
		sqlcmd += "WHERE template_id IN ("
		sqlcmd += templateIDs + ") "
	}
	sqlcmd += "ORDER BY timestamp DESC LIMIT 600"
	num, err := o.Raw(sqlcmd).Values(&rows)
	if err != nil {
		setError(err.Error(), result)
	} else if num > 0 {
		for _, row := range rows {
			hash := row["id"].(string)
			hostname := row["endpoint"].(string)
			metric := row["metric"].(string)
			metricType := strings.Split(metric, ".")[0]
			content := row["note"].(string)
			priority := row["priority"].(string)
			statusRaw := row["status"].(string)
			time := row["timestamp"].(string)
			time = time[:len(time)-3]
			process := getProcess(getStatus(statusRaw))
			note := []map[string]string{}
			if _, ok := notes[hash]; ok {
				note = notes[hash].([]map[string]string)
				process = row["process_status"].(string)
				mylog.Debug(fmt.Sprintf("process: %v", process))
				process = strings.Replace(process, process[:1], strings.ToUpper(process[:1]), 1)
			}
			templateID := row["template_id"].(string)
			author := row["tpl_creator"].(string)
			alert := map[string]interface{}{
				"hash":       hash,
				"hostname":   hostname,
				"metric":     metric,
				"author":     author,
				"templateID": templateID,
				"priority":   priority,
				"severity":   getSeverity(priority),
				"status":     getStatus(statusRaw),
				"statusRaw":  statusRaw,
				"type":       metricType,
				"content":    content,
				"time":       time,
				"duration":   getDuration(time, result),
				"note":       note,
				"process":    process,
			}
			alerts = append(alerts, alert)
		}
	}
	return alerts
}