diff --git a/src/sonic-yang-models/tests/files/sample_config_db.json b/src/sonic-yang-models/tests/files/sample_config_db.json index be7816e506..d8f9028409 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -426,9 +426,21 @@ "2001:aa:aa::aa": {} }, "SYSLOG_SERVER" : { - "10.13.14.17": {}, - "20.1.1.1": {}, - "2001:aa:aa::aa": {} + "10.13.14.17": { + "source": "1.1.1.1", + "port": "514", + "vrf": "default" + }, + "20.1.1.1": { + "source": "1.1.1.1", + "port": "514", + "vrf": "mgmt" + }, + "2001:aa:aa::aa": { + "source": "1111::1111", + "port": "514", + "vrf": "Vrf_blue" + } }, "CABLE_LENGTH": { "AZURE": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/syslog.json b/src/sonic-yang-models/tests/yang_model_tests/tests/syslog.json index ee45cf4d28..8b110fbd8a 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/syslog.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/syslog.json @@ -1,4 +1,27 @@ { + "SYSLOG_SERVER_VALID": { + "desc": "Configure SYSLOG_SERVER." + }, + "SYSLOG_SERVER_INVALID_SOURCE": { + "desc": "Configure invalid SOURCE in SYSLOG_SERVER.", + "eStrKey": "InvalidValue" + }, + "SYSLOG_SERVER_SOURCE_IP_FAMILY_MISMATCH": { + "desc": "Configure SOURCE IP family mismatch in SYSLOG_SERVER.", + "eStrKey": "Must" + }, + "SYSLOG_SERVER_INVALID_PORT": { + "desc": "Configure invalid PORT in SYSLOG_SERVER.", + "eStrKey": "InvalidValue" + }, + "SYSLOG_SERVER_INVALID_VRF": { + "desc": "Configure invalid VRF in SYSLOG_SERVER.", + "eStrKey": "InvalidValue" + }, + "SYSLOG_SERVER_DISABLED_MGMT_VRF": { + "desc": "Configure disabled management VRF in SYSLOG_SERVER.", + "eStrKey": "Must" + }, "SYSLOG_SERVER_TEST": { "desc": "Load syslog server table with ipv4 address as syslog servers." }, @@ -14,5 +37,4 @@ "desc": "Load syslog server table with invalid ipv6 address as syslog server.", "eStrKey": "InvalidValue" } - -} \ No newline at end of file +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/syslog.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/syslog.json index ed153c0d6c..990fdcf85c 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/syslog.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/syslog.json @@ -1,4 +1,113 @@ { + "SYSLOG_SERVER_VALID": { + "sonic-syslog:sonic-syslog": { + "sonic-syslog:SYSLOG_SERVER": { + "SYSLOG_SERVER_LIST": [ + { + "server_address": "100.0.0.1", + "source": "1.1.1.1", + "port": "514", + "vrf": "default" + }, + { + "server_address": "200.0.0.1", + "source": "1.1.1.1", + "port": "514", + "vrf": "mgmt" + }, + { + "server_address" : "2000::1", + "source": "1111::1111", + "port": "514", + "vrf": "Vrf-Data" + } + ] + } + }, + "sonic-mgmt_vrf:sonic-mgmt_vrf": { + "sonic-mgmt_vrf:MGMT_VRF_CONFIG": { + "sonic-mgmt_vrf:vrf_global": { + "mgmtVrfEnabled": "true" + } + } + }, + "sonic-vrf:sonic-vrf": { + "sonic-vrf:VRF": { + "VRF_LIST": [ + { + "name": "Vrf-Data" + } + ] + } + } + }, + "SYSLOG_SERVER_INVALID_SOURCE": { + "sonic-syslog:sonic-syslog": { + "sonic-syslog:SYSLOG_SERVER": { + "SYSLOG_SERVER_LIST": [ + { + "server_address": "100.0.0.1", + "source": "invalid_value" + } + ] + } + } + }, + "SYSLOG_SERVER_SOURCE_IP_FAMILY_MISMATCH": { + "sonic-syslog:sonic-syslog": { + "sonic-syslog:SYSLOG_SERVER": { + "SYSLOG_SERVER_LIST": [ + { + "server_address": "100.0.0.1", + "source": "1111::1111" + } + ] + } + } + }, + "SYSLOG_SERVER_INVALID_PORT": { + "sonic-syslog:sonic-syslog": { + "sonic-syslog:SYSLOG_SERVER": { + "SYSLOG_SERVER_LIST": [ + { + "server_address": "100.0.0.1", + "port": "65536" + } + ] + } + } + }, + "SYSLOG_SERVER_INVALID_VRF": { + "sonic-syslog:sonic-syslog": { + "sonic-syslog:SYSLOG_SERVER": { + "SYSLOG_SERVER_LIST": [ + { + "server_address": "100.0.0.1", + "vrf": "invalid_value" + } + ] + } + } + }, + "SYSLOG_SERVER_DISABLED_MGMT_VRF": { + "sonic-syslog:sonic-syslog": { + "sonic-syslog:SYSLOG_SERVER": { + "SYSLOG_SERVER_LIST": [ + { + "server_address": "100.0.0.1", + "vrf": "mgmt" + } + ] + } + }, + "sonic-mgmt_vrf:sonic-mgmt_vrf": { + "sonic-mgmt_vrf:MGMT_VRF_CONFIG": { + "sonic-mgmt_vrf:vrf_global": { + "mgmtVrfEnabled": "false" + } + } + } + }, "SYSLOG_SERVER_TEST": { "sonic-syslog:sonic-syslog": { "sonic-syslog:SYSLOG_SERVER": { diff --git a/src/sonic-yang-models/yang-models/sonic-syslog.yang b/src/sonic-yang-models/yang-models/sonic-syslog.yang index 2bb05a0297..c2aa73827f 100644 --- a/src/sonic-yang-models/yang-models/sonic-syslog.yang +++ b/src/sonic-yang-models/yang-models/sonic-syslog.yang @@ -9,22 +9,72 @@ module sonic-syslog { prefix inet; } + import sonic-mgmt_vrf { + prefix mvrf; + } + + import sonic-vrf { + prefix vrf; + } + + description "Syslog YANG Module for SONiC OS: remote syslog logging"; + + revision 2022-04-18 { + description "Initial revision."; + } + + typedef vrf-device { + description "Represents syslog VRF device"; + type enumeration { + enum default; + enum mgmt; + } + } + container sonic-syslog { container SYSLOG_SERVER { - description "SYSLOG SERVER part of config_db.json"; + description "SYSLOG_SERVER part of config_db.json"; list SYSLOG_SERVER_LIST { key "server_address"; leaf server_address { - description "syslog server ip address"; + description "Syslog server IP address"; type inet:ip-address; } - } /* end of list SYSLOG_SERVER_LIST */ - } /* end of container SYSLOG_SERVER */ + leaf source { + description "Syslog source IP address"; + type inet:ip-address; + must "(contains(current(), '.') and contains(../server_address, '.')) + or (contains(current(), ':') and contains(../server_address, ':'))"; + } + + leaf port { + description "Syslog server UDP port"; + type inet:port-number; + } + + leaf vrf { + description "Syslog VRF device"; + type union { + type leafref { + path "/vrf:sonic-vrf/vrf:VRF/vrf:VRF_LIST/vrf:name"; + } + type vrf-device; + } + must "(current() != 'mgmt') + or (/mvrf:sonic-mgmt_vrf/mvrf:MGMT_VRF_CONFIG/mvrf:vrf_global/mvrf:mgmtVrfEnabled = 'true')"; + } + + } + /* end of list SYSLOG_SERVER_LIST */ + } + /* end of container SYSLOG_SERVER */ } + /* end of container sonic-syslog */ } +/* end of module sonic-syslog */