Custom
Enrich and drop TenXObjects using custom JavaScript constructors.
Load custom .js files via JavaScript config.
Enrich
Enrich instances with calculated fields that combine JSON/KV field, reflection, launch argument and lookup values.
The example below calculates an HTTP code field:
// @loader: tenx
import {TenXObject, TenXMath} from '@tenx/tenx'
export class HttpCodeObject extends TenXObject {
/**
This constructor computes a calculated HTTP error code field from the penultimate variable token for each 10x Object
according to: https://httpd.apache.org/docs/2.4/logs.html
For example, this will extract the '200' value into the 'code' field from:
127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
*/
constructor() {
var code = TenXMath.parseInt(this.var[-2]);
this.httpCode = (code >= 200) && (code < 600) ? code : 0;
}
}
Filter
Drop unnecessary TenXObjects from the pipeline via the drop function.
// @loader: tenx
import {TenXObject} from '@tenx/tenx'
export class FilteredObject extends TenXObject {
constructor() {
// Does not require the instance to undergo structuring
this.drop(this.startsWith("TRACE"));
// Requires the instance to undergo structuring based on the value of the penultimate 'vars' element.
this.drop(this.vars[-2] != 200);
}
}
Increase
Update cyclical counters and update dictionaries.
The example below uses an interval counter can be used to limit the rate of TenXObjects based on their symbolSequence to a target limit (e.g. 1000) within a specific interval (e.g. "1s"). This prevents a "chatty" event from "hogging" the pipeline's bandwidth:
// @loader: tenx
import {TenXObject, TenXCounter} from '@tenx/tenx'
export class RateLimitObject extends TenXObject {
constructor() {
var symbolSequence = this.symbolSequence();
if (TenXCounter.getAndSet(symbolSequence, "1s") > 1000)
this.drop();
else
TenXCounter.inc(symbolSequence);
}
}
Template Members
Template members demonstrated below allow all instances of the same TenXTemplate to share members across all of its instances.
The example below assigns TenXObjects with a calculated severity level using specific symbol values (e.g.,Debug, Traceback most recent call last).
// @loader: tenx
import {TenXTemplate, TenXString, TenXEnv} from '@tenx/tenx'
export class LevelTemplate extends TenXTemplate {
constructor() {
// check the template's symbol value starts with any of the configured 'levelTerms' values
// use the map function to get the level value associated with a matching term
LevelTemplate.level = TenXString.startsWith(
this.symbolSequence("", "log"", 30),
TenXMap.fromEntries(TenXEnv.get("levelTerms"))
));
}
}
Dynamic Loading
Each class can define a custom shouldLoad static function to determine whether to execute code defined in its constructor based on configuration and environment settings.
The engine invokes this function upon initialization. If the function returns a truthy value the class is loaded into memory, otherwise it is not loaded and its enclosed constructor code is not executed to initialize inputs, instances, and summaries.
// @loader: tenx
import {TenXInput, TenXObject, TenXEnv} from '@tenx/tenx'
export class MyInput extends TenXInput {
// To learn more see https://doc.log10x.com/api/js/#TenXEngine.shouldLoad
static shouldLoad(config) {
return config.myProp || TenXEnv.get("myVar");
}
constructor() {
// init actions
}
}
export class SplunkObject extends TenXObject {
// To learn more see https://doc.log10x.com/api/js/#TenXEngine.shouldLoad
static shouldLoad(config) {
return config.myProp || TenXEnv.get("myVar");
}
constructor() {
// init actions
}
}
Options
Specify the options below to configure multiple Object JavaScript:
| Name | Description |
|---|---|
| objectActionsClassName | JavaScript class name |
| objectActions | 10x JavaScript instance constructor statements to execute |
| objectActionsFile | Declaring .js file |
objectActionsClassName
JavaScript class name.
| Type | Required | Names |
|---|---|---|
| String | ✔ | [objectActionsClassName, TenXObjectClassName] |
Specifies the JavaScript class name in which objectActions are defined.
objectActions
10x JavaScript instance constructor statements to execute.
| Type | Default | Names |
|---|---|---|
| List | [] | [objectActions, TenXObject] |
JavaScript statements for initializing target input(s) TenXObject instances.
NOTE: This argument is not designed to be set directly, but instead by passing a .js launch file containing these statements nested within an TenXObject sub-class constructor as command line argument as described above.
objectActionsFile
Declaring .js file.
| Type | Default | Names |
|---|---|---|
| String | "" | [objectActionsFile, TenXObjectFile] |
Specifies the .js file name declaring objectActions.
This unit is defined in object/unit.yaml.