<?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: Splunk6 Django app -- Importing SQLite in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125195#M1816</link>
    <description>&lt;P&gt;Glad to see you got it working, but I wanted to caution against this, for a couple of reasons:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;settings.py&lt;/CODE&gt; may be overridden during upgrades, which may remove your database&lt;BR /&gt;
definition.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;The Python libraries directories may also be overridden, which will remove the&lt;BR /&gt;
DB drivers.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;As a general concern, you may have some trouble with a Search Head Pooling scenario, but that&lt;BR /&gt;
may not be an issue for you.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Overall, I completely understand that this is a great feature to have, but I wanted to be honest that it may not be the best approach at the moment. It is something we are looking at enabling.&lt;/P&gt;</description>
    <pubDate>Fri, 01 Nov 2013 18:43:52 GMT</pubDate>
    <dc:creator>mgroves_splunk</dc:creator>
    <dc:date>2013-11-01T18:43:52Z</dc:date>
    <item>
      <title>Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125190#M1811</link>
      <description>&lt;P&gt;Hey Splunk Gurus, &lt;/P&gt;

&lt;P&gt;I'm writing a Splunk 6 app, and need the ability to persist settings.  I did a simple mock-up writing/reading JSON to a file, but now I want to use SQLite. &lt;/P&gt;

&lt;P&gt;The problem comes when I go to import sqlite in python:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;/myapp/django/myapp/views.py:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;from django.contrib.auth.decorators import login_required
from splunkdj.decorators.render import render_to
from django.shortcuts import render

# Add various modules that we'll use in this app
import logging
import sqlite3
import sys
import json    
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The error that I get is: "global name 'sqlite3' is not defined"&lt;/P&gt;

&lt;P&gt;Ok, so I try moving the import down into my def, now the exception is "No module named sqlite3"&lt;/P&gt;

&lt;P&gt;Inside myapp, I did a "logger.debug(sys.path)" and can see it's pointing to /opt/splunk/lib/python2.7/&lt;/P&gt;

&lt;P&gt;After some digging, I realized that there is no "/opt/splunk/lib/python2.7/lib-dynload/_sqlite3.so". I assume this is because Splunk uses a custom-compiled python and omits it. I tried copying a compatible _sqlite3.so but that didn't work. &lt;/P&gt;

&lt;P&gt;So what's going on here? All I want to do is create a little table, insert a few rows, and query the settings back out. I know Splunk uses SQLite already -- I just have no idea how to access it. &lt;/P&gt;

&lt;P&gt;I started playing around with settings.py: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'mydatabase',
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but could not get that working either. I'm a little new to Django, so at this moment I'm stuck. Can anyone give me a hand?&lt;/P&gt;

&lt;P&gt;Thanks! &lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2013 22:56:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125190#M1811</guid>
      <dc:creator>joshuamcqueen</dc:creator>
      <dc:date>2013-10-31T22:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125191#M1812</link>
      <description>&lt;P&gt;Splunk includes the Python SQLite libraries but not the C libraries. Thus, you won't be able to use the Python to connect to SQLite, sadly.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2013 00:35:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125191#M1812</guid>
      <dc:creator>LukeMurphey</dc:creator>
      <dc:date>2013-11-01T00:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125192#M1813</link>
      <description>&lt;P&gt;I GOT IT WORKING!! &lt;/P&gt;

&lt;P&gt;After about 8 hours of messing around here's what I did:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;copy the _sqlite3.so from /usr/lib64/python2.6/lib-dynload/_sqlite3.so to /opt/splunk/lib/python2.7/lib-dynload/&lt;/LI&gt;
&lt;LI&gt;chmod and chown it appropriately&lt;/LI&gt;
&lt;LI&gt;restart Splunk&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Volia!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:10:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125192#M1813</guid>
      <dc:creator>joshuamcqueen</dc:creator>
      <dc:date>2020-09-28T15:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125193#M1814</link>
      <description>&lt;P&gt;Nice! Let us know once you have been using it for a while. I have heard that the sqlite libs could cause reliability problems but I have never seen direct evidence of this (just hearsay).&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2013 01:58:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125193#M1814</guid>
      <dc:creator>LukeMurphey</dc:creator>
      <dc:date>2013-11-01T01:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125194#M1815</link>
      <description>&lt;P&gt;So far it works great -- there are a few got'chas with python syntax, but otherwise working well. The app does basic CRUD with 200+ users. I'll post a full blog post with code sooner-than-later&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2013 14:44:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125194#M1815</guid>
      <dc:creator>joshuamcqueen</dc:creator>
      <dc:date>2013-11-01T14:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125195#M1816</link>
      <description>&lt;P&gt;Glad to see you got it working, but I wanted to caution against this, for a couple of reasons:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;settings.py&lt;/CODE&gt; may be overridden during upgrades, which may remove your database&lt;BR /&gt;
