Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action设置conditions属性无效 #6

Open
826169340 opened this issue Aug 3, 2016 · 2 comments
Open

Action设置conditions属性无效 #6

826169340 opened this issue Aug 3, 2016 · 2 comments

Comments

@826169340
Copy link

新增或更新ActionConditions或OperationConditions均无效

@0312birdzhang
Copy link

测试了一下,可能是zabbix api的问题
测试代码

final String hostId = "10084";
            ActionCreateRequest request = new ActionCreateRequest();
            ActionCreateRequest.Params param = request.createParam();
            param.setName("Action创建测试" + DateUtil.getCurrentDay());
            param.setEventsource(0);
            param.setEvaltype(0);
            param.setStatus(0);
            param.setEsc_period(120);
            param.setDef_shortdata("{TRIGGER.NAME}: {TRIGGER.STATUS}");
            param.setDef_longdata("{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}");

            ActionCondition ac = new ActionCondition();
            ac.setConditiontype(ActionCondition.CONDITION_TYPE_TRIGGER.HOST.value);
            ac.setOperator(ActionCondition.CONDITION_OPERATOR.EQUAL.value);
            ac.setValue(hostId);
            param.addActionConditon(ac);

            ActionOperation ao = new ActionOperation();
            ao.setOperationtype(0);
            ao.setEsc_period(0);
            ao.setEsc_step_from(1);
            ao.setEsc_step_to(2);
            ao.setEvaltype(0);

            OperationMessageGroup omg = new OperationMessageGroup();
            omg.setUsrgrpid(13);
            ao.addOpmessageGrp(omg);

            OperationMessage om = new OperationMessage();
            om.setDefault_msg(1);
            om.setMediatypeid(1);
            ao.setOpmessage(om);
            param.addActionOperation(ao);

            ActionCreateResponse response = zabbixApi.action().create(request);

发送的json数据

{
  "params": [
    {
      "conditions": [
        {
          "conditiontype": 1,
          "value": "10084",
          "operator": 0
        }
      ],
      "operations": [
        {
          "operationtype": 0,
          "esc_period": 0,
          "esc_step_from": 1,
          "esc_step_to": 2,
          "evaltype": 0,
          "opmessage": {
            "default_msg": 1,
            "mediatypeid": 1
          },
          "opmessage_grp": [
            {
              "usrgrpid": 13
            }
          ]
        }
      ],
      "esc_period": 120,
      "evaltype": 0,
      "eventsource": 0,
      "name": "Action创建测试2016-08-29 16:08:42",
      "def_longdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}",
      "def_shortdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}",
      "status": 0
    }
  ],
  "id": 1122868080,
  "jsonrpc": "2.0",
  "method": "action.create",
  "auth": "f6e91311a795ec684d6b4ad04a656703"
}

@0312birdzhang
Copy link

fix https://github.com/0312birdzhang/Zabbix4j/blob/master/src/main/java/com/zabbix4j/action/ActionCreateRequest.java#L69-L100
写的有点乱,自己参考吧。
post数据应该是这样的,特别是filter那里

{
  "params": [
    {
      "filter": {
        "evaltype": 0,
        "conditions": [
          {
            "conditiontype": 1,
            "value": "10084",
            "operator": 0
          },
          {
            "conditiontype": 3,
            "value": "test",
            "operator": 2
          }
        ]
      },
      "operations": [
        {
          "operationtype": 0,
          "esc_period": 0,
          "esc_step_from": 1,
          "esc_step_to": 2,
          "evaltype": 0,
          "opmessage": {
            "default_msg": 1,
            "mediatypeid": 1
          },
          "opmessage_grp": [
            {
              "usrgrpid": 7
            }
          ]
        }
      ],
      "esc_period": 120,
      "evaltype": 0,
      "eventsource": 0,
      "name": "Action创建测试 +++1473758369314",
      "def_longdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}\r\nLast value: {ITEM.LASTVALUE}\r\n\r\n{TRIGGER.URL}",
      "def_shortdata": "{TRIGGER.NAME}: {TRIGGER.STATUS}",
      "status": 0
    }
  ],
  "id": 1642081764,
  "jsonrpc": "2.0",
  "method": "action.create",
  "auth": "1111111111"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants