Test Generator (im_testgen)

This module generates simple events for testing, with an incremented integer up to the number of events specified by the MaxCount directive.

Configuration

The im_testgen module accepts the following directives in addition to the common module directives.

Optional directives

MaxCount

The module will generate the defined number of events and then stop generating events. If this directive is not specified, im_testgen will continue generating events until NXLog Agent is running.

Examples

Example 1. Generating unstructured events

This configuration generates ten unstructured events defined in the MaxCount directive and then stops generating events.

nxlog.conf
<Input testgen>
   Module      im_testgen
   MaxCount    10
</Input>
Output sample
0@Mon Nov 13 16:14:53 2023
1@Mon Nov 13 16:14:53 2023
2@Mon Nov 13 16:14:53 2023
3@Mon Nov 13 16:14:53 2023
4@Mon Nov 13 16:14:53 2023
5@Mon Nov 13 16:14:53 2023
6@Mon Nov 13 16:14:53 2023
7@Mon Nov 13 16:14:53 2023
8@Mon Nov 13 16:14:53 2023
9@Mon Nov 13 16:14:53 2023
Example 2. Generating structured events

This configuration generates ten events defined in the MaxCount directive and pares them into a JSON format as a structured output.

nxlog.conf
<Extension json>
   Module      xm_json
</Extension>

<Input testgen>
   Module      im_testgen
   MaxCount    10
   Exec        $Message=$raw_event; json->to_json();
</Input>
Output sample
{
  "SeverityValue":2,
  "EventTime":"2023-11-13T16:18:44.854580+00:00",
  "SourceName":"nxlog",
  "ProcessID":1,
  "EventReceivedTime":"2023-11-13T16:18:44.854580+00:00",
  "SourceModuleName":"testgen",
  "SourceModuleType":"im_testgen",
  "Hostname":"f691d53f3ad0",
  "Message":"1@Mon Nov 13 16:18:44 2023"
}
Example 3. Using a schedule and module restart for crude rate-limiting

This configuration generates ten events defined in the MaxCount directive. Then, the Schedule block restarts the module to start generating events again, going into a cycle of generating ten events every 5 seconds.

nxlog.conf
<Extension json>
    Module      xm_json
</Extension>

<Input testgen>
    Module      im_testgen
    MaxCount    10
    Exec        $Message=$raw_event; json->to_json();
    <Schedule>
        Every    5 sec
        Exec     module_restart();
    </Schedule>
</Input>
MaxCount is only reset on module restart starting from NXLog Agent version 6.2.
Output sample from the NXLog Agent log file reporting of completed cycles.
2023-11-13 16:26:08 INFO [im_testgen|testgen] maxcount 10 reached
2023-11-13 16:26:13 INFO [im_testgen|testgen] maxcount 10 reached
2023-11-13 16:26:18 INFO [im_testgen|testgen] maxcount 10 reached
2023-11-13 16:26:23 INFO [im_testgen|testgen] maxcount 10 reached
Example 4. Rate-limiting and randomized rate-limiting

This configuration generates a continuous event stream where the module waits for 100000 microseconds between generating events. It roughly equals to around ten events generated per second.

nxlog.conf
<Input testgen>
    Module    im_testgen
    Exec      sleep (100000);
</Input>

This configuration generates a continuous event stream where the module waits randomly between 0 to 2000 microseconds within generating events.

nxlog.conf
<Input testgen>
    Module    im_testgen
    Exec      sleep (get_rand(2000));
</Input>