Splunk Search

Service maintenance in search

niemi_splunk
Explorer

Hi,

I am a rookie in SPL and I have this general correlation search for application events:

index="foo" sourcetype="bar" (fields.A="something" "fields.B"="something else")

If this was a application specific search I could just specify the service in the search. But what I want to achieve is to use a service id from event rather than a fixed value to suppress results for that specific service. If I append 
| `filter_maintenance_services("e5095542-9132-402f-8f17-242b83710b66")` to the search it works but if I use the event data service id it does not. Ex. 
| `filter_maintenance_services($fields.ServiceID$)`

I suspect that it has to do with  fields.ServiceID not being populated when the filter is deployed. How can get this to work?

 

0 Karma
1 Solution

niemi_splunk
Explorer

Thanks Yuanliu.

I ended up using some of the macro in my search and it works:

| eval service_ids = $fields.ServiceID$
| eval maintenance_object_type = "service", maintenance_object_key = service_ids
| lookup operative_maintenance_log maintenance_object_type, maintenance_object_key OUTPUT _key as maintenance_log_key
| eval in_maintenance = if(IsNull(maintenance_log_key), 0, 1)
| fields - maintenance_object_key, maintenance_object_type, maintenance_log_key
| where IsNull(in_maintenance) OR (in_maintenance != 1)
| fields - in_maintenance
| mvcombine service_ids
| fields - service_ids

I tried a lot of variants for your suggestion to use the macro but didn't find any that worked

View solution in original post

yuanliu
SplunkTrust
SplunkTrust

Let's first clarify your use case.  Your attempted code suggests two implications:

  1. You are trying to substitute parameter in a macro filter_maintenance_services(1); and
  2. You are using this in a dashboard or a map command, where $fields.ServiceID$ dereferences into a service ID such as e5095542-9132-402f-8f17-242b83710b66.

Are these correct?

It seems that you run into a quirk in that macro.  It is written such that quotation marks are required to invoke it properly. (I've written a macro that behaves this way and it took me a while to realize this requirement.)  Try

| `filter_maintenance_services("\"$fields.ServiceID$\"")`

or some variant of this.

 

0 Karma

niemi_splunk
Explorer

Thanks Yuanliu.

I ended up using some of the macro in my search and it works:

| eval service_ids = $fields.ServiceID$
| eval maintenance_object_type = "service", maintenance_object_key = service_ids
| lookup operative_maintenance_log maintenance_object_type, maintenance_object_key OUTPUT _key as maintenance_log_key
| eval in_maintenance = if(IsNull(maintenance_log_key), 0, 1)
| fields - maintenance_object_key, maintenance_object_type, maintenance_log_key
| where IsNull(in_maintenance) OR (in_maintenance != 1)
| fields - in_maintenance
| mvcombine service_ids
| fields - service_ids

I tried a lot of variants for your suggestion to use the macro but didn't find any that worked

richgalloway
SplunkTrust
SplunkTrust

To refer to a field in an event, use single quotes around the field name.  Dollar signs refer to tokens, which are not part of an event.

| `filter_maintenance_services('fields.ServiceID')`
---
If this reply helps you, Karma would be appreciated.
0 Karma

niemi_splunk
Explorer

Thanks, but I already tried that and does not work.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

What’s New in Splunk AI: Volume 02

Welcome to the second edition of “What’s New in Splunk AI” where we look at the latest and greatest updates, ...

Splunk App Dev Quarterly Roundup: AI, Agents, and Innovation!

Another quarter, another wave of innovation. From complex integrations to pushing the limits ...

Federated Search for Dynamic Data Self Storage Is Now Generally Available on Splunk ...

 Splunk is excited to announce the General Availability of Federated Search for Dynamic Data Self Storage ...