Execution of scripts

WOCU-Monitoring offers the possibility to run scripts previously loaded into the system by an Administrator.

Loading scripts

For a script to be available, it must be placed in the following directory:

/opt/wocu/embedded/wocu/script_launcher/scripts/

Once copied, execution permissions must be granted (if not previously available).

In order for scripts to run correctly, they must meet the following conditions:

  • The script name must not contain spaces.

  • They must not generate or modify intermediate or output files during their execution.

  • They must manage internally the presence or absence of parameters.

  • It is necessary to implement a proper deadlock management, preventing situations that can cause timeouts.

Automatic parameter collection

In order for the system to identify and add parameters automatically, it is necessary to include one or more specific lines within the script.

Each of them must begin with the prefix ##autoload__parameter followed by the variable name.

Here are some examples of how to define parameters within a script:

  • Parameter host_name

##__autoload__parameter__host_name
  • Parameter service name

##__autoload__parameter__service name
  • Parameter Stop Condition

##__autoload__parameter__Stop Condition

As can be seen, parameter names may contain spaces.

Example

In the following script, two input parameters are defined that will later be displayed in the form that will allow its execution.

#!/bin/bash

##__autoload__parameter__host1
##__autoload__parameter__host2
##__autoload__parameter__Stop Condition

# Nota: El tercer parámetro no se usa en el script

host1=$1
host2=$2

echo "Primero el parámetro host1: ${host1}"
ping -c1 ${host1}
echo "Después el parámetro host2 ${host2}"
ping -c1 ${host2}

Execution of a script

La funcionalidad está preparada para cargar, actualizar y retirar scripts automáticamente.

Each time the Advanced Diagnostic window is accessed, the system performs a reload process that detects any changes made to the scripts.

This process is executed automatically and transparently, without requiring manual intervention. The following is a description of how it works.

  • First, access Advanced Diagnostic, which can be found under the Settings drop-down menu.

    ../../_images/2_007o_setting_61.png
  • Once there, a drop-down will be displayed with the list of scripts loaded in the system.

    ../../_images/2_007p_aggregator_advanced_diagnostic_view_0-65.png
  • After selecting a script from the list, as many fields will appear as parameters have been defined using the method shown above.

    ../../_images/2_007q_aggregator_advanced_diagnostic_form_0-65.png
  • Additionally, a file selector will appear that allows the upload of a parameter file, in CSV format.

At this point, there are two possible ways of executing the script, each of which has implications for the outcome.

Execution with manually specified parameters

This type of execution refers to the one that receives the necessary parameters for the script based on the information entered by the administrator in the fields of the Parameters section.

../../_images/2_007r_aggregator_advanced_diagnostic_form_0-65.png

The output displayed includes all the information generated during the execution, including the main messages, possible errors and an indicator reflecting the final result of the process.

../../_images/2_007s_aggregator_advanced_diagnostic_form_0-65.png

Execution with file-loaded parameters

In this use case, the administrator is expected to upload a CSV file with headers.

The file must contain as many columns as the number of parameters supported by the script and each row will represent one execution of the script with that set of parameters.

../../_images/2_007t_aggregator_advanced_diagnostic_csv_0-65.png

The return in this type of execution is a text file with extension txt. In this file you will find an entry for each run carried out, i.e. for each row of the CSV file, not counting the headers.

Example

JSON

    // Execution date: 2025-03-14 12:29:13

    {
    "1": {
        "parameters": [
            "www.example.es",
            "www.example.com",
            "42"
        ],
        "output": [
            "Primero el parámetro host1: www.example.es",
            "PING www.example.es (185.53.177.53) 56(84) bytes of data.",
            "64 bytes from 185.53.177.53 (185.53.177.53): icmp_seq=1 ttl=48 time=45.9 ms",
            "",
            "--- www.example.es ping statistics ---",
            "1 packets transmitted, 1 received, 0% packet loss, time 0ms",
            "rtt min/avg/max/mdev = 45.860/45.860/45.860/0.000 ms",
            "Después el parámetro host2 www.example.com",
            "PING a1422.dscr.akamai.net (2.22.146.153) 56(84) bytes of data.",
            "64 bytes from a2-22-146-153.deploy.static.akamaitechnologies.com (2.22.146.153): icmp_seq=1 ttl=55 time=13.8 ms",
            "",
            "--- a1422.dscr.akamai.net ping statistics ---",
            "1 packets transmitted, 1 received, 0% packet loss, time 0ms",
            "rtt min/avg/max/mdev = 13.836/13.836/13.836/0.000 ms",
            ""
        ],
        "errors": [
            ""
        ],
        "return_code": 0
    },
    "2": {
        "parameters": [
            "8.8.8.8",
            "8.8.4.4",
            "41"
        ],
        "output": [
            "Primero el parámetro host1: 8.8.8.8",
            "PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.",
            "64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=14.5 ms",
            "",
            "--- 8.8.8.8 ping statistics ---",
            "1 packets transmitted, 1 received, 0% packet loss, time 0ms",
            "rtt min/avg/max/mdev = 14.501/14.501/14.501/0.000 ms",
            "Después el parámetro host2 8.8.4.4",
            "PING 8.8.4.4 (8.8.4.4) 56(84) bytes of data.",
            "64 bytes from 8.8.4.4: icmp_seq=1 ttl=117 time=13.3 ms",
            "",
            "--- 8.8.4.4 ping statistics ---",
            "1 packets transmitted, 1 received, 0% packet loss, time 0ms",
            "rtt min/avg/max/mdev = 13.283/13.283/13.283/0.000 ms",
            ""
        ],
        "errors": [
            ""
        ],
        "return_code": 0
        }
    }