From 6adc21e872fa521be1aaf08309f7f3d0ba3dc5c5 Mon Sep 17 00:00:00 2001 From: Spain Date: Tue, 17 Apr 2018 17:36:00 -0400 Subject: [PATCH] feat(tags): Allow tags to be configured - New option `tags` to define logdna host tags --- README.md | 9 +++++++++ logdna/logdna.py | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 786481d..e9386ce 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,15 @@ The default level passed along with every log sent through this instance. By default the line has a maximum length of 16000 chars, this can be turned off with the value false. +##### tags + +* _Optional_ +* Type: `String[]` +* Default: `[]` + +List of tags used to dynamically group hosts. More information on tags is available at [How Do I Use Host Tags?](https://docs.logdna.com/docs/logdna-agent#section-how-do-i-use-host-tags-) + + ### log(line, [options]) --- #### line diff --git a/logdna/logdna.py b/logdna/logdna.py index 1bb3bc9..7d37099 100644 --- a/logdna/logdna.py +++ b/logdna/logdna.py @@ -23,6 +23,9 @@ def __init__(self, key, options={}): self.env = options['env'] if 'env' in options else '' self.setLevel(logging.DEBUG) + self.tags = [] + if 'tags' in options and isinstance(options['tags'], list): + self.tags.extend(options['tags']) self.max_length = True if 'max_length' in options: self.max_length = options['max_length'] @@ -71,7 +74,17 @@ def flush(self): self.flusher = Timer(defaults['FLUSH_NOW'], self.flush) self.flusher.start() else: - resp = requests.post(url=defaults['LOGDNA_URL'], json=data, auth=('user', self.key), params={ 'hostname': self.hostname, 'ip': self.ip, 'mac': self.mac if self.mac else None }, stream=True, timeout=defaults['MAX_REQUEST_TIMEOUT']) + resp = requests.post( + url=defaults['LOGDNA_URL'], + json=data, + auth=('user', self.key), + params={ + 'hostname': self.hostname, + 'ip': self.ip, + 'mac': self.mac if self.mac else None, + 'tags': self.tags if self.tags else None}, + stream=True, + timeout=defaults['MAX_REQUEST_TIMEOUT']) self.buf = [] self.bufByteLength = 0 if self.flusher: