//when get the pid of that port //start collecting the packet for 60s //the topology only need to be check temporaray func StartListen(request *restful.Request, response *restful.Response) { portstring := request.PathParameter("port-id") glog.Info("get the port number", portstring) portint, err := strconv.Atoi(portstring) if err != nil { response.WriteError(500, err) return } pid, _, err := lib.Getinfofromport(portint) if pid == -1 { response.WriteError(500, errors.New("the port is not be listend in this machine ( /proc/net/tcp and /proc/net/tcp6)")) return } if err != nil { response.WriteError(500, err) return } //start listen to specific ip:port for 60s and send the data to es timesignal := time.After(time.Second * Defaulttime) //start collect and check the timesignal every one minutes if !lib.Activeflag { go lib.Startcollect(portint, Device, timesignal) lib.Flagmutex.Lock() lib.Activeflag = true response.Write([]byte("activated")) lib.Flagmutex.Unlock() } else { response.Write([]byte("the server is already been activatied")) } }
//if the port is listend by the server , collecting it's process info func Getprocessinfo(portnum int) (string, error) { pid, pinfo, err := lib.Getinfofromport(portnum) //create the process instance and get the detail info of specified pid Pdetail := &model.ProcessDetail{ Process: &process.Process{Pid: int32(pid)}, } cmd, err := Pdetail.Cmdinfo() if err != nil { return "", err } glog.Info(cmd) pinfo = pinfo + " cmd:" + cmd return pinfo, nil }