예제 #1
0
func handleNotificationTestCommand(cmd *NotificationTestCommand) error {
	notifier := NewRootNotifier()

	model := &m.AlertNotification{
		Name:     cmd.Name,
		Type:     cmd.Type,
		Settings: cmd.Settings,
	}

	notifiers, err := notifier.createNotifierFor(model)

	if err != nil {
		log.Error2("Failed to create notifier", "error", err.Error())
		return err
	}

	return notifier.sendNotifications(createTestEvalContext(), []Notifier{notifiers})
}
예제 #2
0
파일: types.go 프로젝트: mapr/grafana
func (q *Query) Build(availableSeries []string) ([]QueryToSend, error) {
	var queriesToSend []QueryToSend
	where := q.buildWhereClause()
	functions := q.buildFunctionList()

	for _, metric := range q.Metrics {
		alias := ""
		if metric.Alias != "" {
			alias = fmt.Sprintf(" {%s}", metric.Alias)
		}

		if !containsWildcardPattern.Match([]byte(metric.Metric)) {
			rawQuery := q.renderQuerystring(metric.Metric, functions, alias, where, q.TimeRange)
			queriesToSend = append(queriesToSend, QueryToSend{
				RawQuery: rawQuery,
				QueryRef: q,
			})
		} else {
			m := strings.Replace(metric.Metric, "*", ".*", -1)
			mp, err := regexp.Compile(m)

			if err != nil {
				log.Error2("failed to compile regex for ", "metric", m)
				continue
			}

			//TODO: this lookup should be cached
			for _, wildcardMatch := range availableSeries {
				if mp.Match([]byte(wildcardMatch)) {
					rawQuery := q.renderQuerystring(wildcardMatch, functions, alias, where, q.TimeRange)
					queriesToSend = append(queriesToSend, QueryToSend{
						RawQuery: rawQuery,
						QueryRef: q,
					})
				}
			}
		}
	}

	return queriesToSend, nil
}