AppD Archive

Question regarding list of string data in a method data collector

CommunityUser
Splunk Employee
Splunk Employee

How do you collect data from a list of string that is a property of a method parameter using a Method Invocation Data Collectior? We either end up with [CANNOT EVALUATE: Error getting data from specified method parameter] or [System.Collections.Generic.List`1[System.String]].

Any help is appreciated.

0 Karma
1 Solution

CommunityUser
Splunk Employee
Splunk Employee

Looking at the documentation on List<String> there isn't a single method you can call (without adding new methods to your code) that would display all the elements. You could certainly get the first element, last element, or any element by index, but if you want all elements in a variable-length list you can't do it in a single call with no custom methods added.

If you were willing to add code, you could call ForEach(Action<T> action) where action was a method that takes a String and prints it via Console.WriteLine(). The ForEach method passes each element of a list in turn to the Action method. The result would be a newline-separated list of all the elements.

This is not ideal, but seems like the only way to get exactly what you want.

View solution in original post

0 Karma

Mike_McFarland
New Member

Thinking about this, should I assume that you mean a java.util.List List<String> ?

That is more interesting!

What have you tried so far?  I assume that you have tried the obvious 'Use toString()'?

If you had a method that would return the info that you wanted, then the 'Use Getter Chain' could possibly do what you want.  Granted, this is a big 'if'.

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

We did try using a Linq statement with the "use getter chain option" but that returned an error (as we expected it likely would).

0 Karma

Mike_McFarland
New Member

RBaco is spot on.  If you were OK with just the first element of the string array, then somithing as simple as using a getter chain with "[0]" should do the trick.  If that does not work as expect, see if there is an error in the agent log, and let us know what the error is.

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

We were hoping to capture all the elements, but it appears this will require the addition of a new method to include in the getter chain. We have control over the source code in this case, so it's something we can do although a bit inconvenient.

Thanks!

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

Looking at the documentation on List<String> there isn't a single method you can call (without adding new methods to your code) that would display all the elements. You could certainly get the first element, last element, or any element by index, but if you want all elements in a variable-length list you can't do it in a single call with no custom methods added.

If you were willing to add code, you could call ForEach(Action<T> action) where action was a method that takes a String and prints it via Console.WriteLine(). The ForEach method passes each element of a list in turn to the Action method. The result would be a newline-separated list of all the elements.

This is not ideal, but seems like the only way to get exactly what you want.

0 Karma

CommunityUser
Splunk Employee
Splunk Employee

Hi,

It is a .NET  object of List<string>. Calling ToString() returns "[System.Collections.Generic.List`1[System.String]]". What we want are the contents of the list.

Thanks!

0 Karma

Mike_McFarland
New Member

When you say "list of string data", do you mean that you have a string array?  If so, are you wanting a specific element of that array, (say always the first element) or everything in the array?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...