Ensures that the mediatype does not exist, eventually deletes the mediatype.

    :param name: name of the usermacro
    :param hostid: id's of the hosts to apply the usermacro on, if missing a global usermacro is assumed.

    :param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring)
    :param _connection_password: Optional - zabbix password (can also be set in opts or pillar, see module's docstring)
    :param _connection_url: Optional - url of zabbix frontend (can also be set in opts, pillar, see module's docstring)

    .. code-block:: yaml

        delete_usermacro:
            zabbix_usermacro.absent:
                - name: '{$SNMP_COMMUNITY}'

def absent(name, hostid=None, **kwargs):
    '''
    Ensures that the mediatype does not exist, eventually deletes the mediatype.

    :param name: name of the usermacro
    :param hostid: id's of the hosts to apply the usermacro on, if missing a global usermacro is assumed.

    :param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring)
    :param _connection_password: Optional - zabbix password (can also be set in opts or pillar, see module's docstring)
    :param _connection_url: Optional - url of zabbix frontend (can also be set in opts, pillar, see module's docstring)

    .. code-block:: yaml

        delete_usermacro:
            zabbix_usermacro.absent:
                - name: '{$SNMP_COMMUNITY}'

    '''
    connection_args = {}
    if '_connection_user' in kwargs:
        connection_args['_connection_user'] = kwargs['_connection_user']
    if '_connection_password' in kwargs:
        connection_args['_connection_password'] = kwargs['_connection_password']
    if '_connection_url' in kwargs:
        connection_args['_connection_url'] = kwargs['_connection_url']

    ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}

    # Comment and change messages
    if hostid:
        comment_usermacro_deleted = 'Usermacro {0} deleted from hostid {1}.'.format(name, hostid)
        comment_usermacro_notdeleted = 'Unable to delete usermacro: {0} from hostid {1}.'.format(name, hostid)
        comment_usermacro_notexists = 'Usermacro {0} does not exist on hostid {1}.'.format(name, hostid)
        changes_usermacro_deleted = {name: {'old': 'Usermacro {0} exists on hostid {1}.'.format(name, hostid),
                                            'new': 'Usermacro {0} deleted from {1}.'.format(name, hostid),
                                            }
                                     }
    else:
        comment_usermacro_deleted = 'Usermacro {0} deleted.'.format(name)
        comment_usermacro_notdeleted = 'Unable to delete usermacro: {0}.'.format(name)
        comment_usermacro_notexists = 'Usermacro {0} does not exist.'.format(name)
        changes_usermacro_deleted = {name: {'old': 'Usermacro {0} exists.'.format(name),
                                            'new': 'Usermacro {0} deleted.'.format(name),
                                            }
                                     }
    if hostid:
        usermacro_exists = __salt__['zabbix.usermacro_get'](name, hostids=hostid, **connection_args)
    else:
        usermacro_exists = __salt__['zabbix.usermacro_get'](name, globalmacro=True, **connection_args)

    # Dry run, test=true mode
    if __opts__['test']:
        if not usermacro_exists:
            ret['result'] = True
            ret['comment'] = comment_usermacro_notexists
        else:
            ret['result'] = None
            ret['comment'] = comment_usermacro_deleted
        return ret

    if not usermacro_exists:
        ret['result'] = True
        ret['comment'] = comment_usermacro_notexists
    else:
        try:
            if hostid:
                usermacroid = usermacro_exists[0]['hostmacroid']
                usermacro_delete = __salt__['zabbix.usermacro_delete'](usermacroid, **connection_args)
            else:
                usermacroid = usermacro_exists[0]['globalmacroid']
                usermacro_delete = __salt__['zabbix.usermacro_deleteglobal'](usermacroid, **connection_args)
        except KeyError:
            usermacro_delete = False

        if usermacro_delete and 'error' not in usermacro_delete:
            ret['result'] = True
            ret['comment'] = comment_usermacro_deleted
            ret['changes'] = changes_usermacro_deleted
        else:
            ret['result'] = False
            ret['comment'] = comment_usermacro_notdeleted + six.text_type(usermacro_delete['error'])

    return ret