Beispiel #1
0
    def test_get_preview_and_events(self):
        self.assertEventuallyTrue(self.job.is_done)
        self.assertLessEqual(int(self.job['eventCount']), 3)

        preview_stream = self.job.preview(output_mode='json')
        preview_r = results.JSONResultsReader(preview_stream)
        self.assertFalse(preview_r.is_preview)

        events_stream = self.job.events(output_mode='json')
        events_r = results.JSONResultsReader(events_stream)

        n_events = len([x for x in events_r if isinstance(x, dict)])
        n_preview = len([x for x in preview_r if isinstance(x, dict)])
        self.assertEqual(n_events, n_preview)
Beispiel #2
0
 def test_export(self):
     jobs = self.service.jobs
     stream = jobs.export("search index=_internal earliest=-1m | head 3",
                          output_mode='json')
     result = results.JSONResultsReader(stream)
     ds = list(result)
     self.assertEqual(result.is_preview, False)
     self.assertTrue(isinstance(ds[0], dict) or \
                         isinstance(ds[0], results.Message))
     nonmessages = [d for d in ds if isinstance(d, dict)]
     self.assertTrue(len(nonmessages) <= 3)
Beispiel #3
0
 def test_read_from_empty_result_set(self):
     job = self.service.jobs.create(
         "search index=_internal_does_not_exist | head 2")
     while not job.is_done():
         sleep(0.5)
     self.assertEqual(
         0,
         len(
             list(
                 results.JSONResultsReader(
                     io.BufferedReader(job.results(output_mode='json'))))))
Beispiel #4
0
 def test_export_docstring_sample(self):
     import splunklib.client as client
     import splunklib.results as results
     service = self.service  # cheat
     rr = results.JSONResultsReader(
         service.jobs.export("search * | head 5", output_mode='json'))
     for result in rr:
         if isinstance(result, results.Message):
             # Diagnostic messages may be returned in the results
             pass  #print '%s: %s' % (result.type, result.message)
         elif isinstance(result, dict):
             # Normal events are returned as dicts
             pass  #print result
     assert rr.is_preview == False
Beispiel #5
0
    def test_v1_job_fallback(self):
        self.assertEventuallyTrue(self.job.is_done)
        self.assertLessEqual(int(self.job['eventCount']), 3)

        preview_stream = self.job.preview(output_mode='json',
                                          search='| head 1')
        preview_r = results.JSONResultsReader(preview_stream)
        self.assertFalse(preview_r.is_preview)

        events_stream = self.job.events(output_mode='json', search='| head 1')
        events_r = results.JSONResultsReader(events_stream)

        results_stream = self.job.results(output_mode='json',
                                          search='| head 1')
        results_r = results.JSONResultsReader(results_stream)

        n_events = len([x for x in events_r if isinstance(x, dict)])
        n_preview = len([x for x in preview_r if isinstance(x, dict)])
        n_results = len([x for x in results_r if isinstance(x, dict)])

        # Fallback test for Splunk Version 9+
        if self.service.splunk_version[0] >= 9:
            self.assertGreaterEqual(9, self.service.splunk_version[0])
        self.assertEqual(n_events, n_preview, n_results)
Beispiel #6
0
 def test_results_docstring_sample(self):
     import splunklib.results as results
     service = self.service  # cheat
     job = service.jobs.create("search * | head 5")
     while not job.is_done():
         sleep(0.2)
     rr = results.JSONResultsReader(job.results(output_mode='json'))
     for result in rr:
         if isinstance(result, results.Message):
             # Diagnostic messages may be returned in the results
             pass  #print '%s: %s' % (result.type, result.message)
         elif isinstance(result, dict):
             # Normal events are returned as dicts
             pass  #print result
     assert rr.is_preview == False
Beispiel #7
0
 def test_preview_docstring_sample(self):
     import splunklib.client as client
     import splunklib.results as results
     service = self.service  # cheat
     job = service.jobs.create("search * | head 5")
     rr = results.JSONResultsReader(job.preview(output_mode='json'))
     for result in rr:
         if isinstance(result, results.Message):
             # Diagnostic messages may be returned in the results
             pass  #print '%s: %s' % (result.type, result.message)
         elif isinstance(result, dict):
             # Normal events are returned as dicts
             pass  #print result
     if rr.is_preview:
         pass  #print "Preview of a running search job."
     else:
         pass  #print "Job is finished. Results are final."