Calculate

Function

Calculate new values by combining or aggregating other SKOOR job measurements with Python scripts. One or more filters can be configured to search for jobs by type, name, custom properties or other criteria. All return values or aggregated values of the filtered jobs can be used for calculation

Alarming

Running time, Script time, Error code, Return value <0-n>, String value <0-n>, Job count <0-n>

Calculate jobs may only be created/edited by users of type Administrator since they allow executing arbitrary code on the SKOOR collector or server (in the case of the collector-local).
The executable or code entered in the inline text box is executed with the eranger user’s permissions. Therefore only limited commands can be executed, unless the Linux administrator (root) enables additional commands using e.g. sudo.

Calculate detail

As calculate jobs are running on the server, working with measurements of other jobs, no collector is used for execution. The collector selected in the Job Execution section is irrelevant

To calculate a value, at least one existing SKOOR job must be selected on the system. From this job or jobs, all return values can be used for calculation.

First, a parent object must be selected for the search filters. Click the Browse button and dropdown near Search below to define the parent object. Click the + button near Filter 1 to add more filters if required:

Add or remove filter criteria using the + / - buttons of a filter. In the below example, all Execute jobs are searched with the custom property Kanton set to Zurich:

For each filter, the type of values must be selected now using the Values for script dropdown. The following options are available:

Category

Type

Aggregated

Avgerage, min, max, etc.
Peaks of last hour
Peaks of last 24 hours

For each job

Peaks of last hour
Peaks of last 24 hours
All job values

Finally, click refresh next to the Values dropdown to populate the menu with the available values from the filtered jobs and select one of the values from the dropdown which will then be available for calculation:

Inline script

This section is the main part of the work regarding the calculate job. Now that the job values have been selected, a Python script must be created to do someting with them. Click the information button at the top right corner of the Job Parameters section to open the help page with example scripts:

In the job definition, a template script is provided. This script contains the variable data with all results from the filtered jobs, formatted as JSON. This JSON string looks like the following one, depending on the selected value type and return value (slightly edited for readability):

{
    "arguments": [],
    "thisJob": {
        "type": "jobInfo",
        "jobId": 4769,
        "jobType": 10,
        "jobTypeName": "calculate",
        "jobState": 0,
        "jobStateName": "Undefined",
        "lastTs": 0,
        "values": {}
    },
    "results": [
        {
            "type": "jobAggregateValues",
            "filter": 1,
            "value": "return_value1",
            "count": 43,
            "average": -24882040.997674418,
            "max": 24648.0,
            "min": -1070000000.0
        }
    ],
    "info": [
        {
            "filter": 0,
            "warning": false
        }
    ]
}

JSON element

Description

arguments

Array of arguments added to the script. None have been added in the above example

thisJob

Data of the calculate job itself

results

Values of the resulting jobs per filter. These will be used for calcuation

info

Additional job information. Warning message if for instance no jobs are found by a filter definition

As described also in the job info/help page, with the following line of Python code, the values can be put into SKOOR return values of the calculate job (example corresponds to the above JSON):

setErangerValues(data["results"][0]["average"],data["results"][0]["max"],data["results"][0]["min"])

The required functions to assign SKOOR result values are available in the Tags dropdown. Add arguments and return values below the Inline script field of the configuration: