diff --git a/apps/assets/forms/asset.py b/apps/assets/forms/asset.py index 69e64ceaf..c8afa6306 100644 --- a/apps/assets/forms/asset.py +++ b/apps/assets/forms/asset.py @@ -68,6 +68,8 @@ class AssetCreateForm(OrgModelForm): 'nodes': _("Node"), } help_texts = { + 'hostname': _('Only Numbers, letters, and characters ( {} ) ' + 'are allowed').format(" ".join(['.', '_', '@'])), 'admin_user': _( 'root or other NOPASSWD sudo privilege user existed in asset,' 'If asset is windows or other set any one, more see admin user left menu' diff --git a/apps/assets/serializers/asset.py b/apps/assets/serializers/asset.py index f67521c3d..f9f099ba8 100644 --- a/apps/assets/serializers/asset.py +++ b/apps/assets/serializers/asset.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # +import re from rest_framework import serializers from django.db.models import Prefetch from django.utils.translation import ugettext_lazy as _ @@ -91,6 +92,15 @@ class AssetSerializer(BulkOrgResourceModelSerializer): 'org_name': {'label': _('Org name')} } + @staticmethod + def validate_hostname(hostname): + pattern = r"^[\._@a-zA-Z0-9-]+$" + res = re.match(pattern, hostname) + if res is None: + msg = _("* The hostname contains characters that are not allowed") + raise serializers.ValidationError(msg) + return hostname + @classmethod def setup_eager_loading(cls, queryset): """ Perform necessary eager loading of data. """