func()

in receiver/splunkenterprisereceiver/scraper.go [1646:1755]


func (s *splunkScraper) scrapeSearchArtifacts(_ context.Context, now pcommon.Timestamp, info infoDict, errs chan error) {
	// if NONE of the metrics set in this scrape are set we return early
	if !s.conf.Metrics.SplunkServerSearchartifactsAdhoc.Enabled && !s.conf.Metrics.SplunkServerSearchartifactsScheduled.Enabled && !s.conf.Metrics.SplunkServerSearchartifactsCompleted.Enabled && !s.conf.Metrics.SplunkServerSearchartifactsIncomplete.Enabled && !s.conf.Metrics.SplunkServerSearchartifactsInvalid.Enabled && !s.conf.Metrics.SplunkServerSearchartifactsSavedsearches.Enabled && !s.conf.Metrics.SplunkServerSearchartifactsJobCacheSize.Enabled && !s.conf.Metrics.SplunkServerSearchartifactsJobCacheCount.Enabled {
		return
	}

	if !s.splunkClient.isConfigured(typeSh) {
		return
	}
	i := info[typeSh].Entries[0].Content

	var da dispatchArtifacts

	ept := apiDict[`SplunkDispatchArtifacts`]

	req, err := s.splunkClient.createAPIRequest(typeSh, ept)
	if err != nil {
		errs <- err
		return
	}

	res, err := s.splunkClient.makeRequest(req)
	if err != nil {
		errs <- err
		return
	}
	defer res.Body.Close()

	body, err := io.ReadAll(res.Body)
	if err != nil {
		errs <- err
		return
	}
	err = json.Unmarshal(body, &da)
	if err != nil {
		errs <- err
		return
	}

	for _, f := range da.Entries {
		if s.conf.Metrics.SplunkServerSearchartifactsAdhoc.Enabled {
			adhocCount, err := strconv.ParseInt(f.Content.AdhocCount, 10, 64)
			if err != nil {
				errs <- err
			}
			s.mb.RecordSplunkServerSearchartifactsAdhocDataPoint(now, adhocCount, s.conf.SHEndpoint.Endpoint, i.Build, i.Version)
		}

		if s.conf.Metrics.SplunkServerSearchartifactsScheduled.Enabled {
			scheduledCount, err := strconv.ParseInt(f.Content.ScheduledCount, 10, 64)
			if err != nil {
				errs <- err
			}
			s.mb.RecordSplunkServerSearchartifactsScheduledDataPoint(now, scheduledCount, s.conf.SHEndpoint.Endpoint, i.Build, i.Version)
		}

		if s.conf.Metrics.SplunkServerSearchartifactsCompleted.Enabled {
			completedCount, err := strconv.ParseInt(f.Content.CompletedCount, 10, 64)
			if err != nil {
				errs <- err
			}
			s.mb.RecordSplunkServerSearchartifactsCompletedDataPoint(now, completedCount, s.conf.SHEndpoint.Endpoint, i.Build, i.Version)
		}

		if s.conf.Metrics.SplunkServerSearchartifactsIncomplete.Enabled {
			incompleteCount, err := strconv.ParseInt(f.Content.IncompleteCount, 10, 64)
			if err != nil {
				errs <- err
			}
			s.mb.RecordSplunkServerSearchartifactsIncompleteDataPoint(now, incompleteCount, s.conf.SHEndpoint.Endpoint, i.Build, i.Version)
		}

		if s.conf.Metrics.SplunkServerSearchartifactsInvalid.Enabled {
			invalidCount, err := strconv.ParseInt(f.Content.InvalidCount, 10, 64)
			if err != nil {
				errs <- err
			}
			s.mb.RecordSplunkServerSearchartifactsInvalidDataPoint(now, invalidCount, s.conf.SHEndpoint.Endpoint, i.Build, i.Version)
		}

		if s.conf.Metrics.SplunkServerSearchartifactsSavedsearches.Enabled {
			savedSearchesCount, err := strconv.ParseInt(f.Content.SavedSearchesCount, 10, 64)
			if err != nil {
				errs <- err
			}
			s.mb.RecordSplunkServerSearchartifactsSavedsearchesDataPoint(now, savedSearchesCount, s.conf.SHEndpoint.Endpoint, i.Build, i.Version)
		}

		if s.conf.Metrics.SplunkServerSearchartifactsJobCacheSize.Enabled {
			infoCacheSize, err := strconv.ParseInt(f.Content.InfoCacheSize, 10, 64)
			if err != nil {
				errs <- err
			}
			statusCacheSize, err := strconv.ParseInt(f.Content.StatusCacheSize, 10, 64)
			if err != nil {
				errs <- err
			}
			s.mb.RecordSplunkServerSearchartifactsJobCacheSizeDataPoint(now, infoCacheSize, s.conf.SHEndpoint.Endpoint, "info", i.Build, i.Version)
			s.mb.RecordSplunkServerSearchartifactsJobCacheSizeDataPoint(now, statusCacheSize, s.conf.SHEndpoint.Endpoint, "status", i.Build, i.Version)
		}

		if s.conf.Metrics.SplunkServerSearchartifactsJobCacheCount.Enabled {
			cacheTotalEntries, err := strconv.ParseInt(f.Content.CacheTotalEntries, 10, 64)
			if err != nil {
				errs <- err
			}
			s.mb.RecordSplunkServerSearchartifactsJobCacheCountDataPoint(now, cacheTotalEntries, s.conf.SHEndpoint.Endpoint, i.Build, i.Version)
		}
	}
}