Example #1
0
// GetMapFromInterface returns a map from an interface
func GetMapFromInterface(i interface{}) map[string]interface{} {
	m, ok := i.(map[string]interface{})
	if !ok {
		logger.Debugf("Could not assert to a map the interface: %+v", i)
		return nil
	}

	return m
}
Example #2
0
func (s *Sensu) delete(endpoint string) error {
	apis := shuffle(s.APIs)

	var err error
	for i := 0; i < len(apis); i++ {
		err = apis[i].delete(endpoint)
		if err == nil {
			return err
		}
		logger.Debugf("Delete %s/%s: %v", s.APIs[i].URL, endpoint, err)
	}

	return err
}
Example #3
0
// GetBoolFromInterface ...
func GetBoolFromInterface(i interface{}) (bool, error) {
	if i == nil {
		logger.Debug("The interface is nil")
		return false, errors.New("The interface is nil")
	}

	b, ok := i.(bool)
	if !ok {
		logger.Debugf("Could not assert to a boolean the interface: %+v", i)
		return false, errors.New("Could not assert to a boolean the interface")
	}

	return b, nil
}
Example #4
0
func (s *Sensu) postPayload(endpoint string, payload string) (map[string]interface{}, error) {
	apis := shuffle(s.APIs)

	for i := 0; i < len(apis); i++ {
		logger.Debugf("POST %s/%s", s.APIs[i].URL, endpoint)
		m, err := apis[i].postPayload(endpoint, payload)
		if err == nil {
			return m, err
		}
		logger.Warningf("POST %s/%s returned: %v", s.APIs[i].URL, endpoint, err)
	}

	return nil, errors.New("")
}
Example #5
0
func (s *Sensu) getSlice(endpoint string, limit int) ([]interface{}, error) {
	apis := shuffle(s.APIs)

	for i := 0; i < len(apis); i++ {
		logger.Debugf("GET %s/%s", s.APIs[i].URL, endpoint)
		slice, err := apis[i].getSlice(endpoint, limit)
		if err == nil {
			return slice, err
		}
		logger.Warningf("GET %s/%s returned: %v", s.APIs[i].URL, endpoint, err)
	}

	return nil, errors.New("")
}
Example #6
0
func (s *Sensu) getBytes(endpoint string) ([]byte, *http.Response, error) {
	apis := shuffle(s.APIs)

	for i := 0; i < len(apis); i++ {
		logger.Debugf("GET %s/%s", s.APIs[i].URL, endpoint)
		bytes, res, err := apis[i].getBytes(endpoint)
		if err == nil {
			return bytes, res, err
		}
		logger.Warningf("GET %s/%s returned: %v", s.APIs[i].URL, endpoint, err)
	}

	return nil, nil, errors.New("")
}
Example #7
0
// getEnterpriseMetrics retrieves Sensu Enterprise metrics
func getEnterpriseMetrics(datacenter SensuDatacenter, metrics *structs.SERawMetrics) *structs.SERawMetrics {
	var err error
	m := make(map[string]*structs.SERawMetric)
	metricsEndpoints := []string{"clients", "events", "keepalives_avg_60", "check_requests", "results"}

	for _, metric := range metricsEndpoints {
		m[metric], err = datacenter.Metric(metric)
		if err != nil {
			logger.Debugf("Could not retrieve the %s enterprise metrics. %s", metric, datacenter.GetName())
			m[metric] = &structs.SERawMetric{}
		}
	}

	m["events"].Name = datacenter.GetName()
	metrics.Clients = append(metrics.Clients, m["clients"])
	metrics.Events = append(metrics.Events, m["events"])
	metrics.KeepalivesAVG60 = append(metrics.KeepalivesAVG60, m["keepalives_avg_60"])
	metrics.Requests = append(metrics.Requests, m["check_requests"])
	metrics.Results = append(metrics.Results, m["results"])

	return metrics
}