예제 #1
0
    def update_one(self, group, groupid=None):
        """Update existing host group.

        :type group: dict
        :param group: Paramter of Host group object.

        :type groupid: str
        :param groupid: ID of the host group.

        :rtype: str
        :return: Return single ID of the updated host group.
        """
        name = group['name']
        if groupid is None:
            groupid = self.get_id_by_name(name)

        if groupid is None:
            logger.debug('Not exists({0})'.format(name))
            return None

        params = self.__to_parameters(group)
        params['groupid'] = groupid

        result = self._do_request('hostgroup.update', params)
        return result['groupids'][0] if result else None
예제 #2
0
    def update_one(self, host, hostid=None):
        """Update existing host.

        :type host: dict
        :param host: Paramter of Host object.

        :type hostid: str
        :param hostid: ID of the host.

        :rtype: str
        :return: Return single ID of the updated host.
        """
        name = host['name']
        if hostid is None:
            hostid = self.get_id_by_name(name)

        if hostid is None:
            logger.debug('Not exists({0})'.format(name))
            return None

        params = self.__to_parameters(host)
        params['hostid'] = hostid
        if 'templates_clear' in host:
            templateids = self.__get_templateids(host['templates_clear'])
            params['templates_clear'] = templateids

        result = self._do_request('host.update', params)
        return result['hostids'][0] if result else None
예제 #3
0
    def update_one(self, application, applicationid=None):
        """Update existing application.

        :type application: dict
        :param application: Paramter of Application object.

        :type applicationid: str
        :param applicationid: ID of the application.

        :rtype: str
        :return: Return single ID of the updated application.
        """
        name = application['name']
        hostname = application['host']
        if applicationid is None:
            applicationid = self.get_id_by_name(name, hostname)

        if applicationid is None:
            logger.debug('Not exists({0},{1})'.format(hostname, name))
            return None

        params = self.__to_parameters(application)
        params['applicationid'] = applicationid

        result = self._do_request('application.update', params)
        return result['applicationids'][0] if result else None
예제 #4
0
    def update_one(self, item, itemid=None):
        """Update existing item.

        :type item: dict
        :param item: Paramter of Item object.

        :type itemid: str
        :param itemid: ID of the item.

        :rtype: str
        :return: Return single ID of the updated item.
        """
        key_ = item['key_']
        hostname = item['host']
        if itemid is None:
            itemid = self.get_id_by_key(key_, hostname)

        if itemid is None:
            logger.debug(('Not exists({0}:{1})'.format(hostname, key_)))
            return None

        params = self.__to_parameters(item)
        params['itemid'] = itemid

        result = self._do_request('item.update', params)
        return result['itemids'][0] if result else None
예제 #5
0
    def update_one(self, template, templateid=None):
        """Update existing template.

        :type template: dict
        :param template: Paramter of Template object.

        :type templateid: str
        :param templateid: ID of the template.

        :rtype: str
        :return: Return single ID of the updated template.
        """
        name = template['name']
        if templateid is None:
            templateid = self.get_id_by_name(name)

        if templateid is None:
            logger.debug('Not exists({0})'.format(name))
            return None

        params = self.__to_parameters(template)
        params['templateid'] = templateid
        if 'groups' in template:
            params['groups'] = self.__get_groupids(template['groups'])
        if 'templates_clear' in template:
            ids = self.get_ids_by_name(template['templates_clear'])
            params['templates_clear'] = ids

        result = self._do_request('template.update', params)
        return result['templateids'][0] if result else None
예제 #6
0
    def create_one(self, trigger):
        """Create new trigger.

        :type trigger: dict
        :param trigger: Paramter of Trigger object.

        :rtype: str
        :return: Return single ID of the created trigger.
        """
        triggerid = self.__get_id(trigger)
        if triggerid is not None:
            logger.debug(('Already exists({0})'.format(trigger['expression'])))
            return None

        params = self.__to_parameters(trigger)

        result = self._do_request('trigger.create', params)
        return result['triggerids'][0] if result else None
