@@ -66,6 +66,9 @@ const (
6666 PATHZ_WRITE_SUCCESS_TIMESTAMP = PATHZ_WRITES + "/last-access-accept"
6767 PATHZ_WRITE_FAILED = PATHZ_WRITES + "/access-rejects"
6868 PATHZ_WRITE_FAILED_TIMESTAMP = PATHZ_WRITES + "/last-access-reject"
69+ ACCOUNT_TBL = "CREDENTIALS|SSH_ACCOUNT"
70+ CONSOLE_TBL = "CREDENTIALS|CONSOLE_ACCOUNT"
71+ SSH_TBL = "CREDENTIALS|SSH_HOST"
6972)
7073
7174type sshState struct {
@@ -115,6 +118,8 @@ func init() {
115118 XlateFuncBind ("DbToYang_pathz_policies_xfmr" , DbToYang_pathz_policies_xfmr )
116119 XlateFuncBind ("Subscribe_pathz_policies_xfmr" , Subscribe_pathz_policies_xfmr )
117120 XlateFuncBind ("DbToYang_pathz_policies_key_xfmr" , DbToYang_pathz_policies_key_xfmr )
121+ XlateFuncBind ("DbToYang_console_counters_xfmr" , DbToYang_console_counters_xfmr )
122+ XlateFuncBind ("Subscribe_console_counters_xfmr" , Subscribe_console_counters_xfmr )
118123}
119124
120125type grpcState struct {
@@ -879,3 +884,53 @@ var Subscribe_pathz_policies_xfmr SubTreeXfmrSubscribe = func(inParams XfmrSubsc
879884 nOpts : & notificationOpts {mInterval : 0 , pType : OnChange },
880885 }, nil
881886}
887+
888+ var DbToYang_console_counters_xfmr SubTreeXfmrDbToYang = func (inParams XfmrParams ) error {
889+ var counters accessCounters
890+
891+ table , err := inParams .dbs [inParams .curDb ].GetEntry (& db.TableSpec {Name : "CREDENTIALS" }, db.Key {Comp : []string {"CONSOLE_METRICS" }})
892+ if err != nil {
893+ log .V (0 ).Infof ("Failed to read from StateDB: %v" , inParams .table )
894+ return err
895+ }
896+
897+ accepts := table .Get ("access_accepts" )
898+ if counters .accessAccepts , err = strconv .ParseUint (accepts , 10 , 64 ); err != nil && accepts != "" {
899+ log .V (0 ).Infof ("Couldn't find access_accepts: %v" , err )
900+ }
901+ lastAccept := table .Get ("last_access_accept" )
902+ if counters .lastAccessAccept , err = strconv .ParseUint (lastAccept , 10 , 64 ); err != nil && lastAccept != "" {
903+ log .V (0 ).Infof ("Couldn't find last_access_accept: %v" , err )
904+ }
905+ rejects := table .Get ("access_rejects" )
906+ if counters .accessRejects , err = strconv .ParseUint (rejects , 10 , 64 ); err != nil && rejects != "" {
907+ log .V (0 ).Infof ("Couldn't find access_rejects: %v" , err )
908+ }
909+ lastReject := table .Get ("last_access_reject" )
910+ if counters .lastAccessReject , err = strconv .ParseUint (lastReject , 10 , 64 ); err != nil && lastReject != "" {
911+ log .V (0 ).Infof ("Couldn't find last_access_reject: %v" , err )
912+ }
913+
914+ sysObj := getAppRootObject (inParams )
915+ ygot .BuildEmptyTree (sysObj )
916+ ygot .BuildEmptyTree (sysObj .Console )
917+ ygot .BuildEmptyTree (sysObj .Console .State )
918+
919+ sysObj .Console .State .Counters .AccessAccepts = & counters .accessAccepts
920+ sysObj .Console .State .Counters .AccessRejects = & counters .accessRejects
921+ sysObj .Console .State .Counters .LastAccessAccept = & counters .lastAccessAccept
922+ sysObj .Console .State .Counters .LastAccessReject = & counters .lastAccessReject
923+
924+ return nil
925+ }
926+
927+ var Subscribe_console_counters_xfmr SubTreeXfmrSubscribe = func (inParams XfmrSubscInParams ) (XfmrSubscOutParams , error ) {
928+ log .V (0 ).Infof ("Subscribe_console_counters_xfmr:%s" , inParams .requestURI )
929+
930+ return XfmrSubscOutParams {
931+ dbDataMap : RedisDbSubscribeMap {
932+ db .StateDB : {"CREDENTIALS" : {"CONSOLE_METRICS" : {}}}},
933+ onChange : OnchangeEnable ,
934+ nOpts : & notificationOpts {mInterval : 0 , pType : OnChange },
935+ }, nil
936+ }
0 commit comments