Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .chloggen/splunkenterprisereceiver_license_timeleft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: 'splunkenterprisereceiver'

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Added a new metric `splunk.license.expiration.seconds_remaining` to report the time remaining in seconds before a Splunk Enterprise license expires."

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [42630]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
- Includes the following attributes: `status`, `label`, `type`.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
18 changes: 18 additions & 0 deletions receiver/splunkenterprisereceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,24 @@ This is the overall status of the kvstore for the given deployment.
| splunk.splunkd.build | The build number for this Splunk instance version | Any Str | false |
| splunk.splunkd.version | The splunkd version number | Any Str | false |

### splunk.license.expiration.seconds_remaining

Gauge tracking the seconds remaining on any given Splunk License found via Splunk API. **Note:** This will only work on a Cluster Manager.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {seconds} | Gauge | Int |

#### Attributes

| Name | Description | Values | Optional |
| ---- | ----------- | ------ | -------- |
| splunk.license.status | The status of the license. | Any Str | false |
| splunk.license.label | The label of the license. | Any Str | false |
| splunk.license.type | The type of license. | Any Str | false |
| splunk.splunkd.build | The build number for this Splunk instance version | Any Str | false |
| splunk.splunkd.version | The splunkd version number | Any Str | false |

### splunk.license.index.usage

Gauge tracking the indexed license usage per index
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ all_set:
enabled: true
splunk.kvstore.status:
enabled: true
splunk.license.expiration.seconds_remaining:
enabled: true
splunk.license.index.usage:
enabled: true
splunk.parse.queue.ratio:
Expand Down Expand Up @@ -153,6 +155,8 @@ none_set:
enabled: false
splunk.kvstore.status:
enabled: false
splunk.license.expiration.seconds_remaining:
enabled: false
splunk.license.index.usage:
enabled: false
splunk.parse.queue.ratio:
Expand Down
16 changes: 16 additions & 0 deletions receiver/splunkenterprisereceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ attributes:
splunk.rollingorrestart:
description: Boolean that indicates if there is a rolling restart or rolling upgrade in progress.
type: bool
splunk.license.status:
description: The status of the license.
type: string
splunk.license.label:
description: The label of the license.
type: string
splunk.license.type:
description: The type of license.
type: string

metrics:
splunk.license.index.usage:
Expand Down Expand Up @@ -448,6 +457,13 @@ metrics:
gauge:
value_type: int
attributes: [splunk.splunkd.build, splunk.splunkd.version]
splunk.license.expiration.seconds_remaining:
enabled: false
description: Gauge tracking the seconds remaining on any given Splunk License found via Splunk API. **Note:** This will only work on a Cluster Manager.
unit: "{seconds}"
gauge:
value_type: int
attributes: [splunk.license.status, splunk.license.label, splunk.license.type, splunk.splunkd.build, splunk.splunkd.version]

tests:
config:
67 changes: 67 additions & 0 deletions receiver/splunkenterprisereceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package splunkenterprisereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkenterprisereceiver"

import (
"bytes"
"context"
"encoding/json"
"encoding/xml"
Expand Down Expand Up @@ -107,6 +108,7 @@ func (s *splunkScraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
s.scrapeHealth,
s.scrapeSearch,
s.scrapeIndexerClusterManagerStatus,
s.scrapeLicenses,
}
errChan := make(chan error, len(metricScrapes))

Expand Down Expand Up @@ -2139,3 +2141,68 @@ func (s *splunkScraper) scrapeIndexerClusterManagerStatus(_ context.Context, now
s.mb.RecordSplunkIndexerRollingrestartStatusDataPoint(now, 0, ic.Content.SearchableRolling, ic.Content.RollingRestartFlag, i.Build, i.Version)
}
}

// Scrape License Endpoint
func (s *splunkScraper) scrapeLicenses(_ context.Context, now pcommon.Timestamp, info infoDict, errs chan error) {
if !s.conf.Metrics.SplunkLicenseExpirationSecondsRemaining.Enabled {
return
}

var eptType string

switch {
case s.conf.IdxEndpoint.Endpoint != "":
errs <- errors.New("splunk.license.remaining cannot be scraped from an indexer")
return
case s.conf.SHEndpoint.Endpoint != "":
errs <- errors.New("splunk.license.remaining cannot be scraped from a search head")
return
case s.conf.CMEndpoint.Endpoint != "":
eptType = typeCm
default:
errs <- errors.New("no endpoint set for scraping")
return
}

i := info[eptType].Entries[0].Content
s.settings.Logger.Debug(fmt.Sprintf("endpoint type set: %s", eptType))

ept := apiDict[`SplunkLicenses`]
var licenses licenses

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

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

var body bytes.Buffer
_, err = io.Copy(&body, res.Body)
if err != nil {
errs <- err
return
}
s.settings.Logger.Debug(fmt.Sprintf("license response: %s", body.String()))
defer body.Reset()

if err := json.NewDecoder(&body).Decode(&licenses); err != nil {
errs <- err
return
}

s.settings.Logger.Debug(fmt.Sprintf("number of licenses found: %d", len(licenses.Entries)))

for _, entry := range licenses.Entries {
expTime := time.Unix(entry.Content.ExpirationTime, 0)
timeRemaining := int64(expTime.Sub(time.Now().UTC()).Seconds()) // expiry time - current time in seconds converted to int64

s.mb.RecordSplunkLicenseExpirationSecondsRemainingDataPoint(now, timeRemaining, entry.Content.Status, entry.Content.Label, entry.Content.Type, i.Build, i.Version)
}
}
Loading