예제 #7
0
    def create_one(self, host):
        """Create new host.

        :type host: dict
        :param host: Paramter of Host object.

        :rtype: str
        :return: Return single ID of the created host.
        """
        name = host['name']
        hostid = self.get_id_by_name(name)
        if hostid is not None:
            logger.debug('Already exists({0})'.format(name))
            return None

        params = self.__to_parameters(host)

        result = self._do_request('host.create', params)
        return result['hostids'][0] if result else None
예제 #8
0
    def create_one(self, group):
        """Create new host group.

        :type group: dict
        :param group: Paramter of Host group object.

        :rtype: str
        :return: Return single ID of the created host group.
        """
        name = group['name']
        groupid = self.get_id_by_name(name)
        if groupid is not None:
            logger.debug('Already exists({0})'.format(name))
            return None

        params = self.__to_parameters(group)

        result = self._do_request('hostgroup.create', params)
        return result['groupids'][0] if result else None
예제 #9
0
    def _do_request(self, method, params):
        """Make request to Zabbix API.

        :type method: str
        :param method: ZabbixAPI method, like: `apiinfo.version`.

        :type params: str
        :param params: ZabbixAPI method arguments.

        :rtype: list
        :return: Return list of values in `result`.
        """
        try:
            response = self._zbx_api.do_request(method, params)
            logger.debug("Response data: %s", response)
        except ZabbixAPIException as e:
            logger.error('%s', e.args)
            raise Exception('Invalid request')

        return response['result']
예제 #10
0
    def create_one(self, template):
        """Create new template.

        :type template: dict
        :param template: Paramter of Template object.

        :rtype: str
        :return: Return single ID of the created template.
        """
        name = template['name']
        templateid = self.get_id_by_name(name)
        if templateid is not None:
            logger.debug('Already exists({0})'.format(name))
            return None

        params = self.__to_parameters(template)
        params['groups'] = self.__get_groupids(template['groups'])

        result = self._do_request('template.create', params)
        return result['templateids'][0] if result else None
예제 #11
0
    def create_one(self, application):
        """Create new application.

        :type application: dict
        :param application: Paramter of Application object.

        :rtype: str
        :return: Return single ID of the created application.
        """
        name = application['name']
        hostname = application['host']
        applicationid = self.get_id_by_name(name, hostname)
        if applicationid is not None:
            logger.debug('Already exists({0},{1})'.format(hostname, name))
            return None

        params = self.__to_parameters(application)
        params['hostid'] = self.__host.get_id_by_name(hostname)

        result = self._do_request('application.create', params)
        return result['applicationids'][0] if result else None
예제 #12
0
    def create_one(self, item):
        """Create new item.

        :type item: dict
        :param item: Paramter of Item object.

        :rtype: str
        :return: Return single ID of the created item.
        """
        key_ = item['key_']
        hostname = item['host']
        itemid = self.get_id_by_key(key_, hostname)
        if itemid is not None:
            logger.debug(('Already exists({0}:{1})'.format(hostname, key_)))
            return None

        params = self.__to_parameters(item)
        params['hostid'] = self.__host.get_id_by_name(hostname)

        result = self._do_request('item.create', params)
        return result['itemids'][0] if result else None
예제 #13
0
    def update_one(self, trigger, triggerid=None):
        """Update existing trigger.

        :type trigger: dict
        :param trigger: Paramter of Trigger object.

        :type triggerid: str
        :param triggerid: ID of the trigger.

        :rtype: str
        :return: Return single ID of the updated trigger.
        """
        if triggerid is None:
            triggerid = self.__get_id(trigger)

        if triggerid is None:
            logger.debug(('Not exists({0})'.format(trigger['expression'])))
            return None

        params = self.__to_parameters(trigger)
        params['triggerid'] = triggerid

        result = self._do_request('trigger.update', params)
        return result['triggerids'][0] if result else None