Skip to main content

Function Library — Context

The remaining C members give a JavaScript script identifiers, shared values and a way to emit a diagnostic message.

MemberSignatureReturns
C.Misc.uuidv4()A random UUID
C.Misc.uuidv5(name, namespace)A deterministic UUID
C.Misc.validateUUID(value)true for a well-formed UUID of any version
C.Misc.getUUIDVersion(uuid)The version number, or undefined
C.Misc.zip(keys, values, target)An object built from two parallel arrays
C.os.hostname()The Director's host name
C.vars.<name>—A configured shared value
C.env.<name>—An environment variable
C.version—The Director's version string
C.confVersion—The configuration version
C.WorkerGroupId—The worker group identifier
C.log(message, data)Nothing; writes to the Director's log
debug(message, data)Nothing; writes to the Director's log

Details​

Identifiers​

C.Misc.uuidv4() generates a random identifier — the right choice for tagging an event that has none.

C.Misc.uuidv5() derives an identifier from a name, so the same name always produces the same UUID. That makes it a way to give a recurring entity a stable identifier without storing a mapping. The namespace argument takes DNS, URL, OID, X500 or a UUID of your own; anything else throws.

Give each host a stable identifier...

- script:
lang: js
source: |
if (__e.host) {
__e['host.id'] = C.Misc.uuidv5(__e.host, 'DNS');
}

Building an Object​

C.Misc.zip() pairs two arrays into an object, stopping at the shorter of the two. Pass a third argument to add the pairs to an existing object rather than a new one.

__e.attributes = C.Misc.zip(__e.field_names, __e.field_values);

Shared Values​

C.vars holds values configured on the Director and visible to every script — thresholds, allow lists, mappings that would otherwise be repeated in each pipeline.

if (C.vars.blocked_hosts.includes(__e.host)) {
__e.blocked = true;
}

C.vars is read-only from a script. Assigning to it fails, so it cannot be used to pass a value between events. Reads return a copy, so modifying a nested object you read from it changes nothing.

Environment and Host​

C.os.hostname() returns the host name of the Director running the pipeline, which is how an event is attributed to a node in a cluster.

C.env exposes environment variables as properties.

warning

C.env carries the Director process's entire environment, not a filtered subset. Anything passed to the process as an environment variable — including credentials — is readable by any script in any pipeline. Do not treat it as a safe place to read configuration from, and keep secrets in the Vault instead.

Version Values​

C.version, C.confVersion and C.WorkerGroupId are fixed strings, useful for stamping an event with the deployment that produced it. C.confVersion reads as undefined where no configuration version is set.

Logging​

C.log() and debug() both write a message to the Director's log, visible under Console Logs. Both take a message and an optional value. Neither throws, and neither returns anything useful.

debug('unexpected payload shape', __e._raw);

There is no console object — these two are the only way a script can emit a message. Use them while developing a script and remove them afterwards: a message written for every event is expensive and buries everything else in the log.