Skip to content

Commit 7f31087

Browse files
author
Worvast
authored
Merge pull request #5 from Worvast/master
Use new version of sender and fixes in CLI
2 parents 32f76cf + 87e752b commit 7f31087

File tree

13 files changed

+75
-59
lines changed

13 files changed

+75
-59
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [2.0.0] - 2019-07-02
8+
#### Changed
9+
* Modified base devo-sender from version 2.x to >=3.0.1
10+
* Faker cli for adapt to new devo-sdk config files
11+
12+
#### Fixed
13+
* Problems with Sender raw sender in CLI removing tag
14+
* Problems with call key when can not exists
15+
716
## [1.0.2] - 2019-04-24
817
#### Security
918
* Updated requirements for high problems of security

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ changes have been made between each release (or version) of the project.
4848

4949
##### Why should I care?
5050
Because software tools are for people. If you don’t care, why are you
51-
contributing? Right, Logtrust pay you for it, but surely, there must be a kernel
51+
contributing? Right, Devo maybe pay you for it, but surely, there must be a kernel
5252
(ha!) of care somewhere in that lovely little brain of yours.
5353

5454
##### What makes a good change log?

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![relese-next Build Status](https://travis-ci.com/DevoInc/python-utils.svg?branch=master)](https://travis-ci.com/DevoInc/python-utils) [![LICENSE](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/DevoInc/python-utils/blob/master/LICENSE)
22

3-
[![wheel](https://img.shields.io/badge/wheel-yes-brightgreen.svg)](https://pypi.org/project/devo-utils/) [![version](https://img.shields.io/badge/version-1.0.2-blue.svg)](https://pypi.org/project/devo-utils/) [![python](https://img.shields.io/badge/python-3.3%20%7C%203.4%20%7C%203.5%20%7C%203.6%20%7C%203.7-blue.svg)](https://pypi.org/project/devo-utils/)
3+
[![wheel](https://img.shields.io/badge/wheel-yes-brightgreen.svg)](https://pypi.org/project/devo-utils/) [![version](https://img.shields.io/badge/version-2.0.1-blue.svg)](https://pypi.org/project/devo-utils/) [![python](https://img.shields.io/badge/python-3.5%20%7C%203.6%20%7C%203.7-blue.svg)](https://pypi.org/project/devo-utils/)
44

55

66
# Devo Python Utils

devoutils/__version__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__description__ = 'Devo Python Library.'
22
__url__ = 'http://www.devo.com'
3-
__version__ = "1.0.2"
3+
__version__ = "2.0.1"
44
__author__ = 'Devo'
55
__author_email__ = 'support@devo.com'
66
__license__ = 'MIT'
7-
__copyright__ = 'Copyright 2018 Devo'
7+
__copyright__ = 'Copyright 2019 Devo'

devoutils/faker/scripts/faker_cli.py

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def cli():
3131
help='Chain file for SSL.')
3232
@click.option('--address', help='address to send.')
3333
@click.option('--port', help='Port to send.')
34-
@click.option('--tag', help='Tag from Logtrust.')
34+
@click.option('--tag', help='Tag from Devo.')
3535
@click.option('--simulation', is_flag=True, help='Set as simulation.')
3636
@click.option('--template', '-t', type=click.File('r'), required=True,
3737
help='Template to send.')
@@ -40,8 +40,9 @@ def cli():
4040
@click.option('--raw_mode', '-raw', is_flag=True,
4141
help='Send raw mode.')
4242
@click.option('--prob', default=100, help='Probability (0-100).')
43-
@click.option('--freq', default="1-1", help='Frequency in seconds '
44-
'("1.0-5.0": 1 sec. to 5secs.).')
43+
@click.option('--freq', default="1-1", help='Frequency in seconds. Example:'
44+
'"1.0-5.0" = random time '
45+
'between 1 sec. to 5secs.')
4546
@click.option('--batch_mode', is_flag=True,
4647
help='Enable blatch mode, a lot of events will be generated as '
4748
'fast as possible and written to a file. The events will be '
@@ -88,21 +89,26 @@ def cli(**kwargs):
8889
freq=cfg['freq'], date_format=cfg['date_format'],
8990
dont_remove_microseconds=cfg['dont_remove_microseconds'])
9091
elif cfg['raw_mode']:
91-
scfg = cfg['logtrust']
92-
params.append('Host={0}:{1}'.format(scfg['address'], scfg['port']))
93-
params.append('Tag={0}'.format(cfg['tag']))
94-
thread = SyslogRawSender(engine, cfg['template'],
92+
scfg = cfg['sender']
93+
params.append('Host={0}:{1}'.format(scfg.get('address', None),
94+
scfg.get("port", None)))
95+
thread = SyslogRawSender(engine, cfg.get('template', None),
9596
interactive=cfg['interactive'],
96-
prob=cfg['prob'], freq=cfg['freq'],
97-
tag=cfg['tag'])
97+
prob=cfg['prob'], freq=cfg['freq'])
9898
else:
99-
scfg = cfg['logtrust']
100-
params.append('Host={0}:{1}'.format(scfg['address'], scfg['port']))
101-
params.append('Tag={0}'.format(cfg['tag']))
99+
scfg = cfg['sender']
100+
params.append('Host={0}:{1}'.format(scfg.get('address', None),
101+
scfg.get("port", None)))
102+
params.append('Tag={0}'.format(cfg.get('tag',
103+
scfg.get("tag",
104+
"my.app.faker.test")
105+
)
106+
)
107+
)
102108
thread = SyslogSender(engine, cfg['template'],
103109
interactive=cfg['interactive'],
104110
prob=cfg['prob'], freq=cfg['freq'],
105-
tag=cfg['tag'])
111+
tag=cfg.get('tag', "my.app.faker.test"))
106112

107113
params.append('Prob={0}'.format(cfg['prob']))
108114
params.append('Freq={0}'.format(cfg['freq']))
@@ -127,39 +133,37 @@ def cli(**kwargs):
127133

128134
def configure(args):
129135
"""For load configuration file/object"""
130-
config = Configuration()
136+
131137
if args.get('config'):
132-
config.load_config(args.get('config'))
133-
config.mix(dict(args))
138+
config = Configuration(args.get('config'))
139+
config.mix(dict(args))
140+
else:
141+
config = dict(args)
134142

135-
if 'freq' in config.cfg:
136-
parts = config.cfg['freq'].split('-')
137-
config.cfg['freq'] = (float(parts[0]), float(parts[1]))
143+
if 'freq' in config.keys():
144+
parts = config['freq'].split('-')
145+
config['freq'] = (float(parts[0]), float(parts[1]))
138146

139-
config.cfg['template'] = config.cfg['template'].read()
147+
config['template'] = config['template'].read()
140148

141149
# Initialize LtSender with the config credentials but only
142150
# if we aren't in batch mode or simulation mode
143151
engine = None
144-
if not (config.cfg['batch_mode'] or config.cfg['simulation']):
152+
if not (config['batch_mode'] or config['simulation']):
145153
try:
146-
if 'sender' in config.cfg:
147-
engine = Sender.from_config(config.get()['sender'])
148-
else:
149-
config.cfg['sender'] = {
150-
'key' : config.cfg['key'],
151-
'chain' : config.cfg['chain'],
152-
'cert' : config.cfg['cert'],
153-
'address' : config.cfg['address'],
154-
'port' : config.cfg['port']
155-
}
156-
engine = Sender.from_config(config.cfg)
154+
if "sender" not in config.keys():
155+
config['sender'] = {'key': config.get('key', None),
156+
'chain': config.get('chain', None),
157+
'cert': config.get('cert', None),
158+
'address': config.get('address', None),
159+
'port': config.get('port', 443)}
160+
161+
engine = Sender(config=config.get('sender'))
157162
except Exception as error:
158163
print_error(error, show_help=False)
159164
print_error("Error when loading devo sender configuration",
160165
show_help=True)
161-
162-
return engine, config.get()
166+
return engine, config
163167

164168

165169
def print_error(error, show_help=False, stop=True):

devoutils/faker/senders/base_sender.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(self, engine, template, **kwargs):
2525
self.dont_remove_microseconds = kwargs.get('dont_remove_microseconds',
2626
False)
2727
self.parser = TemplateParser()
28+
self.date_generator = kwargs.get('date_generator', None)
2829

2930
def process(self, date_generator=None, **kwargs):
3031
"""Process template"""

devoutils/faker/senders/batch_sender.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ def date_range(start_date, end_date, freq, prob,
2727
date_format="%Y-%m-%d %H:%M:%S.%f",
2828
dont_remove_microseconds=True):
2929
"""
30-
Generates datetime objects between a start date and an end date with
30+
Generates dateti
31+
:param start_date:me objects between a start date and an end date with
3132
some given frequency,
3233
Some events can be piled up in the same millisecond, this happens
3334
sometimes with real data.
3435
:param frequency_ms:
35-
:param start_date:
3636
:param end_date:
3737
:return:
3838
"""

devoutils/faker/senders/syslog_raw_sender.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class SyslogRawSender(BaseSender):
99
"""Generate a lot of events from/for Syslog"""
1010
def __init__(self, engine, template, **kwargs):
1111
BaseSender.__init__(self, engine, template, **kwargs)
12-
self.tag = kwargs.get('tag', 'test.keep.free')
1312
self.kwargs = kwargs
1413

1514
def run(self):

devoutils/faker/senders/syslog_sender.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ def __init__(self, engine, template, **kwargs):
1414
def run(self):
1515
"""Run function for cli or call function"""
1616
while True:
17-
lines = self.process().split('\n')
17+
lines = self.process(date_generator=self.date_generator).split('\n')
1818
for line in lines:
1919
if self.probability():
20-
self.engine.send(tag=self.tag, msg=str(line))
20+
if not self.simulation:
21+
self.engine.send(tag=self.tag, msg=str(line))
2122
now = datetime.utcnow().ctime()
2223
print('{0} => {1}'.format(now, str(line)))
2324
else:

docs/faker.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ Options:
4242
-ch, --chain PATH Chain file for SSL.
4343
--address TEXT address to send.
4444
--port TEXT Port to send.
45-
--tag TEXT Tag from Logtrust.
45+
--tag TEXT Tag from Devo.
4646
--simulation Set as simulation.
4747
-t, --template FILENAME Template to send. [required]
4848
-i, --interactive Interactive mode.
49+
-raw, --raw_mode Send raw mode.
4950
--prob INTEGER Probability (0-100).
50-
--freq TEXT Frequency in seconds ("1.0-5.0": 1 sec. to
51-
5secs.).
51+
--freq TEXT Frequency in seconds. Example:"1.0-5.0" =
52+
random time between 1 sec. to 5secs.
5253
--batch_mode Enable blatch mode, a lot of events will be
5354
generated as fast as possible and written to a
5455
file. The events will be generated in thetime
@@ -66,13 +67,14 @@ Options:
6667
The config.json file could be like this:
6768
```
6869
{
69-
"protocol": "SSL",
70-
"key": "<path_to_key>.key",
71-
"cert": "<path_to_cert>.crt",
72-
"chain": "<path_to_chain>.crt",
73-
"tag": "test.keep.free",
74-
"address": "eu.elb.relay.logtrust.net",
75-
"port": 443
70+
"sender": {
71+
"key": "<path_to_key>.key",
72+
"cert": "<path_to_cert>.crt",
73+
"chain": "<path_to_chain>.crt",
74+
"tag": "test.keep.free",
75+
"address": "eu.elb.relay.logtrust.net",
76+
"port": 443
77+
}
7678
}
7779
```
7880

0 commit comments

Comments
 (0)