mi: Revert "replace all WMI calls with MI calls" (#1713)

This commit is contained in:
Jan-Otto Kröpke
2024-11-03 11:20:46 +01:00
committed by GitHub
parent c4f5d58a3e
commit 45d3eabab9
82 changed files with 738 additions and 2767 deletions

View File

@@ -11,11 +11,10 @@ import (
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus-community/windows_exporter/internal/headers/wtsapi32"
"github.com/prometheus-community/windows_exporter/internal/mi"
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
"github.com/prometheus-community/windows_exporter/internal/types"
"github.com/prometheus-community/windows_exporter/internal/utils"
"github.com/prometheus/client_golang/prometheus"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows"
)
@@ -32,9 +31,9 @@ type Win32_ServerFeature struct {
ID uint32
}
func isConnectionBrokerServer(logger *slog.Logger, miSession *mi.Session) bool {
func isConnectionBrokerServer(logger *slog.Logger, wmiClient *wmi.Client) bool {
var dst []Win32_ServerFeature
if err := miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * FROM Win32_ServerFeature"))); err != nil {
if err := wmiClient.Query("SELECT * FROM Win32_ServerFeature", &dst); err != nil {
return false
}
@@ -113,14 +112,10 @@ func (c *Collector) Close(_ *slog.Logger) error {
return nil
}
func (c *Collector) Build(logger *slog.Logger, miSession *mi.Session) error {
if miSession == nil {
return errors.New("miSession is nil")
}
func (c *Collector) Build(logger *slog.Logger, wmiClient *wmi.Client) error {
logger = logger.With(slog.String("collector", Name))
c.connectionBrokerEnabled = isConnectionBrokerServer(logger, miSession)
c.connectionBrokerEnabled = isConnectionBrokerServer(logger, wmiClient)
c.sessionInfo = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "session_info"),