You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.6 KiB
59 lines
1.6 KiB
# Needed to use PSC build
|
|
import exec_anaconda
|
|
|
|
exec_anaconda.exec_anaconda_or_die()
|
|
|
|
# Needed to import libraries in /lib folder
|
|
import sys, os
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
|
|
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option
|
|
from splunklib.client import connect
|
|
from splunklib.binding import handler
|
|
|
|
import setup_logging
|
|
|
|
logger = setup_logging.get_logger()
|
|
|
|
|
|
@Configuration()
|
|
class SPLGenFeedbackCommand(GeneratingCommand):
|
|
"""
|
|
Generating command that submit feedback information
|
|
"""
|
|
|
|
sessionId = Option(require=True)
|
|
# Required plain English description of a query
|
|
prompt = Option(require=True)
|
|
# Required returned query string
|
|
response = Option(require=True)
|
|
# Required correct/incorrect boolean
|
|
correct = Option(require=True)
|
|
|
|
def generate(self):
|
|
try:
|
|
service = connect(
|
|
token=self._metadata.searchinfo.session_key,
|
|
handler=handler(timeout=1),
|
|
host="127.0.0.1",
|
|
)
|
|
except Exception as e:
|
|
service = None
|
|
|
|
# Retrieve the index for the data
|
|
feedback_indx = service.indexes["splgen_fb"]
|
|
|
|
# Submit an event over HTTP
|
|
feedback_indx.submit(
|
|
f"session_id='{self.sessionId}' query='{self.prompt}',response='{self.response}',correct={self.correct}",
|
|
sourcetype="splgen_feedback",
|
|
host="local",
|
|
)
|
|
|
|
yield self.gen_record(
|
|
query=self.prompt, response=self.response, correct=self.correct
|
|
)
|
|
|
|
|
|
dispatch(command_class=SPLGenFeedbackCommand)
|