<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to create a new field using macros? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153016#M42899</link>
    <description>&lt;P&gt;I understand what you mean, but the problem is that my main search looks at a different sourcetype, which does not have ip as field. So, this will return absolutely no results. What I try to achieve is to add a new field (ip) and then use it to group the mac addresses. I will try to do some more research and come back with a solution.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Apr 2015 14:08:41 GMT</pubDate>
    <dc:creator>andra_pietraru</dc:creator>
    <dc:date>2015-04-21T14:08:41Z</dc:date>
    <item>
      <title>How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153003#M42886</link>
      <description>&lt;P&gt;I am trying to add a new field in my events using eval, but I am getting errors.&lt;BR /&gt;
My search looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval newField=`getIpBasedOnMac($mac$)` | chart values(field1) over newField by mac
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any suggestions on how I could create &lt;CODE&gt;newField&lt;/CODE&gt; and give it the value that the macro returns?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 11:54:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153003#M42886</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-21T11:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153004#M42887</link>
      <description>&lt;P&gt;Does &lt;CODE&gt;$mac$&lt;/CODE&gt; come from some input, i.e. is it a token, or why did you enclose it in dollar signs?&lt;BR /&gt;
Otherwise, the dollar signs are needed only in the definition of the macro. If &lt;CODE&gt;mac&lt;/CODE&gt; exists as a field, you can just call your macro with the plain field name as its argument.&lt;BR /&gt;
Also, what does your macro look like?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:13:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153004#M42887</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-04-21T13:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153005#M42888</link>
      <description>&lt;P&gt;No, mac is just a field that I want to pass as argument. I tried without the $ sign, but still get the same error.&lt;BR /&gt;
If I call the macro without the eval, i.e:&lt;BR /&gt;
 sourcetype=xmlConfig &lt;CODE&gt;findIpBasedOnMac(00000001)&lt;/CODE&gt;&lt;BR /&gt;
 I get ip="190.000.000.00"&lt;/P&gt;

&lt;P&gt;The problem is that I want to assign that value as a new field in my events. IS there any way to do that?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:19:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153005#M42888</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-21T13:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153006#M42889</link>
      <description>&lt;P&gt;Probably &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; What does your macro definition look like? It has to be of the form you would usually place after the &lt;CODE&gt;=&lt;/CODE&gt;-sign of your eval.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:22:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153006#M42889</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-04-21T13:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153007#M42890</link>
      <description>&lt;P&gt;You're already on your way using eval to set a new field. However, your macro has to be written in search language terms, it's just string replacement. So whatever you would ordinarily write to get "190.000.000.00" from "00000001" (a lookup?) would have to be the body of the macro.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:23:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153007#M42890</guid>
      <dc:creator>sowings</dc:creator>
      <dc:date>2015-04-21T13:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153008#M42891</link>
      <description>&lt;P&gt;hi andra_pietraru,&lt;BR /&gt;
try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | eval newField= getIpBasedOnMac("$mac$") | chart values(field1) over newField by mac
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:25:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153008#M42891</guid>
      <dc:creator>gyslainlatsa</dc:creator>
      <dc:date>2015-04-21T13:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153009#M42892</link>
      <description>&lt;P&gt;This is the macro:&lt;/P&gt;

&lt;P&gt;sourcetype=xmlConfig  | rename switch.ipv4address as ip | search MAC=$mac$ | return ip&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:29:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153009#M42892</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-21T13:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153010#M42893</link>
      <description>&lt;P&gt;I tried, still get error. Thanks for the suggestion!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:32:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153010#M42893</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-21T13:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153011#M42894</link>
      <description>&lt;P&gt;Your rex probably got corrupted while posting it, you need to post it as code. But still, that looks like the problem. As sowings (and I also) mentioned, your macro definition must be what you would usually put after the &lt;CODE&gt;=&lt;/CODE&gt;-sign of your eval. A macro is basically text replacement.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:34:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153011#M42894</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-04-21T13:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153012#M42895</link>
      <description>&lt;P&gt;You can't just run any search string you like in the middle of another search string. To perform that kind of translation you'd have to run a saved search, and use join (icky) or create some sort of lookup.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:37:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153012#M42895</guid>
      <dc:creator>sowings</dc:creator>
      <dc:date>2015-04-21T13:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153013#M42896</link>
      <description>&lt;P&gt;Actually, I just realized that I do not even need that rex to retrieve the ip field.&lt;/P&gt;

&lt;P&gt;Anyway, how could I return only the value of the ip field instead of "ip=..." in my macro? Should I use rex for that as well? I am fairly new to Splunk, so I have no idea of what are my possibilities. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:48:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153013#M42896</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-21T13:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153014#M42897</link>
      <description>&lt;P&gt;You should not think of "returning" anything in your macro, only as much as for example &lt;CODE&gt;if(field=value,1,0)&lt;/CODE&gt; returns something. What just crossed my mind is that you could run your macro almost as it is, but change it so that it contains an eval expression which gives you the field you want, something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=xmlConfig | search MAC=$mac$ | eval ip=switch.ipv4address
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You could then use the field "ip" in the search after the macro.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:54:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153014#M42897</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-04-21T13:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153015#M42898</link>
      <description>&lt;P&gt;The function  &lt;CODE&gt;getIpBasedOnmac&lt;/CODE&gt; does what and what parameters it can take to return a result, I think we have to look at how we used the function &lt;CODE&gt;getIpBasedOnMac&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 14:02:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153015#M42898</guid>
      <dc:creator>gyslainlatsa</dc:creator>
      <dc:date>2015-04-21T14:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153016#M42899</link>
      <description>&lt;P&gt;I understand what you mean, but the problem is that my main search looks at a different sourcetype, which does not have ip as field. So, this will return absolutely no results. What I try to achieve is to add a new field (ip) and then use it to group the mac addresses. I will try to do some more research and come back with a solution.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 14:08:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153016#M42899</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-21T14:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153017#M42900</link>
      <description>&lt;P&gt;The eval in your macro will create the field ip &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 14:11:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153017#M42900</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-04-21T14:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153018#M42901</link>
      <description>&lt;P&gt;Won't the eval create the field ip for sourcetype=xmlConfig? So in my main search I look at sourcetype=other and it doesn't find the created ip field.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 14:20:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153018#M42901</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-21T14:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153019#M42902</link>
      <description>&lt;P&gt;Your eval will create the field for this event, in this search.&lt;/P&gt;

&lt;P&gt;With the above macro definition, try&lt;BR /&gt;
     ... |&lt;CODE&gt;getIpBasedOnMac(mac)&lt;/CODE&gt; | chart values(field1) over ip by mac&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 14:23:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153019#M42902</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-04-21T14:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153020#M42903</link>
      <description>&lt;P&gt;I tried. No results.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 14:39:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153020#M42903</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-21T14:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153021#M42904</link>
      <description>&lt;P&gt;getIpBasedOnMac() is not supported by splunk&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 15:28:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153021#M42904</guid>
      <dc:creator>gyslainlatsa</dc:creator>
      <dc:date>2015-04-21T15:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new field using macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153022#M42905</link>
      <description>&lt;P&gt;It is a macro, written by andra_pietraru.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 16:03:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-new-field-using-macros/m-p/153022#M42905</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-04-21T16:03:54Z</dc:date>
    </item>
  </channel>
</rss>

