def check_difference(self, **kwargs):
     """Check difference between discovery rule and user specified parameters.
     Args:
         **kwargs: Arbitrary keyword parameters.
     Returns:
         dict: dictionary of differences
     """
     existing_drule = zabbix_utils.helper_convert_unicode_to_str(self.check_if_drule_exists(kwargs['name'])[0])
     parameters = zabbix_utils.helper_convert_unicode_to_str(self._construct_parameters(**kwargs))
     change_parameters = {}
     if existing_drule['nextcheck']:
         existing_drule.pop('nextcheck')
     _diff = zabbix_utils.helper_cleanup_data(compare_dictionaries(parameters, existing_drule, change_parameters))
     return _diff
    def construct_the_data(self, _tag_filters):
        """Construct the user defined tag filters to fit the Zabbix API requirements

        Parameters:
            _tag_filters: tag filters to construct

        Returns:
            dict: user defined tag filters
        """
        if _tag_filters is None:
            return []
        constructed_data = []
        for tag_filter in _tag_filters:
            constructed_tag_filter = {
                'groupid': self.get_hostgroup_by_hostgroup_name(tag_filter.get('host_group'))['groupid'],
                'tag': tag_filter.get('tag'),
                'value': tag_filter.get('value')
            }
            constructed_data.append(constructed_tag_filter)
        return zabbix_utils.helper_cleanup_data(constructed_data)
    def construct_the_data(self, _rights):
        """Construct the user defined rights to fit the Zabbix API requirements

        Parameters:
            _rights: rights to construct

        Returns:
            dict: user defined rights
        """
        if _rights is None:
            return []
        constructed_data = []
        for right in _rights:
            constructed_right = {
                'id': self.get_hostgroup_by_hostgroup_name(right.get('host_group'))['groupid'],
                'permission': zabbix_utils.helper_to_numeric_value([
                    'denied',
                    None,
                    'read-only',
                    'read-write'], right.get('permission')
                )
            }
            constructed_data.append(constructed_right)
        return zabbix_utils.helper_cleanup_data(constructed_data)
 def construct_the_data(self, _dchecks):
     """Construct the user defined discovery check to fit the Zabbix API
     requirements
     Args:
         _dchecks: discovery checks to construct
     Returns:
         dict: user defined discovery checks
     """
     if _dchecks is None:
         return None
     constructed_data = []
     for check in _dchecks:
         constructed_check = {
             'type': zabbix_utils.helper_to_numeric_value([
                 'SSH',
                 'LDAP',
                 'SMTP',
                 'FTP',
                 'HTTP',
                 'POP',
                 'NNTP',
                 'IMAP',
                 'TCP',
                 'Zabbix',
                 'SNMPv1',
                 'SNMPv2',
                 'ICMP',
                 'SNMPv3',
                 'HTTPS',
                 'Telnet'], check.get('type')
             ),
             'uniq': int(check.get('uniq'))
         }
         if LooseVersion(self._zbx_api_version) >= LooseVersion('4.4'):
             constructed_check.update({
                 'host_source': zabbix_utils.helper_to_numeric_value([
                     'None',
                     'DNS',
                     'IP',
                     'discovery'], check.get('host_source')
                 ),
                 'name_source': zabbix_utils.helper_to_numeric_value([
                     'None',
                     'DNS',
                     'IP',
                     'discovery'], check.get('name_source')
                 )
             })
         if constructed_check['type'] in (0, 1, 2, 3, 4, 5, 6, 7, 8, 14, 15):
             constructed_check['ports'] = check.get('ports')
         if constructed_check['type'] == 9:
             constructed_check['ports'] = check.get('ports')
             constructed_check['key_'] = check.get('key')
         if constructed_check['type'] in (10, 11):
             constructed_check['ports'] = check.get('ports')
             constructed_check['snmp_community'] = check.get('snmp_community')
             constructed_check['key_'] = check.get('key')
         if constructed_check['type'] == 13:
             constructed_check['ports'] = check.get('ports')
             constructed_check['key_'] = check.get('key')
             constructed_check['snmpv3_contextname'] = check.get('snmpv3_contextname')
             constructed_check['snmpv3_securityname'] = check.get('snmpv3_securityname')
             constructed_check['snmpv3_securitylevel'] = zabbix_utils.helper_to_numeric_value([
                 'noAuthNoPriv',
                 'authNoPriv',
                 'authPriv'], check.get('snmpv3_securitylevel')
             )
             if constructed_check['snmpv3_securitylevel'] in (1, 2):
                 constructed_check['snmpv3_authprotocol'] = zabbix_utils.helper_to_numeric_value([
                     'MD5',
                     'SHA'], check.get('snmpv3_authprotocol')
                 )
                 constructed_check['snmpv3_authpassphrase'] = check.get('snmpv3_authpassphrase')
             if constructed_check['snmpv3_securitylevel'] == 2:
                 constructed_check['snmpv3_privprotocol'] = zabbix_utils.helper_to_numeric_value([
                     'DES',
                     'AES'], check.get('snmpv3_privprotocol')
                 )
                 constructed_check['snmpv3_privpassphrase'] = check.get('snmpv3_privpassphrase')
         constructed_data.append(constructed_check)
     return zabbix_utils.helper_cleanup_data(constructed_data)