Scripts
There are currently two types of script you can use in SquaredUp:
Tile Data scripts (JavaScript) – used to get data to display on a tile.
Monitor Condition scripts (JavaScript) – used to write conditions that determine the monitored state of a tile based on its data.
Tile Data scripts
Tile Data scripts allow you to fetch data and display it on a tile. Tile Data scripts require an async function getData(params, api)
entrypoint that returns the tile data, usually in data stream format, either as a result of invoking a data stream or by calling the api.toStreamData
function to convert the tile data to data stream format. Data should be formatted as a data stream before it can be used in visualizations in SquaredUp. If possible, the api.toStreamData
function should always be called. If it is not called, SquaredUp will attempt to convert the data, but then metadata cannot be specified.
See Data Streams
Adding a Tile Data script
In SquaredUp browse to Settings > Advanced > Scripts and select Add new script.
Display name:
Enter a name for your script. This helps you to identify this script in the list of your scripts.
Script Type:
Select Tile Data (JavaScript).
Script editor:
Enter your script. By default, you will see an example script in the editor. The example will help you to understand how to structure your script.
The
params
object contains:params.timeframe
– the timeframe (object) for which tile data should be read.params.config
– the configuration object specified when configuring the +Run Script data stream.params.targetNodes
– the tile scope's target nodes (array of node objects or [] if no scope).params.context
– the context object containing:Copy{
“tenant“: “ten-XecW75nBaFpw3JnepDuS“, # the tenant id (mandatory)
“dashboard“: “dash-dHD9A4q3Hv8xOsKtJtQ8“, # the dashboard id (optional)
“workspace“: “space-rjd73f8s9f204azocm9d“ # the workspace id (optional)
}
The
api
callback function object contains:async function post(path, body)
– the asyncpost
callback function can be used to invoke a data stream (/datastreams/requests
path), query the graph (/query
path), or make a WebApi request (/request
path) from within a script. This callback function is unlikely to be called from a Monitor Condition script but is often needed by a Tile Data script.async function toStreamData(data, { rowpath = [], metadata = [] } = {} )
– the asynctoStreamData
callback function can be used to convert non-data stream formatted data into data stream formatted data for use with data stream visualizations. This callback function is unlikely to be called from a Monitor Condition script but is often needed by a Tile Data script.async getColumnData(data, columnName)
– thegetColumnData
callback function can be used to obtain the rows of the specified column of data stream formatted data (i.e. thedata
parameter must be data stream formatted data). This callback function is very unlikely to be called from a Tile Data script but is often needed by a Monitor Condition script.
When have finished editing your script, click Save.
Using a Tile Data Script
Add or Edit a dashboard and go into the configuration of a tile.
The Run Script data stream appears under SquaredUp in the tile editor scope. Alternatively, you are able to scope to an object and then select the Run Script data stream. If you have scoped to one or more objects, the script's
params.targetNodes
array argument will contain the target object(s).Display Name:
Enter a name for the new data stream.
Script:
Select the script that you want to use from the dropdown.
Configuration (optional):
params.config
argument to pass the script. You would normally leave this empty, it can be used if you want to parameterize your script.Click Save.
Monitor Condition scripts
Monitor Condition scripts give you unlimited flexibility and can be written to monitor any data in any way. Monitor Condition scripts require an async function getState(params, api)
entrypoint that must return the tile monitor’s state (error
, warning
, success
, or unknown
) and may return the monitor’s scalar value that caused the state.
See Monitors
Adding a Monitor Condition script
In SquaredUp browse to Settings > Advanced > Scripts and select Add new script.
Display name:
Enter a name for your script. This helps you to identify this script in the list of your scripts.
Script Type:
Select Monitor Condition (JavaScript).
Script editor:
Enter your script. By default, you will see an example script in the editor. The example will help you to understand how to structure your script.
The
params
object contains:params.data
– the tile data in data stream format.
params.config
– the script configuration specified when enabling script monitoring within the tile editor.
The
api
callback function object contains:async function post(path, body)
– the asyncpost
callback function can be used to invoke a data stream (/datastreams/requests
path), query the graph (/query
path), or make a WebApi request (/request
path) from within a script. This callback function is unlikely to be called from a Monitor Condition script but is often needed by a Tile Data script.async function toStreamData(data, { rowpath = [], metadata = [] } = {} )
– the asynctoStreamData
callback function can be used to convert non-data stream formatted data into data stream formatted data. This callback function is unlikely to be called from a Monitor Condition script but is often needed by a Tile Data script.async getColumnData(data, columnName)
– thegetColumnData
callback function can be used to obtain the rows of the specified column of data stream formatted data (i.e. thedata
parameter must be data stream formatted data). This callback function is very unlikely to be called from a Tile Data script but is often needed by a Monitor Condition script.
A data stream column always has three properties:
raw
,value
, andformatted
. Thevalue
property is the one to use in scripts as it contains the column’s value as a JavaScript type.
Return value format:
An object with a mandatory state property and an optional scalar property. The scalar property value is the value that caused the returned state, e.g. the value that caused the error state.
Example monitor condition script return values:
Copy// state must be one of 'error', 'warning', 'success', or 'unknown'
return { state: 'unknown' };
return { state: 'success', scalar: 36.53 };
return { state: 'error', scalar: 105 };
return { state: 'warning' };
Using a Monitor Condition script
Add or Edit a dashboard and go into the configuration of a tile.
Configure the data that you want to run the script against in the Data editor tab.
Select the Monitoring tab and then switch Monitoring to on.
Monitor type:
Select script.
Condition script:
Select the Monitor Condition script to run from the dropdown.
Script configuration (optional):
params.config
argument to pass the script. For example, you could use configuration to specify thresholds for the script to use. This allows you to reuse the script for multiple tiles with different thresholds (or other configuration), and avoids having to hardcode values that may change within the script.Frequency:
How often you want to call the script.
Click Save.