Hey Splunk Gurus,
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.
The problem comes when I go to import sqlite in python:
/myapp/django/myapp/views.py:
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
The error that I get is: "global name 'sqlite3' is not defined"
Ok, so I try moving the import down into my def, now the exception is "No module named sqlite3"
Inside myapp, I did a "logger.debug(sys.path)" and can see it's pointing to /opt/splunk/lib/python2.7/
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.
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.
I started playing around with settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase',
}
}
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?
Thanks!
I GOT IT WORKING!!
After about 8 hours of messing around here's what I did:
Volia!