add machineId, gofmt

pull/3/head
Simon Let 7 years ago
parent 4d8d7efa4d
commit abcd44e108
  1. 22
      collect/resh-collect.go
  2. 1
      common/resh-common.go

@ -3,17 +3,18 @@ package main
import (
"bytes"
"encoding/json"
"flag"
"github.com/BurntSushi/toml"
common "github.com/curusarn/resh/common"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"os/user"
"path/filepath"
"flag"
"log"
"net/http"
"strconv"
"strings"
common "github.com/curusarn/resh/common"
"github.com/BurntSushi/toml"
)
func main() {
@ -84,7 +85,6 @@ func main() {
realtimeBeforeLocal := realtimeBefore + timezoneBeforeOffset
realtimeAfterLocal := realtimeAfter + timezoneAfterOffset
rec := common.Record{
// core
CmdLine: *cmdLine,
@ -127,6 +127,7 @@ func main() {
RealtimeSinceBoot: realtimeSinceBoot,
GitWorkTree: getGitDir(),
MachineId: getMachineId(),
}
sendRecord(rec, strconv.Itoa(config.Port))
}
@ -151,6 +152,14 @@ func sendRecord(r common.Record, port string) {
}
}
func getMachineId() string {
dat, err := ioutil.ReadFile("/etc/machine-id")
if err != nil {
log.Fatal("failed to open /etc/machine-id")
}
return string(dat)
}
func getGitDir() string {
// assume we are in pwd
gitWorkTree := os.Getenv("GIT_WORK_TREE")
@ -189,4 +198,3 @@ func getTimezoneOffsetInSeconds(zone string) float64 {
secs := ((hours * 60) + mins) * 60
return float64(secs)
}

@ -42,6 +42,7 @@ type Record struct {
//Logs []string `json: "logs"`
GitWorkTree string `json:"gitWorkTree"`
MachineId string `json:"machineId"`
}
type Config struct {

Loading…
Cancel
Save