Skip to content

Commit 4f4b3d4

Browse files
author
joseramon.afonso
committed
Updated documentation
1 parent fe8b6d0 commit 4f4b3d4

File tree

7 files changed

+113
-17
lines changed

7 files changed

+113
-17
lines changed

devoutils/faker/generators/template_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def __init__(self, template=None, providers=None, date_generator=None):
2020
self.fake.add_provider(InternetProvider)
2121
self.template = template
2222
self.providers = {} if providers is None else providers
23-
self.date_generator = TemplateParser.null_date_generator() \
23+
self.date_generator = TemplateParser.null_date_generator \
2424
if date_generator is None else date_generator
2525

2626
@staticmethod
2727
def null_date_generator():
2828
"""Generate now date"""
29-
yield str(datetime.now())
29+
return str(datetime.now())
3030

3131
def process(self, date_generator=None, **kwargs):
3232
"""Procces template, parsing it"""

docs/faker/file.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,41 @@
55
* [FileFakeGenerator](../../devoutils/faker/generators/file_fake_generator.py)
66

77
### Doc
8+
9+
file_name
10+
11+
This generator is mainly intended to create files with fake data.
12+
13+
You have one example in simple_file_template, we explain here:
14+
15+
Script:
16+
17+
from devoutils.faker import SyslogFakeGenerator
18+
from devo.sender import Sender
19+
20+
if __name__ == "__main__":
21+
with open("./simple_syslog_template.jinja2", 'r') as myfile:
22+
template = myfile.read()
23+
24+
con = Sender(config="./config.yaml")
25+
26+
f = SyslogFakeGenerator(engine=con,
27+
template=template,
28+
probability=100,
29+
frequency=(1, 1),
30+
tag="my.app.request.info",
31+
verbose=True)
32+
f.start()
33+
34+
35+
With this code we create one Sender With this basic code we create a Sender with the devo-sdk to send data to
36+
Devo, and we create a SyslogFakeGenerator to create the false data.
37+
38+
You have to add the tag that you want to send in the creation of the SyslogFakeGenerator object, a
39+
nd the generator will be in charge of using the con.send function (tag = self.tag, msg = fake_data_line) to send the data
40+
41+
Template:
42+
43+
{%- set type = fake.random_element(["post", "get"]) -%}
44+
{{ next(date_generator) }} receiving {{ type }} request.
45+
{%- set a = 3 -%}

docs/faker/realtime.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,25 @@
55
* [RealtimeFakeGenerator](../../devoutils/faker/generators/realtime_fake_generator.py)
66

77
### Doc
8+
9+
This generator is the parent class of several generators, but it is also useful for creating your own generators.
10+
11+
Just create a class like the example below, and create your own run function. With this you can add your own functions.
12+
13+
The important thing is, in the run function, call `self.realtime_iteration` sending your own write function in the
14+
variable `write_function` (It can be a send, or a print, or your own function to send it by https or a socket, anything.
15+
16+
from .realtime_fake_generator import RealtimeFakeGenerator
17+
18+
19+
class MyCustomGenerator(RealtimeFakeGenerator):
20+
"""Class to manage secure simulations of faker"""
21+
def __init__(self, template=None, **kwargs):
22+
RealtimeFakeGenerator.__init__(self, template=template, **kwargs)
23+
24+
#You can override this function/Creat your own
25+
def run(self):
26+
"""Run function for cli or call function"""
27+
#This call is neccesary for write/send/whatever, yo need send your function
28+
#in write_function. You receive in each call one text line
29+
self.realtime_iteration(write_function=lambda x: x)

docs/faker/shellcli.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ command, for example:
44
```
55
devo-faker -t template --config config.json -i
66
```
7+
8+
Or all in config file
9+
```
10+
devo-faker --config config.json
11+
```
12+
713
This command uses the template indicated with the configuration inside the
814
config.json file and makes the process interactive.
915

@@ -26,27 +32,36 @@ Options:
2632
will only store the events in a file. Can be
2733
used with batch mode to set the file where
2834
store the batch events
35+
2936
--simulation Set as simulation. Shows the event in the
3037
console, but do not send it
38+
3139
-t, --template FILENAME Template to send. [required]
40+
-p, --providers FILENAME File with custom providers dict.
3241
-i, --interactive Interactive mode.
3342
-raw, --raw_mode Send raw mode.
34-
--prob INTEGER Probability (0-100).
35-
--freq TEXT Frequency in seconds. Example:"1.0-5.0" =
43+
--probability INTEGER Probability (0-100).
44+
--frequency TEXT Frequency in seconds. Example: "1.0-5.0" =
3645
random time between 1 sec. to 5secs.
46+
3747
--batch_mode Enable blatch mode, a lot of events will be
3848
generated as fast as possible and written to a
3949
file. The events will be generated in thetime
4050
range specified by the --date_range option
51+
4152
--date_range <TEXT TEXT>... batch mode: Date range where the logs will be
4253
generated, default: the last 24 hours
54+
4355
--date_format TEXT (batch mode) Format of the generated dates.
4456
default: "%Y-%m-%d %H:%M:%S.%f"
57+
4558
--dont_remove_microseconds (batch mode) By default the microseconds are
4659
removed from the generated dates by doing
4760
date[:-3] this flags prevents it
61+
4862
--verbose Verbose mode shows the events created in the
4963
console when sending dta into Devo.
64+
5065
--help Show this message and exit.
5166
```
5267

@@ -60,20 +75,24 @@ The config.json file could be like this:
6075
"tag": "test.keep.free",
6176
"address": "eu.elb.relay.logtrust.net",
6277
"port": 443
63-
}
78+
},
79+
"verbose": true,
80+
"probability": 80,
81+
"frequency": (2,4)
6482
}
6583
```
6684

6785
config.yaml its available too:
6886
```
69-
{
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-
}
78-
}
87+
sender:
88+
key: "<path_to_key>.key",
89+
cert: "<path_to_cert>.crt",
90+
chain: "<path_to_chain>.crt",
91+
tag: "test.keep.free",
92+
address: "eu.elb.relay.logtrust.net",
93+
port: 443
94+
simulation: true
95+
probability: 50
96+
frequency: (1,3)
97+
providers: providers.py
7998
```

docs/faker/simulation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@
55
* [SimulationFakeGenerator](../../devoutils/faker/generators/simulation_fake_generator.py)
66

77
### Doc
8+
9+
This is a basic generator to create simulations on the screen, useful to see how a template
10+
would work, etc., without risking sending data.
11+
12+
In short, it is a generator to display the data on the screen, as if you activated the flag
13+
`simulation` and` verbose` in any of the other generators

examples/simple_file_example.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from devoutils.faker import FileFakeGenerator
2+
3+
if __name__ == "__main__":
4+
with open("./simple_syslog_template.jinja2", 'r') as myfile:
5+
template = myfile.read()
6+
7+
f = FileFakeGenerator(template=template,
8+
probability=80,
9+
frequency=(1, 3),
10+
verbose=True,
11+
file_name="faker_file_example.log")
12+
f.start()
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
{%- set type = fake.random_element(["post", "get"]) -%}
2-
{{ next(date_generator) }} receiving {{ type }} request.
3-
{%- set a = 3 -%}
2+
{{ date_generator() }} receiving {{ type }} request.

0 commit comments

Comments
 (0)