Automation

High-Level Overview

Automation leveragesscripts, hooks and helpers to enable users to ask questions, build custom reports and metrics, and create automations—all based on the information available in the network.

GenAI-Assisted Network Observability

Examples of Questions:

  • Identify the top 5 DNS consumers.
  • Report the theoretical impact of network policies on live pods.
  • Show pods and processes with external connections.
  • Highlight pods with no network activity (likely candidates for cost optimization).
  • Report API latency anomalies.

Examples of Automations:

  • Export traffic for API security scanning.
  • Record traffic and upload it to an immutable datastore.

Custom Report Templates

Some examples are already available and ready to use in the Kubeshark dashboard.

Script Templates


Scripts

A script includes ES5 JavaScript code that comprises:

  1. Hooks - Triggered upon the occurrence of certain events.
  2. Helpers - Invoke integrations and specific Kubeshark functions.
  3. General code - Used for calculations and storing information in memory.

Scripts are used to process network traffic, perform calculations, and trigger actions that may result in creating custom metrics, exporting logs, generating reports, or building automations.


Hooks

Hooks are functions designed to process traffic. They are called when specific events occur and provide a way to invoke user-created JavaScript code from Kubeshark’s Go backend.

The simplest example is the onItemCaptured hook, which is triggered every time a new API call is processed and reassembled. The example below prints the metadata for every API call:

function onItemCaptured(data) {
  // Prints the API call metadata
  console.log("Msg:", JSON.stringify(data));
}

Hooks operate continuously in the backend, regardless of the dashboard state (whether open or closed).

Hook Examples

Below is a list of some hooks and their descriptions.

HookEventRunnable onDescription
onItemCapturedAPI call reassemblyWorkersInvoked for every emitted item representing a reassembled message. This hook works inline and should include quick actions like calculations or assignments.
onHubActionhub.action(action, object) is invokedHubUsed for moving objects from Workers to the Hub for further processing, consolidating map objects, or offloading computations to the Hub.
onPodEventOn every pod event (e.g., restart)Hub and WorkersTriggered on pod events, enabling custom functionality, such as capturing a snapshot of pod traffic before a crash.

Helpers

Helpers are used to trigger actions related to supported integrations (e.g., Slack, AWS S3). They provide a way to invoke Kubeshark’s Go backend from user-created JavaScript code.

Below is an example of a helper that uploads an object to a webhook:

vendor.webhook(
  "POST",
  "https://webhook.site/a42ca96d-4984-45dc-8f72-a601448399dc",
  JSON.stringify(data)
);

Helper Examples

Below is a list of some helpers and their descriptions.

HelperUsageRunnable onDescription
console.logPrint text to the ConsoleHub and WorkersA commonly used helper to print log messages or create custom reports.
jobs.scheduleSchedule jobsHub and WorkersSchedules a function to run at specified intervals using a cron expression. Suitable for handling complex or time-consuming tasks.
vendor.kinesis.putExport traffic to AWS KinesisHub and WorkersExports data to a Kinesis stream, enabling external systems to process it for tasks like security or API scanning.