<?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: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert? in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272792#M31680</link>
    <description>&lt;P&gt;Hi jodros, &lt;/P&gt;

&lt;P&gt;thats the proper way to use it in alert action. we need to update the doc in AoB as well to highlight the same. &lt;/P&gt;</description>
    <pubDate>Thu, 16 Mar 2017 02:02:10 GMT</pubDate>
    <dc:creator>ehaddad_splunk</dc:creator>
    <dc:date>2017-03-16T02:02:10Z</dc:date>
    <item>
      <title>Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272782#M31670</link>
      <description>&lt;P&gt;I am new to Python and to the Splunk Add-On Builder but I have been figuring it out so far but now I am at the point that I am stuck. I have been trying to build a new alert option for our Splunk instance. I am able to execute a binary and pass my parameters to it when called but I have been unable to figure out the correct code to use in order to grab the event that triggered the alert.&lt;/P&gt;

&lt;P&gt;If you look at the Python code below, look specifically at this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;value2="-m "+"'"+"SPLUNK EVENT VALUE SHOULD BE HERE"+"'"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am attempting to figure out how to pull the value of the event which set off the alert and assign it to value2. Below is my full code. Any aid would be highly appreciated. Thank you!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# encoding = utf-8

import os
import sys
import time
import datetime
import subprocess

def process_event(helper, *args, **kwargs):
    """
    # IMPORTANT
    # Do not remove the anchor macro:start and macro:end lines.
    # These lines are used to generate sample code. If they are
    # removed, the sample code will not be updated when configurations
    # are updated.

    [sample_code_macro:start]

    # The following example gets the alert action parameters and prints them to the log
    gfs_impact = helper.get_param("gfs_impact")
    helper.log_info("gfs_impact={}".format(gfs_impact))

    gfs_urgency = helper.get_param("gfs_urgency")
    helper.log_info("gfs_urgency={}".format(gfs_urgency))

    easyvista_category_id = helper.get_param("easyvista_category_id")
    helper.log_info("easyvista_category_id={}".format(easyvista_category_id))


    # The following example adds two sample events ("hello", "world")
    # and writes them to Splunk
    # NOTE: Call helper.writeevents() only once after all events
    # have been added
    helper.addevent("hello", sourcetype="sample_sourcetype")
    helper.addevent("world", sourcetype="sample_sourcetype")
    helper.writeevents(index="summary", host="localhost", source="localhost")

    # The following example gets the events that trigger the alert
    events = helper.get_events()
    for event in events:
        helper.log_info("event={}".format(event))

    # helper.settings is a dict that includes environment configuration
    # Example usage: helper.settings["server_uri"]
    helper.log_info("server_uri={}".format(helper.settings["server_uri"]))
    [sample_code_macro:end]
    """

    helper.log_info("Alert action OMNIbus started.")

    # TODO: Implement your alert action logic here
    value1="-f /lcl/sit/apps/splunk/splunk6.4.0/etc/apps/TA-OMNIbus/bin/config.ini"
    value2="-m "+"'"+"SPLUNK EVENT VALUE SHOULD BE HERE"+"'"
    value3="GFS_Impact="+helper.get_param("gfs_impact")
    value4="GFS_Urgency="+helper.get_param("gfs_urgency")
    value5="ISOC_Instructions="+"'"+helper.get_param("easyvista_category_id")+"'"
    value6="Generic"
    value7="Generic"
    os.system("/lcl/sit/apps/splunk/splunk6.4.0/etc/apps/TA-OMNIbus/bin/posteifmsg %s %s %s %s %s %s %s" % (value1,value2,value3,value4,value5,value6,value7))
    return 0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Feb 2017 14:48:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272782#M31670</guid>
      <dc:creator>larryleeroberts</dc:creator>
      <dc:date>2017-02-01T14:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272783#M31671</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;When developing this in Add-on builder just test that the parameters work with values that you pass/hardcode. Tokenization is automatically handled by alert action framework. &lt;BR /&gt;
To test this out, after you are done building alert action (make sure you restart Splunk), you can use $result.fieldname$ to dynamically pass a value from a given alert results field. Check out "Pass search result values to alert action tokens" section of this doc link for more details&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.1/AdvancedDev/ModAlertsLog"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.1/AdvancedDev/ModAlertsLog&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You can test this out using send alert command as such:&lt;BR /&gt;
index=_internal | head 1| eval fieldname="xyz" | sendalert myalertname param.abc="$result.fieldname$"&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 17:10:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272783#M31671</guid>
      <dc:creator>ehaddad_splunk</dc:creator>
      <dc:date>2017-02-01T17:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272784#M31672</link>
      <description>&lt;P&gt;Ah! I see. So as long as I account for helper.get_param("abc") it should pull it in then? As long as it was supplied in the search that set off the alert that is. Does that sound correct?&lt;/P&gt;

