<?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 install local app via rest API? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-install-local-app-via-rest-API/m-p/655393#M111045</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;local installation means that app package must be on splunk server not on you local workstation. See old &lt;A href="https://community.splunk.com/t5/Getting-Data-In/REST-API-Install-local-App/m-p/354279" target="_blank"&gt;post&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;r. Ismo&lt;/P&gt;</description>
    <pubDate>Wed, 23 Aug 2023 17:30:38 GMT</pubDate>
    <dc:creator>isoutamo</dc:creator>
    <dc:date>2023-08-23T17:30:38Z</dc:date>
    <item>
      <title>How to install local app via rest API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-install-local-app-via-rest-API/m-p/653648#M110864</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Hi All, trying to install an app I have locally via API.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;I have tried both curl command and python script&lt;/P&gt;
&lt;P&gt;Curl Command:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;curl -k -u admin:YOUR_SPLUNK_PASSWORD \ -X POST &lt;A class="" title="https://your_splunk_host:8089/services/apps/local" href="https://YOUR_SPLUNK_HOST:8089/services/apps/local" target="_blank" rel="noreferrer noopener"&gt;https://YOUR_SPLUNK_HOST:8089/services/apps/local&lt;/A&gt; \ -H &lt;SPAN class=""&gt;"Content-Type: multipart/form-data"&lt;/SPAN&gt; \ -F &lt;SPAN class=""&gt;"name=appname"&lt;/SPAN&gt; \ -F &lt;SPAN class=""&gt;"appfile=@/path/to/your/app_package.tar.gz"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;The error I get is the following:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&amp;lt;msg type="ERROR"&amp;gt;Error during app install: failed to extract app from app_package.tar.gz to /opt/splunk/var/run/splunk/bundle_tmp/7391c87f2a023fd5: No such file or directory&amp;lt;/msg&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Python script:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;import splunklib.client as client&lt;BR /&gt;import splunklib.results as results&lt;BR /&gt;import requests&lt;/P&gt;
&lt;P&gt;# Splunk server details&lt;BR /&gt;splunk_host = 'hostname'&lt;BR /&gt;splunk_port = 8089&lt;BR /&gt;splunk_username = 'splunk_user'&lt;BR /&gt;splunk_password = 'splunk_password'&lt;/P&gt;
&lt;P&gt;# App installation details&lt;BR /&gt;app_package_path = '/path/to/custom_app.tgz'&lt;BR /&gt;app_name = 'custom_app'&lt;/P&gt;
&lt;P&gt;# Connect to Splunk&lt;BR /&gt;service = client.connect(&lt;BR /&gt;host=splunk_host,&lt;BR /&gt;port=splunk_port,&lt;BR /&gt;username=splunk_username,&lt;BR /&gt;password=splunk_password&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;# Install the app&lt;BR /&gt;try:&lt;BR /&gt;endpoint = f'/services/apps/local'&lt;BR /&gt;headers = {'Authorization': f'Splunk {service.token}'}&lt;BR /&gt;files = {'app_package': open(app_package_path, 'rb')}&lt;BR /&gt;data = {'app': app_name}&lt;/P&gt;
&lt;P&gt;app_response = requests.post(&lt;BR /&gt;f'https://{splunk_host}:{splunk_port}{endpoint}',&lt;BR /&gt;headers=headers,&lt;BR /&gt;files=files,&lt;BR /&gt;data=data,&lt;BR /&gt;verify=False # Disabling SSL certificate verification (for self-signed certificates)&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;app_status = app_response.status_code&lt;/P&gt;
&lt;P&gt;if app_status == 200:&lt;BR /&gt;print(f"App '{app_name}' was successfully installed.")&lt;BR /&gt;else:&lt;BR /&gt;print(f"Failed to install app '{app_name}'. Status code: {app_status}")&lt;/P&gt;
&lt;P&gt;except Exception as e:&lt;BR /&gt;print(f"An error occurred: {str(e)}")&lt;/P&gt;
&lt;P&gt;# Disconnect from Splunk&lt;BR /&gt;service.logout()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error I get:&lt;/P&gt;
&lt;P&gt;/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1015: InsecureRequestWarning: Unverified HTTPS request is being made to host '127.0.0.1'. Adding certificate verification is strongly advised. See: &lt;A href="https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings" target="_blank" rel="noopener"&gt;https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings&lt;/A&gt;&lt;BR /&gt;warnings.warn(&lt;BR /&gt;Failed to install app 'custom_app'. Status code: 400&lt;/P&gt;
&lt;P&gt;In both cases, I have confirmed that I am able to connect and query Splunk, so there shouldn't be any connectivity issues. I have also confirmed that I can manually install the app so there shouldn't be any issues with the tgz file.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 16:26:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-install-local-app-via-rest-API/m-p/653648#M110864</guid>
      <dc:creator>kenchansan</dc:creator>
      <dc:date>2023-08-09T16:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to install local app via rest API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-install-local-app-via-rest-API/m-p/655393#M111045</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;local installation means that app package must be on splunk server not on you local workstation. See old &lt;A href="https://community.splunk.com/t5/Getting-Data-In/REST-API-Install-local-App/m-p/354279" target="_blank"&gt;post&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;r. Ismo&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 17:30:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-install-local-app-via-rest-API/m-p/655393#M111045</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2023-08-23T17:30:38Z</dc:date>
    </item>
  </channel>
</rss>

