// QueryWavefrontAnomalyCount - run query for servicename at unix time to get anomaly count from WAVEFRONT
// returns value of anomaly count
run query for servicename at unix time to get anomaly count from WAVEFRONT
returns value of anomaly count
// QueryWavefrontAnomalyCount - run query for servicename at unix time to get anomaly count from WAVEFRONT // returns value of anomaly count
func QueryWavefrontAnomalyCount(serviceName string, query string, metricName string, unixtime int64, currentYear *int, currentMonth *time.Month, currentDay *int) float64 {
	client := &http.Client{}
	var Url *url.URL
	Url, err := url.Parse(os.Getenv("WAVEFRONT_ENDPOINT"))
	if err != nil {
		panic("boom")
	}
	Url.Path += "api/v2/chart/api"
	parameters := url.Values{}
	newQuery := strings.Replace(query, "APPNAME", serviceName, -1)
	parameters.Add("q", strings.Replace(newQuery, "REPLACE_METRIC", metricName, -1))
	parameters.Add("s", strconv.FormatInt((unixtime)*1000, 10)) 
	parameters.Add("g", "d")                                    
	parameters.Add("sorted", "false")
	parameters.Add("cached", "true")
	Url.RawQuery = parameters.Encode()
	log.Printf("[%s] sending request for anomaly count...\n%s", serviceName, Url.String())
	req, err := http.NewRequest("GET", Url.String(), nil)
	if err != nil {
		log.Printf("[%s] error submitting request for anomaly report: %s\n%s\n", serviceName, err, err.Error())
	}
	req.Header.Add("Authorization", "Bearer "+os.Getenv("WAVEFRONT_TOKEN"))
	req.Header.Add("Accept", "application/json")
	resp, err := client.Do(req)
	if err != nil {
		log.Printf("[%s] error receiving response for anomaly report: %s\n%s\n", serviceName, err, err.Error())
	}
	bodyBytes, _ := ioutil.ReadAll(resp.Body)
	var responsebody map[string]interface{}
	err = json.Unmarshal(bodyBytes, &responsebody)
	bodyString := string(bodyBytes)
	_ = bodyString
	log.Printf("%#v\n", bodyString)
	if responsebody["warnings"] != nil {
		return -1
	}
	timeseries := responsebody["timeseries"].([]interface{})
	if len(timeseries) < 1 {
		return 0
	}
	timeseriesdata := responsebody["timeseries"].([]interface{})[0].(map[string]interface{})["data"].([]interface{})[0].([]interface{})[1].(float64)
	return timeseriesdata
}
func QueryWavefrontAnomalyCount ( serviceName string , query string , metricName string , unixtime int64 , currentYear * int , currentMonth * time . Month , currentDay * int ) float64 { client := & http . Client { } var Url * url . URL Url , err := url . Parse ( os . Getenv ( " " ) ) if err != nil { panic ( " " ) } Url . Path += " " parameters := url . Values { } newQuery := strings . Replace ( query , " " , serviceName , - 1 ) parameters . Add ( " " , strings . Replace ( newQuery , " " , metricName , - 1 ) ) parameters . Add ( " " , strconv . FormatInt ( ( unixtime ) * 1000 , 10 ) ) parameters . Add ( " " , " " ) parameters . Add ( " " , " " ) parameters . Add ( " " , " " ) Url . RawQuery = parameters . Encode ( ) log . Printf ( " \n " , serviceName , Url . String ( ) ) req , err := http . NewRequest ( " " , Url . String ( ) , nil ) if err != nil { log . Printf ( " \n \n " , serviceName , err , err . Error ( ) ) } req . Header . Add ( " " , " " + os . Getenv ( " " ) ) req . Header . Add ( " " , " " ) resp , err := client . Do ( req ) if err != nil { log . Printf ( " \n \n " , serviceName , err , err . Error ( ) ) } bodyBytes , _ := ioutil . ReadAll ( resp . Body ) var responsebody map [ string ] interface { } err = json . Unmarshal ( bodyBytes , & responsebody ) bodyString := string ( bodyBytes ) _ = bodyString log . Printf ( " \n " , bodyString ) if responsebody [ " " ] != nil { return - 1 } timeseries := responsebody [ " " ] . ( [ ] interface { } ) if len ( timeseries ) < 1 { return 0 } timeseriesdata := responsebody [ " " ] . ( [ ] interface { } ) [ 0 ] . ( map [ string ] interface { } ) [ " " ] . ( [ ] interface { } ) [ 0 ] . ( [ ] interface { } ) [ 1 ] . ( float64 ) return timeseriesdata }
run query for servicename at unix time to get anomaly count from WAVEFRONT
returns value of anomaly count
run query for servicename at unix time to get anomaly count from WAVEFRONT returns value of anomaly count
// time in milliseconds // get data for past day // log.Printf("%#v\n", resp) // no metrics found // could mean either no anomalies ever for this metric, or that there was a typo somewhere // log.Printf("%#v\n", timeseriesdata)