Ad Widget

Collapse

API - Is it possible to update script in Browser Item via API call

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • milospt1
    Junior Member
    • May 2025
    • 10

    #1

    API - Is it possible to update script in Browser Item via API call

    Hello everyone, thank you for reading this.

    I am wondering is it possible to update a script that is located inside of an Zabbix Item with type Browser? I am utilizing a Website by Browser for a web application monitoring and my end goal is to eventually update a script via Azure DevOps pipeline.
    For the testing purposes I am using Postman to make requests and so far I was able to obtain contents of Browser Item and noticed that the script is stored under params.

    Request example:
    Code:
    {
        "jsonrpc": "2.0",
        "method": "item.get",
        "params": {
            "itemids":"47131"
            },
        "id": 1
    }
    Response that I get from this looks something like following:
    ​​

    Attempts to update script by updating params have failed so far and I am wondering is it even possible to update Browser Items this way or it falls into the lines from zabbix documentation?
    Web items cannot be updated via the Zabbix API.
    Any input and tips are appreciated.
  • Answer selected by milospt1 at 04-07-2025, 15:00.
    milospt1
    Junior Member
    • May 2025
    • 10

    Originally posted by santosra02
    no sure if I got it correctly but did you try Action > Trigger Actions > Create an Action with "Run sript" ?
    Hello santosra02 not related to my problem but I did find a "hack-ish" workaround to update script in Browser item.
    Basically I stored script inside of a JavaScript variable as multi-line string then used function JSON.stringify() on that string variable, copy and paste output of JSON.stringify() into an API request under params and it worked.

    For example:
    Code:
    let myBrowserScript = `// Code updated by API
    const Website = {
        params: {},
        setParams(params) {
            ['scheme', 'domain','width', 'height'].forEach(function (field) {
                if (typeof params !== 'object' || !params[field]) {
                    throw new Error('Required param is not set: ' + field + '.');
                }
            });
            this.params = params;
        }, ... // REMAINING PART OF THE CODE
    `
    let myBrowserScriptJson = JSON.stringify(myBrowserScript);
    My API request looks something like:
    Click image for larger version

Name:	image.png
Views:	57
Size:	36.5 KB
ID:	504881
    Not an elegant solution but it works and I am still learning Zabbix.
    Last edited by milospt1; 04-07-2025, 15:00.

    Comment

    • santosra02
      Junior Member
      • May 2023
      • 21

      #2
      no sure if I got it correctly but did you try Action > Trigger Actions > Create an Action with "Run sript" ?

      Comment

      • milospt1
        Junior Member
        • May 2025
        • 10

        #3
        Originally posted by santosra02
        no sure if I got it correctly but did you try Action > Trigger Actions > Create an Action with "Run sript" ?
        Hello santosra02 not related to my problem but I did find a "hack-ish" workaround to update script in Browser item.
        Basically I stored script inside of a JavaScript variable as multi-line string then used function JSON.stringify() on that string variable, copy and paste output of JSON.stringify() into an API request under params and it worked.

        For example:
        Code:
        let myBrowserScript = `// Code updated by API
        const Website = {
            params: {},
            setParams(params) {
                ['scheme', 'domain','width', 'height'].forEach(function (field) {
                    if (typeof params !== 'object' || !params[field]) {
                        throw new Error('Required param is not set: ' + field + '.');
                    }
                });
                this.params = params;
            }, ... // REMAINING PART OF THE CODE
        `
        let myBrowserScriptJson = JSON.stringify(myBrowserScript);
        My API request looks something like:
        Click image for larger version

Name:	image.png
Views:	57
Size:	36.5 KB
ID:	504881
        Not an elegant solution but it works and I am still learning Zabbix.
        Last edited by milospt1; 04-07-2025, 15:00.

        Comment

        Working...