<span class="invalid-feedback"
*ngIf="serviceForm.showError('snmp_destination', frm, 'required')"
i18n>This field is required.</span>
+ <span class="invalid-feedback"
+ *ngIf="serviceForm.showError('snmp_destination', frm, 'snmpDestinationPattern')"
+ i18n>The value does not match the pattern: <strong>hostname:port</strong></span>
</div>
</div>
<!-- Engine id for snmp V3 -->
}
});
});
+ it('should submit invalid snmp destination', () => {
+ formHelper.setValue('snmp_version', 'V2c');
+ formHelper.setValue('snmp_destination', '192.168.20.1');
+ formHelper.setValue('snmp_community', 'public');
+ formHelper.expectError('snmp_destination', 'snmpDestinationPattern');
+ });
});
describe('check edit fields', () => {
})
export class ServiceFormComponent extends CdForm implements OnInit {
readonly RGW_SVC_ID_PATTERN = /^([^.]+)(\.([^.]+)\.([^.]+))?$/;
+ readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/;
@ViewChild(NgbTypeahead, { static: false })
typeahead: NgbTypeahead;
snmp_version: [null, [Validators.required]],
snmp_destination: [
null,
- [
- CdValidators.requiredIf({
- service_type: 'snmp-gateway',
- unmanaged: false
- })
- ]
+ {
+ validators: [
+ CdValidators.requiredIf({
+ service_type: 'snmp-gateway',
+ unmanaged: false
+ }),
+ CdValidators.custom('snmpDestinationPattern', (value: string) => {
+ if (_.isEmpty(value)) {
+ return false;
+ }
+ return !this.SNMP_DESTINATION_PATTERN.test(value);
+ })
+ ]
+ }
],
engine_id: [
null,