Exemplo n.º 1
0
func V1DeleteMonitor(c *middleware.Context) {
	id := c.ParamsInt64(":id")

	check, err := sqlstore.GetCheckById(c.OrgId, id)
	if err != nil {
		handleError(c, err)
		return
	}

	// get the endpoint that the check belongs too.
	endpoint, err := sqlstore.GetEndpointById(c.OrgId, check.EndpointId)
	if err != nil {
		handleError(c, err)
		return
	}

	// now update the endpoint and remove the check.
	newChecks := make([]m.Check, 0)
	for _, ch := range endpoint.Checks {
		if ch.Id != id {
			newChecks = append(newChecks, ch)
		}
	}
	endpoint.Checks = newChecks
	err = sqlstore.UpdateEndpoint(endpoint)
	if err != nil {
		handleError(c, err)
		return
	}
	c.JSON(200, "monitor deleted")
}
Exemplo n.º 2
0
func GetOrgQuotas(c *middleware.Context) *rbody.ApiResponse {
	var quotas []m.OrgQuotaDTO
	var err error
	org := c.ParamsInt64("orgId")
	if setting.Quota.Enabled {
		quotas, err = sqlstore.GetOrgQuotas(org)
		if err != nil {
			return rbody.ErrResp(500, err)
		}
	} else {
		quotas = []m.OrgQuotaDTO{
			{
				OrgId:  org,
				Target: "endpoint",
				Limit:  -1,
				Used:   -1,
			},
			{
				OrgId:  org,
				Target: "probe",
				Limit:  -1,
				Used:   -1,
			},
		}
	}

	return rbody.OkResp("quotas", quotas)
}
Exemplo n.º 3
0
func V1DeleteCollector(c *middleware.Context) {
	id := c.ParamsInt64(":id")

	err := sqlstore.DeleteProbe(id, c.OrgId)
	if err != nil {
		handleError(c, err)
		return
	}

	c.JSON(200, "collector deleted")
	return
}
Exemplo n.º 4
0
func V1GetCollectorById(c *middleware.Context) {
	id := c.ParamsInt64(":id")

	probe, err := sqlstore.GetProbeById(id, c.OrgId)
	if err != nil {
		handleError(c, err)
		return
	}

	c.JSON(200, probe)
	return
}
Exemplo n.º 5
0
func UpdateOrgQuota(c *middleware.Context) *rbody.ApiResponse {
	orgId := c.ParamsInt64(":orgId")
	target := c.Params(":target")
	limit := c.ParamsInt64(":limit")

	if _, ok := setting.Quota.Org.ToMap()[target]; !ok {
		return rbody.NotFound
	}

	quota := m.OrgQuotaDTO{
		OrgId:  orgId,
		Target: target,
		Limit:  limit,
	}
	err := sqlstore.UpdateOrgQuota(&quota)
	if err != nil {
		return rbody.ErrResp(500, err)
	}
	return rbody.OkResp("quota", quota)
}