MCPcopy
hub / github.com/PatchMon/PatchMon / Get

Method Get

server-source-code/internal/handler/metrics.go:39–69  ·  view source on GitHub ↗

Get handles GET /api/v1/metrics - returns metrics settings.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

37
38// Get handles GET /api/v1/metrics - returns metrics settings.
39func (h *MetricsHandler) Get(w http.ResponseWriter, r *http.Request) {
40 if h.adminModeGuard(w) {
41 return
42 }
43 s, err := h.settings.GetFirst(r.Context())
44 if err != nil {
45 Error(w, http.StatusInternalServerError, "Failed to load settings")
46 return
47 }
48
49 // Generate anonymous ID if it doesn't exist
50 if s.MetricsAnonymousID == nil || *s.MetricsAnonymousID == "" {
51 anonymousID := uuid.New().String()
52 s.MetricsAnonymousID = &anonymousID
53 if err := h.settings.Update(r.Context(), s); err != nil {
54 Error(w, http.StatusInternalServerError, "Failed to save anonymous ID")
55 return
56 }
57 }
58
59 var lastSent interface{}
60 if s.MetricsLastSent != nil {
61 lastSent = s.MetricsLastSent.Format(time.RFC3339)
62 }
63
64 JSON(w, http.StatusOK, map[string]interface{}{
65 "metrics_enabled": s.MetricsEnabled,
66 "metrics_anonymous_id": s.MetricsAnonymousID,
67 "metrics_last_sent": lastSent,
68 })
69}
70
71// Update handles PUT /api/v1/metrics - updates metrics_enabled.
72func (h *MetricsHandler) Update(w http.ResponseWriter, r *http.Request) {

Callers 15

ListMethod · 0.45
HostsMethod · 0.45
HostDetailMethod · 0.45
PackageTrendsMethod · 0.45
ListHostsMethod · 0.45
GetHostPackagesMethod · 0.45
GetHostPackageReportsMethod · 0.45
GetHostAgentQueueMethod · 0.45
ListMethod · 0.45
GetHostsMethod · 0.45
GetActivityMethod · 0.45
hostFromRequestFunction · 0.45

Calls 5

adminModeGuardMethod · 0.95
ErrorFunction · 0.85
GetFirstMethod · 0.80
JSONFunction · 0.70
UpdateMethod · 0.45

Tested by

no test coverage detected