-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use last valid host name when next event is incomplete
New feature flag. Enables a kv store feature to cache the last host name from a SOURCEIP and use that value if a following event has null, nill or ip rather than host name. Local storage uses sqllite
- Loading branch information
Ryan Faircloth
authored
Mar 16, 2022
1 parent
2574e07
commit 5971773
Showing
16 changed files
with
190 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Current Experimental Features | ||
|
||
# > 2.13.0 | ||
|
||
* In env_file set `SC4S_USE_NAME_CACHE=yes` to enable caching last valid host string and replacing nill, null, or ipv4 with last good value. | ||
- Benefit: More correct host name values in Splunk when source vendor fails to provide valid syslog message | ||
- Risk: Potential disk I/O usage (space, iops) Potential reduction in throughput when a high proportion of events are incomplete. |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
destination d_psc { | ||
python( | ||
class("parser_source_cache.psc_dest") | ||
batch-timeout(3000) | ||
batch-lines(100) | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
log { | ||
if { | ||
filter(f_host_is_nil_or_ip); | ||
} else { | ||
destination(d_psc); | ||
}; | ||
flags(catchall); | ||
}; |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
import sys | ||
import traceback | ||
import socket | ||
import struct | ||
from sqlitedict import SqliteDict | ||
|
||
import time | ||
try: | ||
import syslogng | ||
except: | ||
pass | ||
|
||
|
||
def ip2int(addr): | ||
return struct.unpack("!I", socket.inet_aton(addr))[0] | ||
|
||
def int2ip(addr): | ||
return socket.inet_ntoa(struct.pack("!I", addr)) | ||
|
||
hostdict = str("/var/lib/syslog-ng/hostip") | ||
|
||
class psc_parse(object): | ||
def init(self, options): | ||
self.logger = syslogng.Logger() | ||
self.db = SqliteDict(f"{hostdict}.sqlite") | ||
return True | ||
|
||
def deinit(self): | ||
self.db.close() | ||
|
||
def parse(self, log_message): | ||
try: | ||
ipaddr = log_message["SOURCEIP"].decode("utf-8") | ||
ip_int = ip2int(ipaddr) | ||
self.logger.debug(f'psc.parse sourceip={ipaddr} int={ip_int}') | ||
name = self.db[ip_int] | ||
self.logger.debug(f'psc.parse host={name}') | ||
log_message["HOST"]=name | ||
|
||
except: | ||
exc_type, exc_value, exc_traceback = sys.exc_info() | ||
lines = traceback.format_exception(exc_type, exc_value, exc_traceback) | ||
self.logger.debug(''.join('!! ' + line for line in lines)) | ||
return False | ||
self.logger.debug(f'psc.parse complete') | ||
return True | ||
|
||
class psc_dest(object): | ||
def init(self, options): | ||
self.logger = syslogng.Logger() | ||
try: | ||
self.db = SqliteDict(f"{hostdict}.sqlite",autocommit=True) | ||
except: | ||
exc_type, exc_value, exc_traceback = sys.exc_info() | ||
lines = traceback.format_exception(exc_type, exc_value, exc_traceback) | ||
self.logger.debug(''.join('!! ' + line for line in lines)) | ||
return False | ||
return True | ||
|
||
def deinit(self): | ||
"""Close the connection to the target service""" | ||
self.db.commit() | ||
self.db.close() | ||
|
||
def send(self, log_message): | ||
try: | ||
ipaddr = log_message["SOURCEIP"].decode("utf-8") | ||
ip_int = ip2int(ipaddr) | ||
self.logger.debug(f'psc.send sourceip={ipaddr} int={ip_int} host={log_message["HOST"]}') | ||
if ip_int in self.db: | ||
current = self.db[ip_int] | ||
if current != log_message["HOST"]: | ||
self.db[ip_int] =log_message["HOST"] | ||
else: | ||
self.db[ip_int] =log_message["HOST"] | ||
|
||
except: | ||
exc_type, exc_value, exc_traceback = sys.exc_info() | ||
lines = traceback.format_exception(exc_type, exc_value, exc_traceback) | ||
self.logger.debug(''.join('!! ' + line for line in lines)) | ||
return False | ||
self.logger.debug('psc.send complete') | ||
return True | ||
|
||
def flush(self): | ||
self.db.commit() | ||
|
||
if __name__ == "__main__": | ||
db = SqliteDict(f"{hostdict}.sqlite",autocommit=True) | ||
db[0]="seed" | ||
db.commit() | ||
db.close() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
import sys | ||
import traceback | ||
import socket | ||
import struct | ||
from sqlitedict import SqliteDict | ||
|
||
|
||
hostdict = str("/var/lib/syslog-ng/cache/hostip") | ||
db = SqliteDict(f"{hostdict}.sqlite") | ||
|
||
for k,v in db.items(): | ||
print(f"key={k}={v}") |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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