Object Engine
The Trisul metrics engine.
You call methods on this object to add metrics, objects, flows, or other types of information.
π This is the most important object you will be working with.
Functions and typesβ
A summary of the functions available in this object.
- F β functions that can be called from Frontend scripts
- B β functions that can be called from Backend scripts
If you call functions that are not available you will get the following error
ERR_NOTAVAIL: add_flow_counter() is not available for backend scripts
| Name | Availability | Description |
|---|---|---|
| update_counter | F B | Updates a meter for a key with a particular value |
| update_counter_bytes | F | Updates a meter for a key but with a value of wire_length in the packet |
| update_counter_raw | F B | Update counter raw is a variant of update_counter. |
| update_key_info | F B | Set a user friendly label or a description for a key |
| add_alert | F B | Add an alert |
| add_alert_full | F B | Same as add alert with with a priority and classification. Used for IDS alert types |
| add_alert_tca | F B | For alerts based on metric values and threshold crossing events` |
| add_resource | F B | Add a new resource with metadata and contents to Trisul |
| timestamp | F B | The latest timestamp seen by the engine |
| add_flow_counter | F | Add a flow counter |
| reset_flow_counter | F | Removes all flow counters, then does an add_flow_counter |
| tag_flow | F B | Tag a flow with a label. Y |
| instanceid | F B | Engine Instance identifier |
| probeid | F B | Trisul probe id of the engine |
| update_flow | F | Update a flow based metric |
| new_flow_record | F | Inform framework about a new flow record |
| set_flow_duration | F | Set the duration of the flow in seconds |
| disable_reassembly | F | Stop TCP reassembly of this flow |
| post_message_frontend | F B | Post a message to other LUA plugins attached to the packet (frontend) pipeline |
| post_message_backend | F B | Post a message to other LUA plugins in the metrics (backend) pipeline |
| add_edge | F B | Add a single edge to the Trisul Streaming Graph Analytics pipeline |
| add_flow_edges | F B | Automatically add edges from a network flow to a given vertex. |
| set_key_attribute | F B | Set an arbitrary {attribute-name,value}\ pair for any key |
| add_flow_attribute | F B | Add an {attribute-name,value} pair for any flow for other Lua script to pick up. |
Function update_counterβ
Adds a single metric to the Trisul platform.
Purposeβ
Update a counter with a value. Recall that the heirarchy in Trisul is
- Counter Group example
Applications- Key example
pop3- Meter example meter
id = 5 Active Connections
- Meter example meter
- Key example
Also seeβ
Use update_counter_raw if
- you are updating
GAUGEorAVERAGEmeter data types - you are updating more than 8 metrics for the same key
Parametersβ
| counter guid | guid string | the counter group you want to update |
|---|---|---|
| key | string | the unique key within the counter group |
| meter | number | the metric id within the counter group |
| value | number | the metric value |
Return valueβ
None
Usageβ
..
-- update the Hosts counter group identified by the GUID {4CD..}
-- the Host identified by 182.28.22.123
-- the Meter 1 (received bytes)
-- with the value 288278
--
engine:update_counter( "{4CD742B1-C1CA-4708-BE78-0FCA2EB01A87}", "182.28.22.123", 1, 288378)
Function update_counter_bytesβ
FRONTEND ONLY
Adds a single metric to the Trisul framework. Same as update_counter but where the metric value is the packet wire length.
Purposeβ
When used with simplecounter and other front end scripts β this method adds a metric with the wire length of the packet context in which it is called.
Parametersβ
| counter guid | guid string | the counter group you want to update |
|---|---|---|
| key | string | the unique key within the counter group |
| meter | number | the metric id within the counter group |
Return valueβ
None
Usageβ
This method is only available on frontend scripts.
Function update_counter_rawβ
A variation of update_counter
Purposeβ
This does exactly the same thing as update_counter with the following difference.
- this version has a slightly lower performance
- use this method if you want to update a large number of keys for a single counter group . More than 8 keys
- you are updating
GAUGEorAVERAGEmeter data types
Parametersβ
| counter guid | guid string | the counter group you want to update |
|---|---|---|
| key | string | the unique key within the counter group |
| meter | number | the metric id within the counter group |
| value | number | the value of the meter |
Return valueβ
None
Usageβ
--
-- we are updating 6 keys for a single counter group
-- for this kind of updating use the 'raw' version
--
engine:update_counter_raw("{D2AAD7C6-...}", "user_1", 1, 100)
engine:update_counter_raw("{D2AAD7C6-...}", "user_11", 1, 10)
engine:update_counter_raw("{D2AAD7C6-...}", "user_2", 1, 200)
engine:update_counter_raw("{D2AAD7C6-...}", "user_33", 1, 3200)
engine:update_counter_raw("{D2AAD7C6-...}", "user_34", 1, 300)
engine:update_counter_raw("{D2AAD7C6-...}", "user_44", 1, 23200)
Function update_key_infoβ
Set a user friendly label for a key.
Purposeβ
Set a user friendly label or a description for a particular key. For example : to assign a hostname to an IP address
Parametersβ
| counter group id | guid string | the counter group id of the counter |
|---|---|---|
| key | string | the key |
| label | string | the human friendly label attached to the key |
| description (optional) | string | more information |
Return valueβ
None
Usageβ
..
--
-- to assign a label "Router1_10G_1" to the MAC address "0A:11:21.BA:00:02"
-- the GUID "{4B0.." represents the MAC Counter Group
--
engine:update_key_info( "{4B09BD22-3B99-40FC-8215-94A430EA0A35}", "0A:11:21:BA:00:02", "Router1_10G_1")
..
Function add_alertβ
Add an alert to the Trisul framework.
Purposeβ
Lets you add a simple alert to the Trisul pipeline. This simple version only contains a priority, alert-type, and description. Also see add_alert_full and add_alert_tca for more specific variants.
Parametersβ
| alert guid | guid string | Identifies the type of alert. See GUIDs |
|---|---|---|
| flowkey | string or nil | the flowid string of the flow which caused the alert. nil if alert not related to a particular flow |
| alertkey | string | the type of alert within the group. Think of this as a Signature ID |
| priority | number | the alert priority. typically 1 = high, 2 = medium, 3 = low. But you can use your priorities if you are using your own alert groups |
| message | string | a dispatch message |
Return valueβ
None
Usageβ
The following example adds a Priority 1 alert to the general purpose User Alerts group.
engine:add_alert("{B5F1DECB-51D5-4395-B71B-6FA730B772D9}", -- GUID for 'User Alerts' group
resource:flow():id(), -- flow ID
"RAMNIT-DETECTED", -- alert key , think of this as a SigID
1, -- priority
"A potential EK was detected message =" -- free form text alert
)
Function add_alert_fullβ
Add an alert to the Trisul framework with all bells and whistles.
Purposeβ
Same as add_alert but with classification and priority fields. To make it compatible with alerts from IDS systems like Snort and Suricata
Parametersβ
| alert guid | guid string | Identifies the type of alert. See GUIDs |
|---|---|---|
| flowkey | string or nil | the flowid string of the flow which caused the alert. nil if alert not related to a particular flow |
| alertkey | string | the type of alert within the group. Think of this as a Signature ID |
| classification | string | Optional: a type of alert. This is for compatibility with popular IDS systems like Snort and Suricata |
| priority | number | the alert priority. typically 1 = high, 2 = medium, 3 = low. But you can use your priorities if you are using your own |
| message | string | a dispatch message |
| status | string (optional) | a status or impact field. Example : CLEAR, ALARM, FIRE, BLOCK etc |
Return valueβ
None
Usageβ
Function add_alert_tcaβ
A special type of alert called Threshold Crossing Alert (TCA) based on metrics.
Purposeβ
Same as add_alert family but designed for metrics based alerting.
Parametersβ
| alert guid | guid string | Identifies the type of alert. See GUIDs |
|---|---|---|
| tca_id | number | a number that uniquely identifies a type of threshold youβve defined elsewhere. Example : a TCA , Threshold Band, or Flow Tracker alert in Trisul. |
| status | string | a string FIRED crossed threshold event or CLEAR when condition is clear and metric back in limits |
| message | string | a dispatch message |
Return valueβ
None
Usageβ
Function add_resourceβ
Add a new resource.
Purposeβ
Resources are meta data which you can log and search on. You can create your own resource group or add to existing resource groups like βDNS Recordsβ, βHTTP URLsβ, etc. Think of resources as logs and resource groups as log types
Parametersβ
| resource_id | a GUID | Resource group ID. See GUIDs |
|---|---|---|
| flowkey | a string in FlowID format | The flow containing this resource. You can get the flow ID from a packet. |
| uri | a string | The metadata that identifies the resource. This can be thought of a summary of the full log entry |
| contents (optional) | a string | The actual resource (less than 32K). This of this as the complete log line |
Return valueβ
None
Usageβ
-- add a custom SHA256 hash resource
--
engine:add_resource('{9781db2c-f78a-4f7f-a7e8-2b1a9a7be71a}', -- represents FileHash resource in Trisul
flowkey:id(), -- flow ID
"SHA256:"..hex_sha256, -- resource key (log summary)
full_filename) -- full resource (full log)
Function timestampβ
The latest timestamp in seconds since Epoch format (timeval.tv_sec) seen by the engine.
Purposeβ
If you want to find out the latest timestamps seen by the engine. Remember that you may not be able to simply use os.date) because Trisul also works on PCAP files that may have other timestamps.
Parametersβ
None.
Return valueβ
| Number | Representing number of seconds since 1-1-1970, a unix timestamp value (tv_sec) |
|---|
- For frontend scripts that work with packets, this represents the timestamp of the last packet seen.
- For backend scripts, this returns the last stream interval that was processed to completion.
Usageβ
Function add_flow_counterβ
FRONTEND ONLY
Add an automatic flow based counter.
Purposeβ
A Flow Counter works in the following way :
- you attach a counter to a flow
- all packets in that flow from that point onwards automatically get that counter with the metric equal to the packet length
Parametersβ
| flowkey | string | identifies the flow that you want to attach a counter to |
|---|---|---|
| counter group id | guid string | the counter group id of the counter you want to attach to this flow |
| key | string | the key within the counter group |
| metric | number | the metric for the counter group |
| direction | number | the direction you want to count. 0 = Both 1 = OUT (in Direction of SYN), 2 = IN |
Return valueβ
None
Usageβ
The method is only available for Frontend scripts. If you call this method from a backend script you will get an error.
If you detect a particular flow to be carrying YouTube video you can attach a counter βyou-tube-trafficβ metric. From that point onwards each packet on that flow will automatically update the βyoutube-trafficβ counter with the packet length.
Note on the Direction parameterβ
Use Direction=0 to update a Total traffic counter and Directions 1,2 to update IN/OUT separately. In the snippet below youβve created your own counter group with GUID {55F..} with three meters 0=Total,1=Xmit,2=Recv. You can see how to update the Totals counter Direction=0 and In/Out counters
-- Direction 0 : update both OUT and IN direction packets to the same counter
-- to update a TOTAL BYTES counter
engine:add_flow_counter( flowkey:id(),
"{55F98CC1-646E-4DE6-AD79-6B896211F177}", -- a counter guid
'my-video-traffic',
0, -- Total bytes
0) -- Both directions update the Total bytes counter
-- for XMIT
engine:add_flow_counter( flowkey:id(),
"{55F98CC1-646E-4DE6-AD79-6B896211F177}", -- a counter guid
external_host,
1, -- Transmit meter
1) -- Only OUT direction update the Trasmit meter
-- for RECV
engine:add_flow_counter( flowkey:id(),
"{55F98CC1-646E-4DE6-AD79-6B896211F177}", -- a counter guid
external_host,
2, -- Recv meter
2) -- Only IN direction update the receive meter
Function reset_flow_counterβ
FRONTEND ONLY
Removes a flow based counter.
Purposeβ
Remove a previous flow based counter added by add_flow_counter
Parametersβ
| flowkey | string | identifies the flow that you want to attach a counter to |
|---|---|---|
| counter group id | guid string | the counter group id of the counter you want to attach to this flow |
Return valueβ
None
Usageβ
The method is only available for Frontend scripts. If you call this method from a backend script you will get an error.
Function tag_flowβ
Tag a flow with a string.
Purposeβ
Add a text label to a IP flow. You can then search for flows using this string.
Parametersβ
| flowkey | string | identifies the flow that you want to attach a counter to. Usually you get this from flow:id |
|---|---|---|
| tag | string | a short text label that is attached to the flow. You can attach multiple tags to a flow but the total length of all tags must be less than 64 bytes. If you add tags >= 64 bytes the extra tags are discarded. |
Return valueβ
None
Usageβ
Function instanceidβ
A string representing the instance of the engine
Purposeβ
There may be multiple engine contexts in Trisul. This string identifies each one. You can use this to construct unique filenames etc.