definition.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;The Python libraries directories may also be overridden, which will remove the&lt;BR /&gt;
DB drivers.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;As a general concern, you may have some trouble with a Search Head Pooling scenario, but that&lt;BR /&gt;
may not be an issue for you.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Overall, I completely understand that this is a great feature to have, but I wanted to be honest that it may not be the best approach at the moment. It is something we are looking at enabling.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2013 18:43:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125195#M1816</guid>
      <dc:creator>mgroves_splunk</dc:creator>
      <dc:date>2013-11-01T18:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125196#M1817</link>
      <description>&lt;P&gt;@joshuamcqueen Are you certain that copying the sqlite3 SO was the only thing you needed to do? I tried it and had no luck whatsoever. I even downloaded the Python 2.7.5 source and compiled it to get the same SO as the Splunk version of Python would expect. No luck. &lt;/P&gt;

&lt;P&gt;I'm a little frustrated that we get access to Django, but no access to databases. I guess I'll just write JSON files to the file system.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2013 16:00:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125196#M1817</guid>
      <dc:creator>tysonstewart</dc:creator>
      <dc:date>2013-12-04T16:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125197#M1818</link>
      <description>&lt;P&gt;@tysonstewart -- Let me go back and double check. I'm almost positive. HOWEVER, I tried to port this app over to a Windows search head and could not get it working. &lt;/P&gt;

&lt;P&gt;I have been meaning to do a screencast / blog writeup of this project. If you can wait a week I'll give you a full write up. I'll post it to this thread.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2013 16:31:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125197#M1818</guid>
      <dc:creator>joshuamcqueen</dc:creator>
      <dc:date>2013-12-04T16:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125198#M1819</link>
      <description>&lt;P&gt;@joshuamcqueen I got it working. There was a conflict around character encoding, and I also had to reference the sqlite3 modules in my external Python directory because my Splunk installation is missing the dbapi2 module. &lt;/P&gt;

&lt;P&gt;I thought I would mention that I used a module in my app to add to the sys.path so that it could find the sqlite modules, and alter the DATABASES setting so that the default Splunk application doesn't have to be modified. If you want to know more for your blog post, let me know. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2013 23:17:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125198#M1819</guid>
      <dc:creator>tysonstewart</dc:creator>
      <dc:date>2013-12-05T23:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125199#M1820</link>
      <description>&lt;P&gt;I had some similar experience when trying to use SQLITE3 inside a Python Lookup script.&lt;/P&gt;

&lt;P&gt;I tried the copying method from the OS Python (RHEL 6.5) but it was returning some weird results from SQLITE, like partial string and things like that.&lt;/P&gt;

&lt;P&gt;My solution was:&lt;BR /&gt;&lt;BR /&gt;
 1. Install RedHat Package Sqlite3-Dev&lt;BR /&gt;&lt;BR /&gt;
 2. Download the Python 2.7.7 Source&lt;BR /&gt;&lt;BR /&gt;
 3. Compile it using "./configure --prefix=/home/splunk/local"&lt;BR /&gt;&lt;BR /&gt;
 4. Finally copy the "sqlite3" folder and "lib-dynload/_sqlite3.so" from my freshly compiled Python to the Splunk/lib/python2.7 folder&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;My guess is that the sqlite3 python package from OS was built using python 2.6 and Splunk runs python 2.7 so some incompatibility there caused it.&lt;/P&gt;

&lt;P&gt;I think it would work with other modules as well.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jun 2014 22:30:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125199#M1820</guid>
      <dc:creator>musskopf</dc:creator>
      <dc:date>2014-06-23T22:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk6 Django app -- Importing SQLite</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125200#M1821</link>
      <description>&lt;P&gt;@joshuamcqueen, Any chance for you to put as a blog? Also is it not possible to put sqlite files in an app?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Aug 2014 11:09:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk6-Django-app-Importing-SQLite/m-p/125200#M1821</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2014-08-11T11:09:47Z</dc:date>
    </item>
  </channel>
</rss>

