Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Faircloth committed Jun 30, 2019
1 parent 13b93fb commit 4e16448
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
14 changes: 2 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ dmypy.json
*.bak
*.gho
*.ori
*.orig
*.tmp

### Windows template
Expand Down Expand Up @@ -202,7 +201,6 @@ export_presets.cfg
*.bz2
*.xz
*.lzma
*.cab

# Packing-only formats
*.iso
Expand All @@ -212,15 +210,10 @@ export_presets.cfg
*.dmg
*.xpi
*.gem
*.egg
*.deb
*.rpm
*.msi
*.msm
*.msp

### Patch template
*.orig
*.rej

### macOS template
Expand Down Expand Up @@ -256,7 +249,6 @@ Temporary Items
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
Expand All @@ -271,15 +263,13 @@ Temporary Items
### VirtualEnv template
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
.venv
pip-selfcheck.json

### PuTTY template
Expand All @@ -305,6 +295,6 @@ tags
# Persistent undo
[._]*.un~

/.env
/test-results
/.idea
/.idea/workspace.xml
/.idea/tasks.xml
38 changes: 17 additions & 21 deletions tests/test_poc.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
from jinja2 import Environment
import urllib.request

import random

import socket

import sys
from time import sleep
import splunklib.results as results
import splunklib.client as client
import urllib.request
from time import sleep

import pytest
import splunklib.client as client
from jinja2 import Environment

env = Environment(extensions=['jinja2_time.TimeExtension'])


@pytest.fixture
def setup_wordlist():

word_url = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain"
response = urllib.request.urlopen(word_url)
long_txt = response.read().decode()
return long_txt.splitlines()


@pytest.fixture
def setup_splunk():
tried=0
tried = 0
while True:
try:
c = client.connect(username="admin", password="Changed@11", host="splunk", port="8089")
break
except ConnectionRefusedError:
tried +=1
if tried>90:
tried += 1
if tried > 90:
raise
sleep(1)
return c


def sendsingle(message):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('sc4s', 514)
Expand All @@ -46,14 +43,15 @@ def sendsingle(message):
sock.connect(server_address)
break
except:
tried +=1
tried += 1
if tried > 90:
raise
sleep(1)
sock.sendall(str.encode(message))
sock.close()

def splunk_single(service,search):

def splunk_single(service, search):
kwargs_normalsearch = {"exec_mode": "normal"}
tried = 0
while True:
Expand All @@ -76,31 +74,29 @@ def splunk_single(service,search):
# Get the results and display them
resultCount = stats["resultCount"]
eventCount = stats["eventCount"]
if resultCount > 0 or tried>15:
if resultCount > 0 or tried > 15:
break
else:
tried += 1
sleep(1)
return resultCount, eventCount


def test_defaultroute(record_property,setup_wordlist,setup_splunk):
def test_defaultroute(record_property, setup_wordlist, setup_splunk):
host = "{}-{}".format(random.choice(setup_wordlist), random.choice(setup_wordlist))

mt = env.from_string("{{ mark }} {% now 'utc', '%b %d %H:%M:%S' %}.000z {{ host }} sc4s_default[0]: test\n")
message = mt.render(mark="<111>1", host=host)

sendsingle(message)

st= env.from_string("search \"{{ host }}\" | head 2")
st = env.from_string("search \"{{ host }}\" | head 2")
search = st.render(host=host)

resultCount, eventCount = splunk_single(setup_splunk,search)
resultCount, eventCount = splunk_single(setup_splunk, search)

record_property("host", host)
record_property("resultCount", resultCount)
record_property("message", message)

assert resultCount == 1


0 comments on commit 4e16448

Please sign in to comment.