Skip to content

Scripting API

ThreatHub supports writing JavaScript code to handle certain actions. This currently includes Automatic vulnerability escalation.

Scripts are in the scripts directory of ThreatHub Ingestor. The directory and example scripts will be created on first run. The file tree should look something like the below:

  • Directory/home/threathub/
    • Directoryingestor/
      • Directoryscripts/
        • software-escalation.js
      • ThreatHub-Ingestor-0.0.1.jar
      • …

There are numerous APIs that can be accessed via the global api object:

api.config
api.http
api.log
api.sql
api.tickets

Returns all configuration values as a JavaScript object.

Example output:

{
"SITE_URL": "https://threathub.example.com",
"ENABLE_TICKETING": true
}

Returns a single configuration value by key.

Parameters:

Example output:

https://threathub.example.com

Sends a GET request to the specified URL.

Example output:

{
"status": 200,
"body": "{\"message\":\"ok\"}",
"headers": {
"content-type": ["application/json"]
}
}

Sends a POST request to the specified URL with a request body.

Example output:

{
"status": 200,
"body": "{\"message\":\"ok\"}",
"headers": {
"content-type": ["application/json"]
}
}

Sends a custom HTTP request.

Parameters:

  • req - A configuration object with the following fields:
    • method (optional) - HTTP method (GET, POST, PUT, DELETE). Defaults to GET.
    • url (required) - The target URL.
    • body (optional) - Request body as a string.
    • headers (optional) - Object of key-value header pairs.
    • timeout (optional) - Timeout in milliseconds. Defaults to 2000.

Example output:

{
"status": 200,
"body": "{\"message\":\"ok\"}",
"headers": {
"content-type": ["application/json"]
}
}

Logs an informational message to the terminal.

Logs an warning message to the terminal.

Logs an error message to the terminal.

Logs a debug message to the terminal.

Executes a SQL query;

Parameters:

  • sql - The SQL query
  • params (optional) - An array of parameters

Example usage:

// No parameters
const customers = await api.sql.query("SELECT * FROM customers");
console.log(customers); // [{ id: 1, name: "Test Customer", ... }]
// With parameters
const customers = await api.sql.query("SELECT * FROM customers WHERE name = ?", ["Test Customer"]);
console.log(customers); // [{ id: 1, name: "Test Customer", ... }]
create(customerId: number, softwareId: number, model?: object)
Section titled “create(customerId: number, softwareId: number, model?: object)”

Creates a ticket for the given customer and software.

Parameters:

  • customerId - The ID of the customer
  • softwareId - The ID of the software
  • model (optional) - Data to pass to the Freemarker template
    • publicExploit - boolean
    • cveCount - number
    • deviceCount - number
    • highestCveSeverity - string
    • softwareLink string | null

Retrieves a ticket by its ID.

Example output:

{
"id": 12345,
"dateoccurred": "2025-01-01T12:00:00Z",
"summary": "Example ticket summary",
"details": "Detailed description of the issue",
"team": "Support",
"client_id": 1001,
"last_update": "2025-01-02T15:30:00Z",
"status_id": 8,
"isClosed": true
}