Ad Widget

Collapse

Global macro update with API

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • markfree
    Senior Member
    • Apr 2019
    • 868

    #1

    Global macro update with API

    Zabbix 6.2

    Hey guys.
    I'm trying to update a global macro using the Zabbix API.
    For testing, I used the "usermacro.updateglobal" method.

    The script:
    Code:
    #!/bin/bash
    # Zabbix Auth
    ZABBIX_URL="https://zabbix.url/api_jsonrpc.php"
    ZBXTOKEN="zabbix_api_token"
    
    # Global Macro ID to update
    GMACROID_1="4"
    GMACROID_2="5"
    GMACROID_3="6"
    
    # Datas
    DATA1=$(data 1)
    DATA2=$(data 2)
    DATA3=$(data 3)
    
    # Zabbix API payload
    PAYLOAD='{
            "jsonrpc": "2.0",
            "method": "usermacro.updateglobal",
            "params": [{
                    "globalmacroid": "'"${GMACROID_1}"'",
                    "value": "'"${DATA1}"'"
                    },
                    {
                    "globalmacroid": "'"${GMACROID_2}"'",
                    "value": "'"${DATA2}"'"
                    },
                    {
                    "globalmacroid": "'"${GMACROID_3}"'",
                    "value": "'"${DATA3}"'"
                    }],
            "auth": "'"$ZBXTOKEN"'",
            "id": 2
    }'
    
    echo -e "PAYLOAD\n $PAYLOAD"
    
    # Curl response
    RESPONSE="$(curl --silent -k \
            --show-error \
            --request POST \
            --header "Content-Type: application/json" \
            --data "${PAYLOAD}" \
            --url $ZABBIX_URL)"
    
    echo -e "\n\nRESPONSE\n $RESPONSE"
    
    # Erro check
    ERROR=$(echo "${RESPONSE}" | jq -r '.error.message')
    if [ "${ERROR}" != "null" ]; then
            echo -e "\nError Zabbix API:"
            echo "${ERROR}"
            exit 1
    fi
    The actual payload.
    Code:
    {
      "jsonrpc": "2.0",
      "method": "usermacro.updateglobal",
      "params": [{
          "globalmacroid": "4",
          "value": "1"
        },
        {
          "globalmacroid": "5",
          "value": "2"
        },
        {
          "globalmacroid": "6",
          "value": "3"
        }],
      "auth": "1122334455",
      "id": 2
    }
    The issue is that the "usermacro.updateglobal" JSON response is an error.
    Code:
    {"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params.","data":"No permissions to call \"usermacro.updateglobal\"."},"id":2}
    For the "event.acknowledge" method, the requests have no issues, but the same is not true for the​ "usermacro.updateglobal".

    The API user role has the "event.acknowledge" and "usermacro.*" permissions. (there's no "usermacro.updateglobal" available on the list).
    Click image for larger version  Name:	image.png Views:	0 Size:	21.2 KB ID:	477249

    I'm not sure if the issue is related to permissions or an invalid parameter.
    Any thoughts?​
    Last edited by markfree; 16-01-2024, 18:32.
  • Answer selected by markfree at 17-01-2024, 18:20.
    cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    https://www.zabbix.com/documentation...ermacro/update
    This method is only available to Admin and Super admin user types.​
    if you change role type from user to admin (you do not even have to save changes) you get also other usermacro. methods in allow list, if you start typing them...
    Last edited by cyber; 17-01-2024, 11:23.

    Comment


    • markfree
      markfree commented
      Editing a comment
      It was permissions after all. Thanks, buddy.
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    https://www.zabbix.com/documentation...ermacro/update
    This method is only available to Admin and Super admin user types.​
    if you change role type from user to admin (you do not even have to save changes) you get also other usermacro. methods in allow list, if you start typing them...
    Last edited by cyber; 17-01-2024, 11:23.

    Comment


    • markfree
      markfree commented
      Editing a comment
      It was permissions after all. Thanks, buddy.
Working...