[ZBX-9411] SQL Error when calling action.create API method Created: 2015 Mar 18  Updated: 2017 May 30  Resolved: 2016 Jan 25

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 2.4.3
Fix Version/s: None

Type: Incident report Priority: Minor
Reporter: Kevin Daudt Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: dm, sql
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux / Mysql 5.6


Issue Links:
Duplicate
duplicates ZBX-3783 Proper API validation Reopened

 Description   

I'm using the API to create an action, which works on a different system, but on our production system, it results in an SQL error when trying to insert a row in the opmessage_usr table,

When manually executing, the error is this:

ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`zabbix`.`opmessage_usr`, CONSTRAINT `c_opmessage_usr_1` FOREIGN KEY (`operationid`) REFERENCES `operations` (`operationid`) ON DELETE CASCADE)

This regards an instance where once an extra node was present, but deactivated, and has since been migrated to 2.4

The complete API request + response can be found here:

http://hastebin.com/umivozonud.tex



 Comments   
Comment by Kevin Daudt [ 2015 Mar 19 ]

The hastebin url apparently has expired.

Here is a new version:

https://gist.github.com/Ikke/e0af80ca0d0dae08b0f1

Comment by richlv [ 2015 Mar 19 ]

as per https://www.zabbix.org/wiki/Docs/bug_reporting_guidelines#Reporting_an_issue, reposting request/response contents here

request :

{
    "auth": "hash",
    "id": 1,
    "jsonrpc": "2.0",
    "method": "action.create",
    "params": {
        "def_longdata": "Trigger: {TRIGGER.NAME}\nTrigger status: {TRIGGER.STATUS}\nTrigger severity: {TRIGGER.SEVERITY}\nTrigger URL: {TRIGGER.URL}\n\nItem values:\n\n1. {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\n2. {ITEM.NAME2} ({HOST.NAME2}:{ITEM.KEY2}): {ITEM.VALUE2}\n3. {ITEM.NAME3} ({HOST.NAME3}:{ITEM.KEY3}): {ITEM.VALUE3}\n\nOriginal event ID: {EVENT.ID}",
        "def_shortdata": "{TRIGGER.STATUS}: {TRIGGER.NAME}",
        "esc_period": 300,
        "eventsource": 0,
        "filter": {
            "conditions": [
                {
                    "conditiontype": 16,
                    "formulaid": "A",
                    "operator": 7,
                    "value": ""
                },
                {
                    "conditiontype": 5,
                    "formulaid": "B",
                    "operator": 0,
                    "value": "1"
                }
            ],
            "evaltype": 3,
            "formula": "A and B"
        },
        "name": "_UserSubscriptions_user",
        "operations": [
            {
                "esc_period": 0,
                "esc_step_from": 2,
                "esc_step_to": 2,
                "operationtype": 0,
                "opmessage": {
                    "default_msg": 1,
                    "mediatypeid": 0
                },
                "opmessage_usr": {
                    "userid": "100100000000059"
                }
            }
        ],
        "r_longdata": "Trigger: {TRIGGER.NAME}\nTrigger status: {TRIGGER.STATUS}\nTrigger severity: {TRIGGER.SEVERITY}\nTrigger URL: {TRIGGER.URL}\n\nItem values:\n\n1. {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\n2. {ITEM.NAME2} ({HOST.NAME2}:{ITEM.KEY2}): {ITEM.VALUE2}\n3. {ITEM.NAME3} ({HOST.NAME3}:{ITEM.KEY3}): {ITEM.VALUE3}\n\nOriginal event ID: {EVENT.ID}",
        "r_shortdata": "Solved: {TRIGGER.STATUS}: {TRIGGER.NAME}",
        "recovery_msg": 1
    }
}

response :

{
    "error": {
        "code": -32500,
        "data": "SQL statement execution has failed \"INSERT INTO opmessage_usr (operationid,userid,opmessage_usrid) VALUES ('200200000000022','1','100100000000169')\".",
        "message": "Application error."
    },
    "id": 1,
    "jsonrpc": "2.0"
}
Comment by Kevin Daudt [ 2015 Mar 20 ]

After debugging the zabbix API code, I found out that

"opmessage_usr": {
    "userid": "100100000000059"
}

is incorrect, it should be an array of users, not a user object.

Perhaps some extra validation could help to catch these kinds of errors.

Comment by Aleksandrs Saveljevs [ 2016 Jan 25 ]

Let's close as a duplicate of ZBX-3783 then.

Generated at Fri Apr 26 22:31:54 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.