Skip to content

Commit

Permalink
new debug flag for json dumps
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlhansen committed Nov 13, 2024
1 parent c4649b0 commit b371412
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cmd/idrac_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ import (

func main() {
var verbose bool
var debug bool
var configFile string
var err error

flag.BoolVar(&verbose, "verbose", false, "Set verbose logging")
flag.BoolVar(&verbose, "verbose", false, "Enable more verbose logging")
flag.BoolVar(&debug, "debug", false, "Dump JSON response from Redfish requests (only for debugging purpose)")
flag.StringVar(&configFile, "config", "/etc/prometheus/idrac.yml", "Path to idrac exporter configuration file")
flag.Parse()

log.Info("Build information: version=%s revision=%s", version.Version, version.Revision)
config.ReadConfig(configFile)

if debug {
config.Debug = true
verbose = true
}

if verbose {
log.SetLevel(log.LevelDebug)
}
Expand Down
12 changes: 11 additions & 1 deletion internal/collector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -474,7 +475,16 @@ func (client *Client) redfishGet(path string, res interface{}) error {
return fmt.Errorf("%d %s", resp.StatusCode, resp.Status)
}

err = json.NewDecoder(resp.Body).Decode(res)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Error("Error reading response from %q: %v", url, err)
}

if config.Debug {
log.Debug("Reponse from %q: %s", url, body)
}

err = json.Unmarshal(body, res)
if err != nil {
log.Error("Error decoding response from %q: %v", url, err)
return err
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"gopkg.in/yaml.v2"
)

var Debug bool = false
var Config RootConfig = RootConfig{
Hosts: make(map[string]*HostConfig),
}
Expand Down

0 comments on commit b371412

Please sign in to comment.