add mission details, allow specification of float/int from sqf
This commit is contained in:
112
arma.go
112
arma.go
@@ -29,7 +29,7 @@ func runExtensionCallback(name *C.char, function *C.char, data *C.char) C.int {
|
||||
|
||||
//export goRVExtensionVersion
|
||||
func goRVExtensionVersion(output *C.char, outputsize C.size_t) {
|
||||
result := C.CString("Version 1.2.3")
|
||||
result := C.CString("Version 1.0")
|
||||
defer C.free(unsafe.Pointer(result))
|
||||
var size = C.strlen(result) + 1
|
||||
if size > outputsize {
|
||||
@@ -73,28 +73,56 @@ func callBackExample() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func sendToInflux(data string) {
|
||||
|
||||
fields := strings.Split(data, ",")
|
||||
a3Data := strings.Split(data, ",")
|
||||
|
||||
host := fields[0]
|
||||
token := fields[1]
|
||||
org := fields[2]
|
||||
bucket := fields[3]
|
||||
profile := fields[4]
|
||||
locality := fields[5]
|
||||
metric := fields[6]
|
||||
value := fields[7]
|
||||
host := a3Data[0]
|
||||
token := a3Data[1]
|
||||
org := a3Data[2]
|
||||
bucket := a3Data[3]
|
||||
profile, locality := a3Data[4], a3Data[5]
|
||||
missionName, worldName, serverName := a3Data[6], a3Data[7], a3Data[8]
|
||||
metric := a3Data[9]
|
||||
valueType := a3Data[10]
|
||||
|
||||
int_value, err := strconv.Atoi(value)
|
||||
tags := map[string]string{
|
||||
"profile": profile,
|
||||
"locality": locality,
|
||||
"worldName": worldName,
|
||||
"serverName": serverName,
|
||||
}
|
||||
fields := map[string]interface{}{
|
||||
"missionName": missionName,
|
||||
// "count": value,
|
||||
}
|
||||
|
||||
var err error
|
||||
// allow for float or int values
|
||||
if valueType == "float" {
|
||||
fields["count"], err = strconv.ParseFloat(a3Data[11], 64)
|
||||
} else if valueType == "int" {
|
||||
fields["count"], err = strconv.Atoi(a3Data[11])
|
||||
}
|
||||
|
||||
if (valueType != "float") && (valueType != "int") {
|
||||
log.Println("valueType must be either 'float' or 'int'", metric, valueType, a3Data[11])
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
// int_value, err := strconv.Atoi(value)
|
||||
client := influxdb2.NewClient(host, token)
|
||||
writeAPI := client.WriteAPI(org, bucket)
|
||||
|
||||
p := influxdb2.NewPoint(metric,
|
||||
map[string]string{"profile": profile, "locality": locality},
|
||||
map[string]interface{}{"count": int_value},
|
||||
time.Now())
|
||||
p := influxdb2.NewPoint(
|
||||
metric,
|
||||
tags,
|
||||
fields,
|
||||
time.Now(),
|
||||
)
|
||||
|
||||
// write point asynchronously
|
||||
writeAPI.WritePoint(p)
|
||||
@@ -115,56 +143,6 @@ func sendToInflux(data string) {
|
||||
//logger.Println(err)
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
func sendToInflux(data string) {
|
||||
|
||||
fields := strings.Split(data, ",")
|
||||
|
||||
host := fields[0]
|
||||
token := fields[1]
|
||||
org := fields[2]
|
||||
bucket := fields[3]
|
||||
profile := fields[4]
|
||||
locality := fields[5]
|
||||
metric := fields[6]
|
||||
value := fields[7]
|
||||
|
||||
|
||||
client := influxdb2.NewClient(host, token)
|
||||
writeAPI := client.WriteAPI(org, bucket)
|
||||
int_value, err := strconv.Atoi(value)
|
||||
|
||||
|
||||
|
||||
p := influxdb2.NewPoint(metric,
|
||||
map[string]string{"profile": profile, "locality": locality},
|
||||
map[string]interface{}{"count": int_value},
|
||||
time.Now())
|
||||
|
||||
// write point asynchronously
|
||||
writeAPI.WritePoint(p)
|
||||
|
||||
|
||||
|
||||
// Flush writes
|
||||
writeAPI.Flush()
|
||||
|
||||
defer client.Close()
|
||||
|
||||
f, err := os.OpenFile("a3metrics.log",
|
||||
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
//logger := log.New(f, "", log.LstdFlags)
|
||||
//logger.Println(err)
|
||||
|
||||
}
|
||||
|
||||
|
||||
//export goRVExtension
|
||||
func goRVExtension(output *C.char, outputsize C.size_t, input *C.char) {
|
||||
@@ -173,7 +151,7 @@ func goRVExtension(output *C.char, outputsize C.size_t, input *C.char) {
|
||||
go callBackExample()
|
||||
} else {
|
||||
// Return a result through callextension Arma call
|
||||
temp := fmt.Sprintf("Rangermetrics: %s", C.GoString(input))
|
||||
temp := fmt.Sprintf("Cavmetrics: %s", C.GoString(input))
|
||||
result := C.CString(temp)
|
||||
defer C.free(unsafe.Pointer(result))
|
||||
var size = C.strlen(result) + 1
|
||||
|
||||
Reference in New Issue
Block a user