@@ -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
128134def 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
165169def print_error (error , show_help = False , stop = True ):
0 commit comments