Ad Widget

Collapse

Creating actions through the API with mediatypeid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaragunde
    Junior Member
    • Jan 2011
    • 13

    #1

    Creating actions through the API with mediatypeid

    Hi everybody,

    I have a Zabbix 1.8.4 deployment, and lately I've been struggling to create an action from the API, in which the operations use only an specific media type. The example in the API documentation looks like this:

    Code:
    {
    "jsonrpc":"2.0",
    "method":"action.create",
    "params":[{
        "name":"ZABBIX ACTION",
        ...
        "conditions":[...],
        "operations":[{
            ...
            "opmediatypes":[{
                "mediatypeid":"100100000000001"
            }]
        }, ...]
    }],
    "auth":"038e1d7b1735c6a5436ee9eae095879e",
    "id":2
    }
    As you can see, the mediatypeid is passed inside a parameter called opmediatypes, which is in turn an array. However, it didn't work; it seemed like the parameter opmediatypes was ignored.

    After hacking a bit around the code of the frontend, I realized that the correct way to create an action like I wanted was:

    Code:
    {
    "jsonrpc":"2.0",
    "method":"action.create",
    "params":[{
        "name":"ZABBIX ACTION",
        ...
        "conditions":[...],
        "operations":[{
            ...
            "mediatypeid":"100100000000001"
        }, ...]
    }],
    "auth":"038e1d7b1735c6a5436ee9eae095879e",
    "id":2
    }
    That's it. Just pass mediatypeid as one more parameter in the operation object.

    However, I warn you that if you use action.get to retrieve the action you've just created, you will receive an object like this:

    Code:
    {
    "jsonrpc":"2.0",
    "result":[{
        "name":"ZABBIX ACTION",
        ...
        "conditions":[...],
        "operations":[{
            "operationid":"189",
            ...
            "opmediatypes":[{
                "opmediatypeid":"12",
                "operationid":"189",
                "mediatypeid":"100100000000001"
            }]
        }, ...]
    }],
    "id":2
    }
    Yes, the mediatypeid is again inside opmediatypes array.

    I share this recipe with you because it's a bit obscure. Maybe it could be thought it's a bug, isn't it?
    Last edited by jaragunde; 12-07-2011, 14:50. Reason: Corrected an error in the example code.
  • walterheck
    Senior Member
    • Jul 2009
    • 153

    #2
    Ran into this one..

    We ran into this one, as well as one with conditiontypes not being updated properly. Also, when you update an action, it omits the operations that were defined on it. Quite annoying and I hope things will be fixed by 2.0
    Free and Open Source Zabbix Templates Repository | Hosted Zabbix @ Tribily (http://tribily.com)

    Comment

    Working...