Ad Widget

Collapse

Failing to create/update action using the API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vkabakov
    Junior Member
    • Jan 2017
    • 5

    #1

    Failing to create/update action using the API

    Hello Everyone,
    The problem is with the users in operations(in the Action).

    This is the third time I am encountering this problem and at this point I do not know what is going on. The only way I found to fix it is to make fresh new Zabbix server install. Deleting all hosts,users,actions .. is not fixing the problem. Only fresh new install is fixing it.

    I am developing small PHP app/module which uses Zabbix API. And at some point something is getting messed up inside the Zabbix DB. Any new user that I create cannot be assigned to any Action/Operations. When I try to associate the user with an Action, instead this user. it tries to add user Admin(id:1). I know that this sounds non-sense, but some association somewhere is getting messed up in the DB. If I have more than one user it fails to enter the record in the db, because it is duplicate(for user Admin(id:1)):

    Application error. [data] => SQL statement execution has failed "INSERT INTO opmessage_usr (operationid,userid,opmessage_usrid) VALUES ('52','1','52')". ) [id] => 1 )

    The API call is fine, because initially it works fine. But during the development and some errors here and there something in the DB is getting messed up and from there only fresh new install is fixing it.

    Here is the call(but it fails for 'action.update' too):


    $json=array(
    "method"=>'action.create',
    "params"=>array(
    'name'=>$this->name,
    'eventsource'=>$this->eventsource,
    'esc_period'=>$this->esc_period,
    'def_shortdata'=>$this->def_shortdata,
    'def_longdata'=>$this->def_longdata,
    'status'=>$this->status,
    'filter'=>$this->filter,
    'operations'=>$this->operations
    ),
    "id"=>1
    );



    When the problem starts , it starts to fail in 'operations' -> 'opmessage_usr' part : $this->operations is :

    Array (
    [operationtype] => 0
    [esc_period] => 0
    [esc_step_from] => 1
    [esc_step_to] => 2
    [evaltype] => 0
    [opmessage_usr] => Array ( [0] => 4 [1] => 5 [2] => 6 [3] => 15 [4] => 16 )
    [opmessage] => Array ( [default_msg] => 1 [mediatypeid] => 1 ) )

    So even that I am specifying that I want to use users with IDs 4,5,6,15,16 it tries to add only user with ID:1 and after the second entry fails with the SQL statement error , because the user is duplicate.


    Any ideas why it would try to add user Admin(id:1) (instead the user with ID 4 as am I specifying)) ? Any ideas are very welcome.

    Note: Like I said it must be some relationship in the DB, because after fresh new Zabbix server install everything works fine for a while, so the problem is not the API calls.


    Thank you for any suggestions or ideas.
    Last edited by vkabakov; 14-09-2017, 14:43.
  • vkabakov
    Junior Member
    • Jan 2017
    • 5

    #2
    Here is the mysql query log showing the problem:

    I am trying to associate to the action users with IDs ('6','15','17'), but instead that it tries to add users with IDs 6 , 1(Admin), 1(Admin) . Users 15 and 17 has been created after the problem starts. User with ID 6 has been created before the problem to occur.



    370 Connect zabbix@localhost as anonymous on zabbix
    370 Query set autocommit=1
    370 Query SET NAMES utf8
    370 Query SHOW TABLES LIKE 'dbversion'
    370 Query SELECT dv.mandatory,dv.optional FROM dbversion dv
    370 Query SELECT NULL FROM config c
    370 Query SELECT u.userid,u.autologout,s.lastaccess FROM sessions s,users u WHERE s.sessionid='6cb14ced3ef023a30349dd6b929ebe25' AND s.status=0 AND s.userid=u.userid AND (s.lastaccess+u.autologout>1505398365 OR u.autologout=0)
    370 Query SELECT MAX(g.gui_access) AS gui_access FROM usrgrp g,users_groups ug WHERE ug.userid='3' AND g.usrgrpid=ug.usrgrpid
    370 Query SELECT u.userid,u.alias,u.name,u.surname,u.url,u.autologi n,u.autologout,u.lang,u.refresh,u.type, u.theme,u.attempt_failed,u.attempt_ip,u.attempt_cl ock,u.rows_per_page FROM users u WHERE u.userid='3'
    370 Query SELECT ug.userid FROM usrgrp g,users_groups ug WHERE ug.userid='3' AND g.usrgrpid=ug.usrgrpid AND g.debug_mode=1
    370 Query BEGIN
    370 Query SELECT a.* FROM actions a WHERE a.actionid='23'
    370 Query SELECT t.conditionid,t.actionid,t.conditiontype,t.operato r,t.value,t.value2 FROM conditions t WHERE t.actionid='23'
    370 Query SELECT t.* FROM operations t WHERE t.actionid='23' AND t.recovery='0'
    370 Query SELECT op.* FROM opconditions op WHERE op.operationid='56'
    370 Query SELECT o.operationid,o.default_msg,o.subject,o.message,o. mediatypeid FROM opmessage o WHERE operationid='56'
    370 Query SELECT og.operationid,og.usrgrpid FROM opmessage_grp og WHERE operationid='56'
    370 Query SELECT ou.operationid,ou.userid FROM opmessage_usr ou WHERE operationid='56'
    370 Query SELECT t.* FROM operations t WHERE t.actionid='23' AND t.recovery='1'
    370 Query SELECT op.* FROM opconditions op WHERE 1=0
    370 Query SELECT COUNT(DISTINCT u.userid) AS rowscount FROM users u WHERE u.userid IN ('6','15','17')
    370 Query UPDATE actions SET def_shortdata='{HOST.HOST} - {TRIGGER.NAME} : {TRIGGER.STATUS}',def_longdata='\n\nHost: {HOST.HOST}\nMonitor: {TRIGGER.NAME}\nStatus: {TRIGGER.STATUS}\nDate: {DATE}\nTime: {TIME}\n\nCurrent Value: {ITEM.LASTVALUE}\n\n ' WHERE actionid='23'
    370 Query SELECT nextid FROM ids WHERE table_name='operations' AND field_name='operationid' FOR UPDATE
    370 Query UPDATE ids SET nextid=57 WHERE table_name='operations' AND field_name='operationid'
    370 Query INSERT INTO operations (operationtype,esc_period,esc_step_from,esc_step_t o,evaltype,actionid,recovery,operationid) VALUES ('0','0','1','2','0','23','0','57')
    370 Query INSERT INTO opmessage (default_msg,mediatypeid,operationid,message) VALUES ('1','1','57','')
    370 Query SELECT nextid FROM ids WHERE table_name='opmessage_usr' AND field_name='opmessage_usrid' FOR UPDATE
    370 Query UPDATE ids SET nextid=59 WHERE table_name='opmessage_usr' AND field_name='opmessage_usrid'
    370 Query INSERT INTO opmessage_usr (operationid,userid,opmessage_usrid) VALUES ('57','6','57')
    370 Query INSERT INTO opmessage_usr (operationid,userid,opmessage_usrid) VALUES ('57','1','58')
    370 Query INSERT INTO opmessage_usr (operationid,userid,opmessage_usrid) VALUES ('57','1','59')

    370 Query ROLLBACK
    370 Quit

    Comment

    • vkabakov
      Junior Member
      • Jan 2017
      • 5

      #3
      This is a bug and I have reported it.

      When you are assigning users to operations(in Actions) it cuts only the first character from the userID. For example if you want to assign user with userID 15 it will get only 1 from it and it will add userID 1. This is happening only using the API.

      Comment

      Working...