How to get the subscriber status of notification stream

1.start thread1, regist notification stream1 by confd_register_notification_stream() and send event notification by confd_notification_send().

  1. i start thread2 and use the confd_notifications_connect2() and confd_read_notification() to subscriber the stream1 (simulate one subscriber user session )and reveived the related notification from the stream1.

  2. how the thread1 to get the subscriber status(such as start or stop) of the thread2 subscriber user session?
    (such as: if thread2 start, thread1 could know the stream1 subscriber session is ready, if thread2 exit, the stream1 subscriber is not ready.)

need support on this,

thx

See $CONFD_DIR/src/confd/yang/tailf-netconf-monitoring.yang
look for start-time and stop-time

Example using MAAPI:

$ confd_load -dd -Fp -o -p /ncm:netconf-state/tncm:streams/tncm:stream
TRACE Connected (maapi) to ConfD
starting user session ctxt=system user=system groups=[system]
TRACE MAAPI_START_USER_SESSION  --> CONFD_OK
TRACE MAAPI_START_TRANS  --> CONFD_OK
TRACE MAAPI_SAVE_CONFIG  --> CONFD_OK
TRACE Connected (stream) to ConfD
<config xmlns="http://tail-f.com/ns/config/1.0">
  <netconf-state xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
  <streams xmlns="http://tail-f.com/yang/netconf-monitoring">
  <stream>
    <name>NETCONF</name>
    <description>default NETCONF event stream</description>
    <replay-support>false</replay-support>
  </stream>
  <stream>
    <name>interface</name>
    <description>Example notifications</description>
    <replay-support>true</replay-support>
    <replay-log-creation-time>2020-06-01T06:38:01.931789+00:00</replay-log-creation-time>
    <subscriber>
      <session-id>1</session-id>
      <start-time>2020-06-01T08:38:17.931283+02:00</start-time>
    </subscriber>
    <subscriber>
      <session-id>2</session-id>
      <start-time>2020-06-01T08:38:22.774519+02:00</start-time>
    </subscriber>
    <subscriber>
      <session-id>3</session-id>
      <start-time>2020-06-01T08:40:04.23751+02:00</start-time>
    </subscriber>
    <subscriber>
      <session-id>4</session-id>
      <start-time>2020-06-01T08:42:03.162586+02:00</start-time>
    </subscriber>
    <subscriber>
      <session-id>5</session-id>
      <start-time>2020-06-01T09:03:42.21049+02:00</start-time>
    </subscriber>
  </stream>
  </streams>
  </netconf-state>
TRACE MAAPI_SAVE_CONFIG_RESULT  --> CONFD_OK
</config>
TRACE MAAPI_END_USER_SESSION  --> CONFD_OK

Best regards,
Conny

thanks your quick response,
can u share the relate Maapi C/C++ example to me?

path= “/ncm:netconfstate/tncm:streams/tncm:stream{evmserver}”;
maapi_get_list_elem(mCandidateDbSocket, mTransId, &list,&number, “%s”, path);

i use the above API want to get some info, but it seems input an invalid path, which path should be used?

error log:

TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_GET_ELEM /ncm:netconf-state/tncm:streams/tncm:stream{evmserver}DEBUG badly formatted or nonexistent path -
–> CONFD_ERR

if use confd_load cmd, it will:

[root@0-9 bin]# ./confd_load -dd -Fp -o -p /ncm:netconf-state/tncm:streams/tncm:stream{evmserver}
TRACE Connected (maapi) to ConfD
starting user session ctxt=system user=system groups=[system]
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_SAVE_CONFIG --> CONFD_OK
TRACE Connected (stream) to ConfD




evmserver
evmserver notifications
true
2020-05-14T17:29:51.331351+00:00

21
2020-06-01T22:09:15.234266+05:30




TRACE MAAPI_SAVE_CONFIG_RESULT --> CONFD_OK

TRACE MAAPI_END_USER_SESSION --> CONFD_OK

how to set path for it?please hlep me.

The source code for the confd_load tool comes with ConfD:
`$CONFD_DIR/src/confd/tools/confd_load.c

You can also use the confd_cmd tool that can use maapi_get_objects() to get the list:
$ confd_cmd -dd -o -c 'traverse_list "/netconf-state/streams/stream{interface}/subscriber"'

The source code for the confd_cmd tool can be found in the same folder as the confd_load tool.
$CONFD_DIR/src/confd/tools/confd_cmd.c

ok,
Is there other event mechnism automatically ? when thread2 start and subscriber this stream, thread1 can get it right now. when the subscriber is exist(thread2 exist), thread1 can know it right now.

for below case:

1.start thread1, regist notification stream1 by confd_register_notification_stream() and send event notification by confd_notification_send().

  1. i start thread2 and use the confd_notifications_connect2() and confd_read_notification() to subscriber the stream1 (simulate one subscriber user session )and reveived the related notification from the stream1

thx

Do you mean getting a notification when someone register for a NETCONF stream notification using the ConfD event notification API?
If so I believe that you can’t subscribe to those changes, and that you need to poll.

Example using the confd_cmd tool:

ecode=1; while [ $ecode -ne 0 ]; do sleep .5; confd_cmd -o -c "mget /netconf-state/streams/stream{interface}/subscriber{1}/session-id" > /dev/null; ecode=$?; done;

thanks for your response.
it seems need application code to do subscriber status polling.
for the standard notificaiton subscriber method(use netconf protocol to subscriber), we can get the user session status(START or STOP) by notificaiton event(CONFD_NOTIF_USER_SESSION - Whenever a user session is started or stopped).
Can we have some methods to get the user session status automatically like the above CONFD_NOTIF_USER_SESSION event.(attention: we use confd_notifications_connect2() and confd_read_notification() API to subscriber NETCONF stream)
thanks for your help.

Can we have some methods to get the user session status automatically like the above CONFD_NOTIF_USER_SESSION event.(attention: we use confd_notifications_connect2() and confd_read_notification() API to subscriber NETCONF stream)

Instead, when your notification stream subscriber application registers using confd_notifications_connect2(), the notification stream subscriber application can at the same time add itself to a list of subscribers in the CDB operational datastore by, for example, reusing the stream subscriber list from the $CONFD_DIR/src/confd/yang/tailf-netconf-monitoring.yang model.

Then you do a cdb_oper_subscribe() to the subscriber list from your application that send notifications.

See examples.confd/cdb_oper/subcriber for an example of writing to the CDB operational datastore and subscribing to updates. A performance demo can be found here: ConfD-Demos/oper-performance at master · ConfD-Developer/ConfD-Demos · GitHub