Created
July 31, 2017 23:39
-
-
Save NickStallman/a5734e0c39a0957bc1e37223f929e1b7 to your computer and use it in GitHub Desktop.
DataDog Log Parser for Pure-FTPd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from datetime import datetime | |
def parse_pureftpd(logger, line): | |
# Split the line into fields | |
time, unique, username, ip, direction, bytes, duration, filename = line.split(' ') | |
attr_dict = {"username": username, "metric_type": "counter"} | |
return ('pure-ftpd.uploads', time, 1, attr_dict) | |
def test(): | |
# Set up the test logger | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
# Set up the test input and expected output | |
test_input = "1501543805 597fbd74.3b84 testaccount 1.2.3.4 U 12 0 /var/ftp/testaccount/test.xml" | |
expected = ( | |
"pure-ftpd.uploads", | |
"1501543805", | |
1, | |
{"username": "testaccount", | |
"metric_type": "counter" } | |
) | |
# Call the parse function | |
actual = parse_pureftpd(logging, test_input) | |
# Validate the results | |
assert expected == actual, "%s != %s" % (expected, actual) | |
print 'test passes' | |
if __name__ == '__main__': | |
# For local testing, callable as "python /path/to/parsers.py" | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment