Ad Widget

Collapse

zabbix api action create

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dobr0
    Junior Member
    • Sep 2011
    • 5

    #1

    zabbix api action create

    Hello!
    Zabbix Server v1.8.4 (revision 16604) (4 January 2011)
    Use (or rather trying to use the API) class is written in python
    Various scripts. Contribute to gescheit/scripts development by creating an account on GitHub.

    Add a host / data elements is! Why, "butted" to add / update action
    Crashes
    10: Response Body: {u'jsonrpc ': u'2 .0', u'id ': 1, u'error': {u'message ': u'Invalid params.', U'code ': -32602, u 'data': u '[CAction:: create] Incorrect parameter used for Action [12 312]}}
    Traceback (most recent call last):
    File "zabbix_act_create.py", line 9, in <module>
    zapi.action.create ({'name': '12312 '})
    File "/ usr / share / zabbix / zabbix_api.py", line 317, in wrapper
    return self.do_request (self.json_obj (name, opts)) ['result']
    File "/ usr / share / zabbix / zabbix_api.py", line 299, in do_requestevaltype
    return self.parent.do_request (req)
    File "/ usr / share / zabbix / zabbix_api.py", line 264, in do_request
    raise ZabbixAPIException (msg, jobj ['error'] ['code'])
    I write the following code
    zapi.action.create ({'name': "some-name", 'eventsource': 0, 'evaltype': 0, 'status': 0, 'esc_period': 0, 'def_shortdata': "{TRIGGER.NAME }: {TRIGGER.STATUS} ", 'def_longdata':" {TRIGGER.NAME}: {TRIGGER.STATUS} \ r \ nLast value: {ITEM.LASTVALUE} \ r \ n \ r \ n {TRIGGER.URL} ", 'recovery_m sg': 0, 'r_shortdata': "{TRIGGER.NAME}: {TRIGGER.STATUS}", 'r_longdata': "{TRIGGER.NAME}: {TRIGGER.STATUS} \ r \ nLast value: {ITEM . LASTVALUE} \ r \ n \ r \ n {TRIGGER.URL} "})
    Last edited by dobr0; 28-09-2011, 08:58.
  • zabbix_zen
    Senior Member
    • Jul 2009
    • 426

    #2
    Issues in your command:
    • 'recovery_m sg' should have been 'recovery_msg'
    • a list of operations is mandatory
    • should have a list of conditions else it's unmeaningful
    • if you're telling it 'evaltype': 0 (escalations off) then 'esc_period': 0 is unnecessary


    Code:
    # Zabbix constants
    EVENTSOURCE_TRIGGER = 0
    STATUS_ENABLED = 0
    escalations_off = 0
    recovery_msg_off = 0
    
    # Your customizations
    name = 'some-name'
    default_subject = '{TRIGGER.NAME }: {TRIGGER.STATUS}'
    default_message = '''
    {TRIGGER.NAME}: {TRIGGER.STATUS} 
    Last value: {ITEM.LASTVALUE}
    
    {TRIGGER.URL}'''
    
    # Example of some conditions
    CONDITION_OPERATOR_EQUAL = 0
    CONDITION_OPERATOR_LIKE = 2
    CONDITION_TYPE_TRIGGER_NAME = 3
    CONDITION_TYPE_TRIGGER_VALUE = 5
    TRIGGER_VALUE_PROBLEM = 1
    trigger_filter = 'Some part of a Trigger Name'
    OPERATION_TYPE_MESSAGE = 0
    MEDIA_TARGET_USER = 0
    MEDIA_TARGET_USERGROUP = 1
    some_usergroupid = 13
    operation_media_type_SMS = 1
    
    operations_list = [{'objectid': some_usergroupid, 'default_msg': 1, 'object': MEDIA_TARGET_USERGROUP, 'opmediatypes': [{'mediatypeid': operation_media_type_SMS}], 'opconditions': [], 'operationtype': OPERATION_TYPE_MESSAGE, 'evaltype': default_recovery_message}]
    
    conditions_list = [{"operator": CONDITION_OPERATOR_EQUAL, "conditiontype": CONDITION_TYPE_TRIGGER_VALUE, "value": TRIGGER_VALUE_PROBLEM}, {"operator": CONDITION_OPERATOR_LIKE, "conditiontype": CONDITION_TYPE_TRIGGER_NAME, "value": trigger_filter}]
    
    zapi.action.create([{'name': name, 
    'eventsource': EVENTSOURCE_TRIGGER, 
    'evaltype': escalations_off, 
    'status': STATUS_ENABLED, 
    'def_shortdata': default_subject, 
    'def_longdata': default_message, 
    'recovery_msg': recovery_msg_off,
    'operations': operations_list,
    'conditions': conditions_list,
    }])
    And please ask some colleague next time to review your english before posting..

    Comment

    • dobr0
      Junior Member
      • Sep 2011
      • 5

      #3
      zabbix continue api action

      Писал на русском!Это сервис на zabbix.com криво переводит!!!
      Thank you!!

      Comment

      • zabbix_zen
        Senior Member
        • Jul 2009
        • 426

        #4
        Hehe. No problem dobr0.
        Those translating services help but are far from perfect.
        It was just an advice so that fellow Zabbix users can better assist you in the future.

        Glad it was useful.

        Comment

        • dobr0
          Junior Member
          • Sep 2011
          • 5

          #5
          Zabbix

          Originally posted by zabbix_zen
          Hehe. No problem dobr0.
          Those translating services help but are far from perfect.
          It was just an advice so that fellow Zabbix users can better assist you in the future.

          Glad it was useful.
          OK!

          i have the error
          " You do not have permission to perform this operation
          "
          forum, this issue is addressed but in the case with the addition of hosts!The user have permissions Zabbix Administrator and API access.Was doing the following:
          add into second string api/classes/class.caction
          require_ance('include/actions.inc.php')
          like this
          <?php
          require_once('include/actions.inc.php');
          /*
          ** ZABBIX

          Maybe i have curved hands:-)And again Sorry for my english,I'm learning the language
          Very bad No courses in Russia on the monitoring system Zabbix. Sincerely

          Comment

          • zabbix_zen
            Senior Member
            • Jul 2009
            • 426

            #6
            I'm sorry but I really didn't understand.
            Are you trying to create an host using an user with API access?

            If you tried my example, you obviously need to pass IDs which already exist,
            for instance
            Code:
            some_usergroupid = 13
            refers to an existing usergroup with ID 13

            If you post your code maybe someone can help you.

            Comment

            • dobr0
              Junior Member
              • Sep 2011
              • 5

              #7
              Originally posted by zabbix_zen
              I'm sorry but I really didn't understand.
              Are you trying to create an host using an user with API access?

              If you tried my example, you obviously need to pass IDs which already exist,
              for instance
              Code:
              some_usergroupid = 13
              refers to an existing usergroup with ID 13

              If you post your code maybe someone can help you.
              Использую Ваш код, т.к до конца не понимаю еще структуру.
              Конечная цель:
              Добавлять/Обновлять с помощью API Действия и условия к ним
              Ошибка с правами не понятна(You do not have permission to perform this operation while sending )...Какие права?Еcли пользователь, под которым происходит подключение состоит в группе Zabbix Администраторы,API access(исходя из мануала на zabbix.com).

              Вот код :
              server="http://12.34.56.78/zabbix"
              username="user"
              password="userpass"
              zapi = ZabbixAPI(server=server, path="", log_level=8)
              zapi.login(username,password)
              # Zabbix constants
              EVENTSOURCE_TRIGGER = 0
              STATUS_ENABLED = 0
              escalations_off = 0
              recovery_msg_off = 0

              name = 'some-name'
              default_subject = '{TRIGGER.NAME }: {TRIGGER.STATUS}'
              default_message = '''
              {TRIGGER.NAME}: {TRIGGER.STATUS}
              Last value: {ITEM.LASTVALUE}

              {TRIGGER.URL}'''
              default_recovery_message = 0
              CONDITION_OPERATOR_EQUAL = 0
              CONDITION_OPERATOR_LIKE = 2
              CONDITION_TYPE_TRIGGER_NAME = 3
              CONDITION_TYPE_TRIGGER_VALUE = 5
              TRIGGER_VALUE_PROBLEM = 1
              trigger_filter = 'Host information was changed on {HOSTNAME}'
              OPERATION_TYPE_MESSAGE = 0
              MEDIA_TARGET_USER = 0
              MEDIA_TARGET_USERGROUP = 0
              some_usergroupid = 10
              operation_media_type_SMS = 100100000000001

              operations_list = [{'objectid': some_usergroupid, 'default_msg': 1, 'object': MEDIA_TARGET_USERGROUP,'opmediatypes': [{'mediatypeid': operation_media_type_SMS}], 'opconditions': [], 'operationtype': OPERATION_TYPE_MESSAGE, 'evaltype': default_recovery_message}]

              conditions_list = [{"operator": CONDITION_OPERATOR_EQUAL, "conditiontype": CONDITION_TYPE_TRIGGER_VALUE, "value": TRIGGER_VALUE_PROBLEM}, {"operator": CONDITION_OPERATOR_LIKE, "conditiontype": CONDITION_TYPE_TRIGGER_NAME, "value": trigger_filter}]

              zapi.action.create([{'name': name,
              'eventsource': EVENTSOURCE_TRIGGER,
              'evaltype': escalations_off,
              'status': STATUS_ENABLED,
              'def_shortdata': default_subject,
              'def_longdata': default_message,
              'recovery_msg': recovery_msg_off,
              'operations': operations_list,
              'conditions': conditions_list,
              }])
              Ошибка :
              reate", "auth": "4ee745858283a891cd2bdd6b69447871", "id": 1}
              10: Sending headers: {'Content-Type': 'application/json-rpc', 'User-Agent': 'python/zabbix_api'}
              20: Response Code: 200
              10: Response Body: {u'jsonrpc': u'2.0', u'id': 1, u'error': {u'message': u'Application error.', u'code': -32500, u'data': u'[ CAction::create ] You do not have permission to perform this operation'}}
              Traceback (most recent call last):
              File "zabbix_act_create.py", line 53, in <module>
              'conditions': conditions_list,
              File "/usr/share/zabbix/zabbix_api.py", line 290, in wrapper
              return self.do_request(self.json_obj(name,opts))['result']
              File "/usr/share/zabbix/zabbix_api.py", line 272, in do_request
              return self.parent.do_request(req)
              File "/usr/share/zabbix/zabbix_api.py", line 237, in do_request
              raise ZabbixAPIException(msg,jobj['error']['code'])
              zabbix_api.ZabbixAPIException: (u'Error -32500: Application error., [ CAction::create ] You do not have permission to perform this operation while sending {"params": [{"status": 0, "operations": [{"objectid": 10, "default_msg": 1, "object": 0, "opmediatypes": [{"mediatypeid": 100100000000001}], "opconditions": [], "operationtype": 0, "evaltype": 0}], "def_shortdata": "{TRIGGER.NAME }: {TRIGGER.STATUS}", "eventsource": 0, "name": "some-name", "evaltype": 0, "conditions": [{"operator": 0, "conditiontype": 5, "value": 1}, {"operator": 2, "conditiontype": 3, "value": "Host information was changed on {HOSTNAME}"}], "def_longdata": "\\n{TRIGGER.NAME}: {TRIGGER.STATUS} \\nLast value: {ITEM.LASTVALUE}\\n\\n{TRIGGER.URL}", "recovery_msg": 0}], "jsonrpc": "2.0", "method": "action.create", "auth": "4ee745858283a891cd2bdd6b69447871", "id": 1}', -32500)

              Comment

              • zabbix_zen
                Senior Member
                • Jul 2009
                • 426

                #8
                That's a generic error.
                In this case it most certainly means some chosen argument does not exist with that ID.
                You must guarantee all those objects exist.

                Start building the Action with less parameters (example: without conditions) and when an Action creation succeeds, experiment adding one parameter at a time.

                Comment

                Working...