Example #1
0
func V1AddCollector(c *middleware.Context, probe m.ProbeDTO) {
	probe.OrgId = c.OrgId
	if probe.Id != 0 {
		c.JSON(400, "Id already set. Try update instead of create.")
		return
	}
	if probe.Name == "" {
		c.JSON(400, "Collector Name not set.")
		return
	}

	if err := sqlstore.AddProbe(&probe); err != nil {
		handleError(c, err)
		return
	}

	c.JSON(200, probe)
	return
}
Example #2
0
func V1UpdateCollector(c *middleware.Context, probe m.ProbeDTO) {
	probe.OrgId = c.OrgId
	if probe.Name == "" {
		c.JSON(400, "Collector Name not set.")
		return
	}

	if probe.Public {
		if !c.IsAdmin {
			c.JSON(400, "Only admins can make public collectors")
			return
		}
	}

	if err := sqlstore.UpdateProbe(&probe); err != nil {
		handleError(c, err)
		return
	}

	c.JSON(200, probe)
	return
}