예제 #1
0
파일: data.go 프로젝트: CoScale/coscale-cli
			cmd.Flag.StringVar(&data, "data", DEFAULT_STRING_FLAG_VALUE, "")
			cmd.ParseArgs(args)

			if datapoint == DEFAULT_STRING_FLAG_VALUE && data == DEFAULT_STRING_FLAG_VALUE {
				cmd.PrintUsage()
				os.Exit(EXIT_FLAG_ERROR)
			}

			timeInSecAgo := false
			if data == DEFAULT_STRING_FLAG_VALUE {
				timeInSecAgo = true
				data = datapoint
			}

			// ParseDataPoint coult return data for multiple calls for same metricIDs with different subjectID
			callsData, err := api.ParseDataPoint(data, timeInSecAgo)
			if err != nil {
				cmd.PrintResult("", err)
			}
			var result string
			var resErr error
			// if datapoint contain multiple subject id, then we will have multiple api calls
			for _, callData := range callsData {
				result, resErr = cmd.Capi.InsertData(callData)
				if resErr != nil {
					break
				}
			}
			cmd.PrintResult(result, resErr)
		},
	},
예제 #2
0
파일: data.go 프로젝트: vdloo/coscale-cli
	},
	{
		Name:      "insert",
		UsageLine: `data insert (--datapoint)`,
		Long: `
Create new EventData for a given event.

The flags for data event action are:
Mandatory:
	--datapoint
		Data format is:"M<metric id>:<subject Id>:<seconds ago>:<value/s>" eg:"M1:S100:120:1,2"
`,
		Run: func(cmd *Command, args []string) {
			var datapoint string
			cmd.Flag.Usage = func() { cmd.PrintUsage() }
			cmd.Flag.StringVar(&datapoint, "datapoint", DEFAULT_FLAG_VALUE, "")
			cmd.ParseArgs(args)
			if datapoint == DEFAULT_FLAG_VALUE {
				cmd.PrintUsage()
				os.Exit(EXIT_FLAG_ERROR)
			}
			data, err := api.ParseDataPoint(datapoint)
			if err != nil {
				cmd.PrintUsage()
				os.Exit(EXIT_FLAG_ERROR)
			}
			cmd.PrintResult(cmd.Capi.InsertData(data))
		},
	},
}