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
- …
API Reference
Section titled “API Reference”There are numerous APIs that can be accessed via the global api object:
api.configapi.httpapi.logapi.sqlapi.ticketsConfig
Section titled “Config”getAll()
Section titled “getAll()”Returns all configuration values as a JavaScript object.
Example output:
{ "SITE_URL": "https://threathub.example.com", "ENABLE_TICKETING": true}get(key: string)
Section titled “get(key: string)”Returns a single configuration value by key.
Parameters:
key- The config key name. Must be one of these enum values
Example output:
https://threathub.example.comget(url: string)
Section titled “get(url: string)”Sends a GET request to the specified URL.
Example output:
{ "status": 200, "body": "{\"message\":\"ok\"}", "headers": { "content-type": ["application/json"] }}post(url: string, body: string)
Section titled “post(url: string, body: string)”Sends a POST request to the specified URL with a request body.
Example output:
{ "status": 200, "body": "{\"message\":\"ok\"}", "headers": { "content-type": ["application/json"] }}request(req: object)
Section titled “request(req: object)”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"] }}info(text: string)
Section titled “info(text: string)”Logs an informational message to the terminal.
warn(text: string)
Section titled “warn(text: string)”Logs an warning message to the terminal.
error(text: string)
Section titled “error(text: string)”Logs an error message to the terminal.
debug(text: string)
Section titled “debug(text: string)”Logs a debug message to the terminal.
query(sql: string, params?: array)
Section titled “query(sql: string, params?: array)”Executes a SQL query;
Parameters:
sql- The SQL queryparams(optional) - An array of parameters
Example usage:
// No parametersconst customers = await api.sql.query("SELECT * FROM customers");console.log(customers); // [{ id: 1, name: "Test Customer", ... }]
// With parametersconst customers = await api.sql.query("SELECT * FROM customers WHERE name = ?", ["Test Customer"]);console.log(customers); // [{ id: 1, name: "Test Customer", ... }]Tickets
Section titled “Tickets”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 customersoftwareId- The ID of the softwaremodel(optional) - Data to pass to the Freemarker templatepublicExploit- booleancveCount- numberdeviceCount- numberhighestCveSeverity- stringsoftwareLinkstring | null
lookup(ticketId: string)
Section titled “lookup(ticketId: string)”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}