avoid OpenSearch search shard failures by including unspecified roles in indexes during NetBox enrichment#749
Closed
niavasha wants to merge 1 commit intocisagov:mainfrom
Closed
Conversation
…le` field because the field exists in index mappings but contains no data. NetBox-enriched documents were missing the role field entirely, even though devices in NetBox have roles assigned (including the default "Unspecified" role).
The `crush()` function in `/logstash/ruby/netbox_enrich.rb` was filtering out any values equal to "Unspecified" or "unspecified" (lines 800-805). Since most auto-populated devices in NetBox get assigned the "Unspecified" role by default, this caused the role field to be removed from enrichment results before being written to OpenSearch.
Modified the `crush()` function to preserve the `role` field even when its value is "Unspecified". This ensures the field is always populated for proper aggregation support.
1. Updated the Ruby script in the Logstash container
2. Restarted Logstash to load the changes
3. Verified new documents contain `source.device.role` field with "Unspecified" value
4. Confirmed OpenSearch aggregations on the role field no longer cause shard failures
```bash
curl -k -u admin:password 'https://localhost:9200/arkime_sessions3-*/_search?size=1' \
-H 'Content-Type: application/json' \
-d '{
"query": {
"bool": {
"must": [
{"term": {"event.dataset": "conn"}},
{"range": {"@timestamp": {"gte": "now-30m"}}}
]
}
},
"_source": ["source.device.role", "related.role"]
}'
```
Documents now include:
```json
{
"source": {
"device": {
"role": ["Unspecified"]
}
},
"related": {
"role": ["Unspecified"]
}
}
```
- Fixes OpenSearch shard failures when aggregating on device role fields
- Enables proper role-based filtering and analysis in dashboards
- Maintains backward compatibility with existing NetBox enrichment logic
- Preserves the "Unspecified" value which is semantically important for inventory tracking
Collaborator
|
Thanks for the explanation and PR, I'll get the commit pulled in for the next release. |
Collaborator
|
I've pulled your commits, with attribution, from your branch into our development branch. It'll be merged into this repo as part of the v25.08.1 release. Even though I'm closing this PR without merging, your changes will be in effect when it's released next week. |
unspecified roles in indexes during NetBox enrichment
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OpenSearch shard failures occur when aggregating on
source.device.rolefield because the field exists in index mappings but contains no data. NetBox-enriched documents were missing the role field entirely, even though devices in NetBox have roles assigned (including the default "Unspecified" role).Root Cause
The
crush()function in/logstash/ruby/netbox_enrich.rbwas filtering out any values equal to "Unspecified" or "unspecified" (lines 800-805). Since most auto-populated devices in NetBox get assigned the "Unspecified" role by default, this caused the role field to be removed from enrichment results before being written to OpenSearch.Solution
Modified the
crush()function to preserve therolefield even when its value is "Unspecified". This ensures the field is always populated for proper aggregation support.Testing
source.device.rolefield with "Unspecified" valueVerification Query
Expected Result
Documents now include:
{ "source": { "device": { "role": ["Unspecified"] } }, "related": { "role": ["Unspecified"] } }Impact
Related Issues
source.device.roleaggregations