/* Copyright © 2026 Thomas von Dein This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package es import ( // "encoding/json/jsontext" // "encoding/json/v2" "encoding/json" "fmt" "codeberg.org/scip/esctl/pkg/cfg" ) type HealthReport struct { Indicators map[string]HealthReportIndicator } type HealthReportIndicator struct { Status, Symptom string Diagnosis []HealthReportDiagnosis } type HealthReportDiagnosis struct { Id, Cause, Action string AffectedResources map[string][]string `json:"affected_resources"` } // we do not use the go-elasticsearch client API here but call the ES // API directly, because the returned structure (a // healthreport.Response) is not iterable, you'd have to explicitly // call every indicator type and every cause etc which also have // different types each. To check which is !green would result in a // gigantic function. func getHealthReport(conf *cfg.Config) (*HealthReport, error) { raw, err := CallAPI(conf, "GET", "/_health_report", "") if err != nil { return nil, err } report := HealthReport{} // FIXME: use this once jsonv2 is no more experimental // // if err := json.UnmarshalDecode( // jsontext.NewDecoder( // bytes.NewBuffer(raw)), // &report); err != nil { // return nil, fmt.Errorf("failed to unmarshal healthreport response: %w", err) // } if err := json.Unmarshal(raw, &report); err != nil { return nil, fmt.Errorf("failed to unmarshal healthreport response: %w", err) } return &report, nil }