&lt;P&gt;Just trying to make sure I account for how the syntax should be in the script.&lt;BR /&gt;
So like this....&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; value2="-m "+"'"helper.get_param("abc")"'"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Correct? And BIG THANK YOU for the assistance on this!&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 17:46:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272784#M31672</guid>
      <dc:creator>larryleeroberts</dc:creator>
      <dc:date>2017-02-01T17:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272785#M31673</link>
      <description>&lt;P&gt;yes - helper.get_param("abc") would allow you to use static or dynamic values passed from search results triggering the alert. &lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 20:17:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272785#M31673</guid>
      <dc:creator>ehaddad_splunk</dc:creator>
      <dc:date>2017-02-01T20:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272786#M31674</link>
      <description>&lt;P&gt;I have built an alert action for an API call to a security device.  I can invoke it manually by running a search: "host=something find_something_bad | stats count by item1 item2 item3 | sendalert cool_api_action param.item1="$result.item1$"."  However when I have the alert scheduled and configured as such: "host=something find_something_bad | stats count by item1 item2 item3" it sends an email but the API call isn't working.  I have the search scheduled and have the action alert and email configured as actions.  Any assistance would be appreciated. &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:10:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272786#M31674</guid>
      <dc:creator>jodros</dc:creator>
      <dc:date>2020-09-29T13:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272787#M31675</link>
      <description>&lt;P&gt;I would check that the alert is getting fired first by looking at the alerts history. if it is, i would check it it works without tokenization &lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 02:44:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272787#M31675</guid>
      <dc:creator>ehaddad_splunk</dc:creator>
      <dc:date>2017-03-14T02:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272788#M31676</link>
      <description>&lt;P&gt;The alert is being fired.  There is an email action along with the custom alert action.  I get an email but it does not appear that the API call is successful.  How would I test this without tokenization?  &lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 14:02:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272788#M31676</guid>
      <dc:creator>jodros</dc:creator>
      <dc:date>2017-03-14T14:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272789#M31677</link>
      <description>&lt;P&gt;I have it scheduled and it is working, however I have to leave "| sendalert  param.item1="$result.item1$" " at the end of the search or it doesn't work.  Is this expected behavior?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 14:57:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272789#M31677</guid>
      <dc:creator>jodros</dc:creator>
      <dc:date>2017-03-14T14:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272790#M31678</link>
      <description>&lt;P&gt;I would say yes. That is the same thing I found. The only way I could make it so that a value from a search is passed is to have it declared within the search itself like you are doing above. If there is another way, I never found it.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 15:26:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272790#M31678</guid>
      <dc:creator>larryleeroberts</dc:creator>
      <dc:date>2017-03-14T15:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272791#M31679</link>
      <description>&lt;P&gt;I figured out my issue.  I did not have alert action inputs defined.  And after I defined them, I needed to add the the token $result.fieldname$, where fieldname was the actual field from the search results, as the default value for the alert action input.  Another way to accomplish this would be to manually edit the alert_actions.conf file and add the line param.item = $result.fieldname$.  I found what I needed in this doc: &lt;A href="https://docs.splunk.com/Documentation/Splunk/6.5.2/AdvancedDev/CustomAlertConfig"&gt;https://docs.splunk.com/Documentation/Splunk/6.5.2/AdvancedDev/CustomAlertConfig&lt;/A&gt;.  Thanks  &lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 15:57:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272791#M31679</guid>
      <dc:creator>jodros</dc:creator>
      <dc:date>2017-03-15T15:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Add-on Builder: How to edit my Python code to pull the value of event for an alert?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272792#M31680</link>
      <description>&lt;P&gt;Hi jodros, &lt;/P&gt;

&lt;P&gt;thats the proper way to use it in alert action. we need to update the doc in AoB as well to highlight the same. &lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 02:02:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Splunk-Add-on-Builder-How-to-edit-my-Python-code-to-pull-the/m-p/272792#M31680</guid>
      <dc:creator>ehaddad_splunk</dc:creator>
      <dc:date>2017-03-16T02:02:10Z</dc:date>
    </item>
  </channel>
</rss>

