summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/windows/collect_adcs.go
blob: 0142fcb9c77321bffcb3f8639193eefb74202c24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: GPL-3.0-or-later

package windows

import (
	"strings"

	"github.com/netdata/netdata/go/go.d.plugin/pkg/prometheus"
)

const (
	metricADCSRequestsTotal                         = "windows_adcs_requests_total"
	metricADCSFailedRequestsTotal                   = "windows_adcs_failed_requests_total"
	metricADCSIssuedRequestsTotal                   = "windows_adcs_issued_requests_total"
	metricADCSPendingRequestsTotal                  = "windows_adcs_pending_requests_total"
	metricADCSRequestProcessingTime                 = "windows_adcs_request_processing_time_seconds"
	metricADCSRetrievalsTotal                       = "windows_adcs_retrievals_total"
	metricADCSRetrievalsProcessingTime              = "windows_adcs_retrievals_processing_time_seconds"
	metricADCSRequestCryptoSigningTime              = "windows_adcs_request_cryptographic_signing_time_seconds"
	metricADCSRequestPolicyModuleProcessingTime     = "windows_adcs_request_policy_module_processing_time_seconds"
	metricADCSChallengeResponseResponsesTotal       = "windows_adcs_challenge_responses_total"
	metricADCSChallengeResponseProcessingTime       = "windows_adcs_challenge_response_processing_time_seconds"
	metricADCSSignedCertTimestampListsTotal         = "windows_adcs_signed_certificate_timestamp_lists_total"
	metricADCSSignedCertTimestampListProcessingTime = "windows_adcs_signed_certificate_timestamp_list_processing_time_seconds"
)

func (w *Windows) collectADCS(mx map[string]int64, pms prometheus.Series) {
	pms = pms.FindByNames(
		metricADCSRequestsTotal,
		metricADCSFailedRequestsTotal,
		metricADCSIssuedRequestsTotal,
		metricADCSPendingRequestsTotal,
		metricADCSRequestProcessingTime,
		metricADCSRetrievalsTotal,
		metricADCSRetrievalsProcessingTime,
		metricADCSRequestCryptoSigningTime,
		metricADCSRequestPolicyModuleProcessingTime,
		metricADCSChallengeResponseResponsesTotal,
		metricADCSChallengeResponseProcessingTime,
		metricADCSSignedCertTimestampListsTotal,
		metricADCSSignedCertTimestampListProcessingTime,
	)

	seen := make(map[string]bool)

	for _, pm := range pms {
		if tmpl := pm.Labels.Get("cert_template"); tmpl != "" && tmpl != "_Total" {
			seen[tmpl] = true
			name := strings.TrimPrefix(pm.Name(), "windows_adcs_")
			v := pm.Value
			if strings.HasSuffix(pm.Name(), "_seconds") {
				v *= precision
			}
			mx["adcs_cert_template_"+tmpl+"_"+name] += int64(v)
		}
	}

	for template := range seen {
		if !w.cache.adcs[template] {
			w.cache.adcs[template] = true
			w.addCertificateTemplateCharts(template)
		}
	}
	for template := range w.cache.adcs {
		if !seen[template] {
			delete(w.cache.adcs, template)
			w.removeCertificateTemplateCharts(template)
		}
	}
}