<?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 Splunk API PDF Generation in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-API-PDF-Generation/m-p/668629#M11263</link>
    <description>&lt;P&gt;I am using splunk 8.2.12 and am trying to generate a pdf via an existing alert action using splunk api calls. The action was originally developed for automated ticketing within another app when a splunk alert is triggered. The end goal is to be able to upload the pdf of&amp;nbsp; search results based on the alert to the ticket in an automated way. below is the current state of the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;def create_pdf_for_ticket(payload, output_file):
    # Extract relevant information from the payload
    ticket_id = payload.get('sid')
    index = payload.get('result', {}).get('index')
    sourcetype = payload.get('result', {}).get('sourcetype')

    # Construct the search query based on the extracted information
    search_query = f'search index={index} sourcetype={sourcetype} sid={ticket_id}'

    # Make the API request to execute the search and get the results
    search_payload = {
        'search': search_query,
        'output_mode': 'json',
    }

    search_response = requests.get('http://localhost:8089/services/search/jobs/export', params=search_payload, headers=post_headers)

    # Check if the search request was successful
    if search_response.status_code == 200:
        # Save the search results to a file
        with open(output_file, 'wb') as pdf_file:
            pdf_file.write(search_response.content)
        print(f"PDF created successfully at: {output_file}")
    else:
        print(f"Error creating PDF: {search_response.status_code} - {search_response.text}")

def main():
*****
        # Create PDF for the ticket
        output_file = os.environ['SPLUNK_HOME'] + '/etc/apps/Splunk_Ivanti/local/ticket.pdf'
        create_pdf_for_ticket(payload, output_file)
*****&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Nov 2023 18:11:25 GMT</pubDate>
    <dc:creator>BrownNicholasGS</dc:creator>
    <dc:date>2023-11-14T18:11:25Z</dc:date>
    <item>
      <title>Splunk API PDF Generation</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-API-PDF-Generation/m-p/668629#M11263</link>
      <description>&lt;P&gt;I am using splunk 8.2.12 and am trying to generate a pdf via an existing alert action using splunk api calls. The action was originally developed for automated ticketing within another app when a splunk alert is triggered. The end goal is to be able to upload the pdf of&amp;nbsp; search results based on the alert to the ticket in an automated way. below is the current state of the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;def create_pdf_for_ticket(payload, output_file):
    # Extract relevant information from the payload
    ticket_id = payload.get('sid')
    index = payload.get('result', {}).get('index')
    sourcetype = payload.get('result', {}).get('sourcetype')

    # Construct the search query based on the extracted information
    search_query = f'search index={index} sourcetype={sourcetype} sid={ticket_id}'

    # Make the API request to execute the search and get the results
    search_payload = {
        'search': search_query,
        'output_mode': 'json',
    }

    search_response = requests.get('http://localhost:8089/services/search/jobs/export', params=search_payload, headers=post_headers)

    # Check if the search request was successful
    if search_response.status_code == 200:
        # Save the search results to a file
        with open(output_file, 'wb') as pdf_file:
            pdf_file.write(search_response.content)
        print(f"PDF created successfully at: {output_file}")
    else:
        print(f"Error creating PDF: {search_response.status_code} - {search_response.text}")

def main():
*****
        # Create PDF for the ticket
        output_file = os.environ['SPLUNK_HOME'] + '/etc/apps/Splunk_Ivanti/local/ticket.pdf'
        create_pdf_for_ticket(payload, output_file)
