func monitor() { for event := range events { switch event.Status { case common.STATUS_DIE: logs.Debug("Status", event.Status, event.ID[:12], event.From) app.Remove(event.ID) reportContainerDeath(event.ID) case common.STATUS_START: logs.Debug("Status", event.Status, event.ID[:12], event.From) // if not in watching list, just ignore it if meta := getContainerMeta(event.ID); meta != nil && !app.Valid(event.ID) { container, err := g.Docker.InspectContainer(event.ID) if err != nil { logs.Info("Status inspect docker failed", err) break } eruApp := app.NewEruApp(container, meta) if eruApp == nil { logs.Info("Create EruApp failed") break } lenz.Attacher.Attach(&eruApp.Meta) app.Add(eruApp) reportContainerCure(event.ID) } } } }
// URL /api/container/add/ func addNewContainer(req *Request) (int, interface{}) { type Data struct { Control string `json:"control"` ContainerID string `json:"container_id"` Meta map[string]interface{} `json:"meta"` } data := &Data{} decoder := json.NewDecoder(req.Body) err := decoder.Decode(data) if err != nil { return http.StatusBadRequest, JSON{"message": "wrong JSON format"} } switch data.Control { case "+": if app.Valid(data.ContainerID) { break } logs.Info("API status watch", data.ContainerID) container, err := g.Docker.InspectContainer(data.ContainerID) if err != nil { logs.Info("API status inspect docker failed", err) break } if eruApp := app.NewEruApp(container, data.Meta); eruApp != nil { lenz.Attacher.Attach(&eruApp.Meta) app.Add(eruApp) } } return http.StatusOK, JSON{"message": "ok"} }