// create the initial request to be sent to foremast
create the initial request to be sent to foremast
// create the initial request to be sent to foremast
func ForemastQuery(jobmap *map[string]JobInfoM, appName string, metricmap map[string]string) bool {
	now := time.Now()
	unix := now.Unix()
	startTime := unix - (60 * 5)
	endTime := startTime + (60 * 30)
	analyzingRequest := ApplicationHealthAnalyzeRequest{}
	analyzingRequest.AppName = appName
	analyzingRequest.Strategy = "rollover"
	analyzingRequest.StartTime = now.Format("2006-01-02T15:04:05Z07:00")
	analyzingRequest.EndTime = now.Add(time.Minute * 5).Format("2006-01-02T15:04:05Z07:00") 
	metricsinfo := MetricsInfo{
		Current:    map[string]MetricQuery{},
		Historical: map[string]MetricQuery{},
		Baseline:   map[string]MetricQuery{},
	}
	for name, query := range metricmap {
		mq := MetricQuery{
			DataSourceType: "wavefront",
			Parameters: map[string](interface{}){
				"query":    query,
				"endpoint": "",
				"start":    startTime * 1000,
				"end":      endTime * 1000,
				"step":     60,
			},
		}
		metricsinfo.Current[name] = mq
		mh := MetricQuery{
			DataSourceType: "wavefront",
			Parameters: map[string](interface{}){
				"query":    query,
				"endpoint": "",
				"start":    (startTime - (7 * 24 * 60 * 60)) * 1000,
				"end":      startTime,
				"step":     60,
			},
		}
		metricsinfo.Historical[name] = mh
		metricsinfo.Baseline[name] = mh
	}
	analyzingRequest.Metrics = metricsinfo
	b, err := json.MarshalIndent(analyzingRequest, "", "  ")
	if err != nil {
		fmt.Printf("[%s] error: %s\n", analyzingRequest.AppName, err)
	}
	_ = b
	resp, err := StartAnalyzing(analyzingRequest)
	if err == nil {
		log.Printf("[%s] startanalyzing resp %#v\n", appName, resp)
		(*jobmap)[analyzingRequest.AppName] = JobInfoM{
			MetricMap: metricmap,
			JobID:     resp,
			Request:   analyzingRequest,
		}
		return true
	} else {
		log.Printf("[%s] startanalyzing err %#v\n%#v\n", appName, err, err.Error())
		return false
	}
}
func ForemastQuery ( jobmap * map [ string ] JobInfoM , appName string , metricmap map [ string ] string ) bool { now := time . Now ( ) unix := now . Unix ( ) startTime := unix - ( 60 * 5 ) endTime := startTime + ( 60 * 30 ) analyzingRequest := ApplicationHealthAnalyzeRequest { } analyzingRequest . AppName = appName analyzingRequest . Strategy = " " analyzingRequest . StartTime = now . Format ( " " ) analyzingRequest . EndTime = now . Add ( time . Minute * 5 ) . Format ( " " ) metricsinfo := MetricsInfo { Current : map [ string ] MetricQuery { } , Historical : map [ string ] MetricQuery { } , Baseline : map [ string ] MetricQuery { } , } for name , query := range metricmap { mq := MetricQuery { DataSourceType : " " , Parameters : map [ string ] ( interface { } ) { " " : query , " " : " " , " " : startTime * 1000 , " " : endTime * 1000 , " " : 60 , } , } metricsinfo . Current [ name ] = mq mh := MetricQuery { DataSourceType : " " , Parameters : map [ string ] ( interface { } ) { " " : query , " " : " " , " " : ( startTime - ( 7 * 24 * 60 * 60 ) ) * 1000 , " " : startTime , " " : 60 , } , } metricsinfo . Historical [ name ] = mh metricsinfo . Baseline [ name ] = mh } analyzingRequest . Metrics = metricsinfo b , err := json . MarshalIndent ( analyzingRequest , " " , " " ) if err != nil { fmt . Printf ( " \n " , analyzingRequest . AppName , err ) } _ = b resp , err := StartAnalyzing ( analyzingRequest ) if err == nil { log . Printf ( " \n " , appName , resp ) ( * jobmap ) [ analyzingRequest . AppName ] = JobInfoM { MetricMap : metricmap , JobID : resp , Request : analyzingRequest , } return true } else { log . Printf ( " \n \n " , appName , err , err . Error ( ) ) return false } }
create the initial request to be sent to foremast
create the initial request to be sent to foremast
// fmt.Printf("%s, %s", analyzingRequest.AppName, appName) //"2018-11-03T16:33:04-07:00"