*****&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2023 18:11:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-API-PDF-Generation/m-p/668629#M11263</guid>
      <dc:creator>BrownNicholasGS</dc:creator>
      <dc:date>2023-11-14T18:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API PDF Generation</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-API-PDF-Generation/m-p/668920#M11264</link>
      <description>&lt;P&gt;When you say, "&lt;SPAN&gt;upload the pdf of&amp;nbsp; search results based on the alert to the ticket in an automated way" are you wanting to take the PDF that the code creates (the file&amp;nbsp;&lt;EM&gt;/etc/apps/Splunk_Ivanti/local/ticket.pdf&lt;/EM&gt;) and post it to some other endpoint?&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If the answer is yes, then you'd need to write the python to do that send.&amp;nbsp; If you want an example how this is done, take a look at the &lt;EM&gt;%SPLUNK_HOME%/etc/apps/alert_webhook/bin/webhook.py&lt;/EM&gt;.&amp;nbsp; That's the code behind the Webhook Alert Action and it does a fairly simple send of data to a URL.&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 21:49:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-API-PDF-Generation/m-p/668920#M11264</guid>
      <dc:creator>_JP</dc:creator>
      <dc:date>2023-11-16T21:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API PDF Generation</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-API-PDF-Generation/m-p/669010#M11265</link>
      <description>&lt;P&gt;JP I already have a connection to the other app in another part of my python you aren't seeing- this is a *new feature* on a app that I had previously built.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess the real question is - is there a way to&lt;/P&gt;&lt;P&gt;1) call Splunk's built in PDF GEN with a SID from an alert action or&lt;/P&gt;&lt;P&gt;2) run a report based on info from an alert action&lt;/P&gt;&lt;P&gt;3) some other method I'm just not thinking of&lt;/P&gt;&lt;P&gt;I do have a new working version that uses fpdf to create a pdf based on the xml output of the jobs/{SID}/results API call so if there is no other way I may just have to bite the bullet on that.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 13:28:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-API-PDF-Generation/m-p/669010#M11265</guid>
      <dc:creator>BrownNicholasGS</dc:creator>
      <dc:date>2023-11-17T13:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk API PDF Generation</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-API-PDF-Generation/m-p/669046#M11266</link>
      <description>&lt;P&gt;I don't know off the top of my head if you can get to the PDF generation functionality from within Python - I've never tried in python and I haven't been able to find any documentation within Splunk's documentation if they officially expose those calls in their Python SDK. The PDF stuff in Splunk is based off of &lt;A href="https://www.reportlab.com/" target="_self"&gt;ReportLab&lt;/A&gt;, and lives in %SPLUNK_HOME%\Python-3.7\Lib\site-packages\reportlab, so you can poke aroundthere a bit to see if that helps. I wasn't finding anything obvious of Splunk-written python calling the ReportLab stuff to generate a PDF, your luck might be better.&lt;/P&gt;&lt;P&gt;You can get a PDF generated from a REST endpoint - but do keep in mind that the overall PDF generation in Splunk is dashboard-centric, not search-centric.&amp;nbsp; So you will need to create a Dashboard that renders the results for your SID, and then have that be generated as a PDF.&amp;nbsp; Here are a few posts of people generating the PDF via a REST call which you can do from the CLI, within Python, etc.&amp;nbsp; Once you have those bytes you can send those on to where you need:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.splunk.com/t5/Getting-Data-In/How-to-generate-PDF-from-view-in-REST-API/m-p/274792" target="_blank"&gt;Solved: Re: Generate PDF from View in REST API - Splunk Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.splunk.com/t5/Reporting/Trigger-a-PDF-via-the-command-line/m-p/147464" target="_blank"&gt;Trigger a PDF via the command line - Splunk Community&lt;/A&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;Historically the built-in PDF generation of Splunk has left something to be desired.&amp;nbsp; It's just been OK...There are some apps on Splunkbase that help with various PDF things you could look into as well:&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;STRONG&gt;PDF Apps:&lt;/STRONG&gt;&amp;nbsp;&lt;A href="https://splunkbase.splunk.com/apps?keyword=pdf" target="_blank"&gt;https://splunkbase.splunk.com/apps?keyword=pdf&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 18:20:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-API-PDF-Generation/m-p/669046#M11266</guid>
      <dc:creator>_JP</dc:creator>
      <dc:date>2023-11-17T18:20:38Z</dc:date>
    </item>
  </channel>
</rss>

