Splunk: How to extract a field containing spaces at end - splunk

I try to extract the value of a field that contains spaces. Apparently it is hard to find a regular expression for this case (even the question is if it is possible at all).
Example: 03 Container ID - ALL_ELIGIBLE_STG_RTAIN Offer Set ID
From Above example, we have to get the count Container ID - ALL_ELIGIBLE_STG_RTAIN
I am Expecting like this.
Container ID
Count
ALL_ELIGIBLE_STG_RTAIN
xxxx

Assuming all container IDs are preceded by "Container ID - " then this command will extract them.
| rex "Container ID - (?<ContainerID>\S+)"

Related

CloudWatch Log Insights using "in" to match any message that has any item in array

I have an array with a list of unique literal strings (ids) and I want to use the "in" keyword to test for set membership. I've used the following query, the ephemeral field "id" extracts the id from the message.
fields #timestamp,#message, #logStream
| filter #message like /mutation CreateOrder/
| parse #message 'Parameters: *}], "id"=>"*"}}, "graphql"*' as rest_of_message, id
| parse #message '"variables"=>{"createOrderInput"=>*}, "graphql"' as variables
| filter id in ["182841661","182126710"]
| sort #timestamp desc
| limit 10000
| display id, variables
It was my assumption that it would match any message whose ephemeral field "id" matches any of the literal ids in the array. However, it's only matching the message that contain the first literal id in the array.
I've searched for both ids using the "like" key word and they both come up in the selected period.
Is it possible to do what I want to do? Is there a better way of doing it?

How to only extract match strings from a multi-value field and display in new column in SPLUNK Query

i am trying to extract matched strings from the multivalue field and display in another column. I have tried various options to split the field by delimiter and then mvexpand and then user where/search to pull those data. I was trying to find if there is an easier way to do this without all this hassle in SPLUNK query.
Example: Lets say i have below multi-value column1 field with data separated by delimiter comma
column1 = abc1,test1,test2,abctest1,mail,send,mail2,sendtest2,new,code,results
I was splitting this column using delimiter |eval column2=split(column1,",") and using regex/where/search to search for data with *test* in this column and return results, where i was able to pull the results but the column1 still shows all the values abc1,test1,test2,abctest1,mail,send,mail2,sendtest2,new,code,results , what i want is either to trim1 column1 to show only words match with test or show those entries in new column2 which should only show this words test1,test2,abctest1,sendtest2 as they were only matching *test*.
I would appreciate your help, thanks.
Found the answer after posting this question, its just using exiting mvfilter function to pull the match resutls.
column2=mvfilter(match(column1,"test"))
| eval column2=split(column1,",") | search column2="*test*"
doesn't work, as the split creates a multi-value field, which is a single event containing a single field containing many values. The search for *test* will still find that event, even though it contains abc1, etc... as there is at least one field that is *test*.
What you can use is the mvfilter command to narrow down the multi-value field to the events you are after.
| eval column2=split(column1,",") | eval column2=mvfilter(match(column2,".*test.*"))
Alternatively to this approach, you can use a regular expression to extract what you need.
| rex field=column1 max_match=0 "(<?column2>[^,]*test[^,]*)"
Regardless, at the end, you would need to use mvjoin to join your multiple values into a single string
| eval column2=mvjoin(column2, ",")

Finding element with similar id of 2 fields - text could be random, Selection should be based on text exists or not

Please see the image for better understanding
My search is by ID (RIN)
ID could be either Legal Name (Corporation client) or Last Name (Individual Client)
Below code works:
driver.findElement(By.xpath("//td[contains(#id,'l_Name')]")).click(); - This one will click on Legal Name (Working)
driver.findElement(By.xpath("//td[contains(#id,'Last_Name')]")).click(); - This works for Last Name if the search ID (RIN) is given for Last Name
driver.findElement(By.xpath("//td[contains(#id,'Name')]")).click(); - This one also works for Legal Name as the first element displayed is Legal Name But not working for Last Name
If I do
String S = driver.findElement(By.xpath("//td[contains(#id,'l_Name')]")).getText();
System.out.println(S);
KAB GIHADO CARTAGE INC. - String is displayed
But I want something like this:
driver.findElement(By.xpath("//td[contains(#id,'Name')]")) --- (#id,'Name')where driver identify Legal name or Last name based on if text exists or not - Text will be random based on the ID (RIN)
Here is the logic that will get the text from the field contains Name in it's ID and contains some text (not empty).
String S = driver.findElement(By.xpath("//td[contains(#id,'Name')][not(.='')]")).getText();
System.out.println(S);

Splunk: Removing all text after a specific string in a column

I have a field where all values have the following format:
Knowledge:xyz,id:2907129
The id number always changes, however, all I want is the value of xyz.
I used the following to remove "Knowledge:"e
eval url=replace (url, "Open_KnowledgeZone:", "")
For the id portion, using ",id*" did not work within the eval replace function.
You'll want to use a regex. Something like:
rex field=url "(?<=Knowledge:)(?<AnyFieldName>.*)(?=,)"
Where <AnyFieldName> is the name you want the result field to be. This will select all characters after "Knowledge:" and before the ",".
Here is the regex in action outside of Splunk:
https://regex101.com/r/ofW0a1/1

Kettle - Text File Unstructured

I have a text file that its structure is not in a single line, it is certain that the lines start with zero (0). Below is the sample:
header : TEXT<br>
header : TEXT<br>
header : TEXT<br>
line 1 : 0TEXT Name Other Field<br>
line 2 : TEXT Other Field Phone<br>
line 3 : 0TEXT Name Other Field<br>
line 4 : TEXT Other Field Phone<br>
line 5 : 0TEXT textexttexttext <br>
line 6 : 0TEXT Name Other Field<br>
line 7 : TEXT Other Field Phone<br>
line 8 : 0TEXT Name Other Field<br>
line 9 : TEXT Other Field Phone<br>
What I want to do is get through a regex evaluation the NAME and the PHONE fields and store this values.
Name, Phone
Name, Phone
The regex part is ok, I already did it.
What I need to know is how to get the values from two different lines and put it in the same register?
I found this forum http://forums.pentaho.com/showthread.php?53288-Reading-multi-line-records-from-text-file-newbie and tried to apply a javascript suggested, but it didn't work for me, maybe I did something wrong..
I really did some simple wrong and fixed it.
js..
var x;
var charInitial = line.toString().charAt(0);
if(charInitial == '0') {
x = line.toString();
}
else{
x += line.toString();
}
With this script I get the rows separated, I want to concatenate them and after apply the regex. I can concatenate all the rows that belong to the group, and with a regex I can drop that ones that are unnecessary.
Thanks
Given that you have those records in multiple rows, you have the following options:
1) Group by: as long as you can identify your rows that belong together via some set of keys, you can use a group by and create two new fields, Name and Phone, obtained by "Concatenate fields separated by" (not the "concatenate fields separated by ,", mind that). If the values are either what you want to keep or null, the concatenation works;
2) De-normalize. Same principle applies, you need a set of keys to identify records that belong together, but you will need both your Name and Phone to be in the same field (e.g, Value) and you need another field with the key (either Name or Phone).
3) Perhaps the best one: Analytic Query: Use "Lag N rows forward and get field" with N=1 and you get the phone number of the next row. After this step you have rows with a Not null name and the next row's phone number; rows with a null name and a null phone number. Filter the rows you want after and you're done.
This is just a generic idea. You have to sort out the details.