src: Add DMA localagent
[barometer.git] / src / dma / cmd / server / agent.go
diff --git a/src/dma/cmd/server/agent.go b/src/dma/cmd/server/agent.go
new file mode 100644 (file)
index 0000000..ffcb4a9
--- /dev/null
@@ -0,0 +1,31 @@
+package main
+
+import (
+       "fmt"
+       "os/exec"
+       "strings"
+)
+
+func createCollectdConf() error {
+       outStatus, errStatus := exec.Command("ssh", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "localhost", "sudo", "systemctl", "status", "collectd").Output()
+       if errStatus != nil {
+               return fmt.Errorf("status NG")
+       }
+       if !strings.Contains(string(outStatus), "running") {
+               return fmt.Errorf("status not running")
+       }
+
+       _, errStop := exec.Command("ssh", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "localhost", "sudo", "systemctl", "stop", "collectd").Output()
+       if errStop != nil {
+               return fmt.Errorf("stop NG")
+       }
+
+       _, errStart := exec.Command("ssh", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "localhost", "sudo", "systemctl", "start", "collectd").Output()
+       if errStart != nil {
+               return fmt.Errorf("start NG")
+       }
+
+       fmt.Println("All complete!")
+
+       return nil
+}