ConfD User Community

Getting Real Time Action Results for WebUI


#1

Hi everyone,

I’m new to ConfD and I guess this is the right place to ask this question.

I defined an action in my yang-model. Then I was able to start this action(process) via “run_action” method of JSON-RPC API. But the problem is, what I got was the whole result of the application. Is there anyway to get real-time data from the application and show it in WebUI ? (Assume that you run the ping command and you got some answers from the remote and you want to show these answers when they arrive to you in the webui)

I tried several things like trying to subscribe to tailf:action attribute. But i guess it is not possible. I also checked the notifications in NETCONF. But I dont think that, there is a JSON-RPC API for Netconf notification.

I would be very happy, if you share your experience for this kind of requirement.
I believe, you can show me some way to handle this situation.

Thank you
Bugra


#2

What I believe you are looking for is a Comet client that use a Comet channel to subscribe to changes and receive notifications.

ConfD UG 6.3.1 Chapter 18. “Web UI Development” and in particular 18.4. “Example of a Comet client” show an example located under ${CONFD_DIR}/var/confd/webui/example which unfortunately is broken.

I believe the next ConfD Premium release will revamp this example into a new one that will be located under examples.confd/json_rpc/common_flow. For details ask Tail-f support.

Meanwhile, for a quick fix of the ${CONFD_DIR}/var/confd/webui/example:

Terminal Window 1
$ pwd
/home/tailf/confd-6.3.1/examples.confd/intro/1-2-3-start-query-model-mod
$ diff -u confd.conf confd.conf.old
— confd.conf.old	2016-08-29 15:17:55.000000000 +0200
+++ confd.conf	2016-11-02 14:12:09.741829147 +0100
@@ -258,7 +258,7 @@
   </netconf>
   <webui>
     <enabled>true</enabled>
-    
+    <docroot>/home/tailf/tailf/confd-6.3.1/var/confd/webui/example</docroot>
     <transport>
       <tcp>
         <enabled>true</enabled>

$ cd /home/tailf/confd-6.3.1/var/confd/webui/example
$ ln -s /home/tailf/confd-6.3.1/examples.confd/webui/basic/docroot/login .
$ cd -
Modified example.js:
$ diff -u /home/tailf/confd-6.3.1/var/confd/webui/example/example.js.old /home/tail/confd-6.3.1/var/confd/webui/example/example.js
— /home/tailf/confd-6.3.1/var/confd/webui/example/example.js.old
2016-08-29 15:16:54.000000000 +0200
+++ /home/tailf//confd-6.3.1/var/confd/webui/example/example.js
2016-11-02 15:21:41.560348930 +0100
@@ -21,9 +21,9 @@
   // CHANGE AT LEAST THESE
   // IN ORDER TO MAKE THIS EXAMPLE WORK IN YOUR SETUP
   var jsonrpcUrl = '/jsonrpc', // 'http://localhost:8008/jsonrpc';
-      path = '/dhcp:dhcp/max-lease-time',
-      value = Math.floor(Math.random() * 800) + 7200;
-
+      path = '/dhcpd:dhcp/maxLeaseTime',
+      value = 'PT' + (Math.floor(Math.random() * 800) + 7200) + 'S';
+      
   var log,
       jsonRpc,
       comet,
$ make clean all start

In browser http://127.0.0.1:8008
(Order of events is from bottom up)
--------------------------------------------------

/dhcpd:dhcp/maxLeaseTime is now set to: PT7746S.

Get value for /dhcpd:dhcp/maxLeaseTime in read transaction...

--------------------------------------------------

>>> Notification >>>
{
  "db": "running",
  "changes": [
    {
      "keypath": "/dhcpd:dhcp/maxLeaseTime",
      "op": "value_set",
      "value": "PT7746S"
    }
  ],
  "user": "admin",
  "ip": "127.0.0.1"
}
<<< Notification <<<

Waiting 2.5 seconds before one last call to get_value

--------------------------------------------------

Commited.

Commiting changes in webui transaction...

--------------------------------------------------

Validated.

Validating changes in webui transaction...

--------------------------------------------------

/dhcpd:dhcp/maxLeaseTime is now set to: PT7746S.

Get value for /dhcpd:dhcp/maxLeaseTime in webui transaction...

--------------------------------------------------

/dhcpd:dhcp/maxLeaseTime is now set to: undefined.

Set value for /dhcpd:dhcp/maxLeaseTime to PT7746S in webui transaction...

--------------------------------------------------

webui (read-write) transaction with th (transaction handle) id: 2.

Create a new webui (read-write) transaction...

--------------------------------------------------

Subscribed with handle id main-1.20392672067748108-max-lease-time.

Subcribing to changes of /dhcpd:dhcp/maxLeaseTime (with handle main-1.20392672067748108-max-lease-time)...

--------------------------------------------------

/dhcpd:dhcp/maxLeaseTime is now set to: PT7200S.

Get value for /dhcpd:dhcp/maxLeaseTime in read transaction...

--------------------------------------------------

Read-only transaction with th (transaction handle) id: 1.

Create a new read-only transaction...

Terminal Window 2
$ confd_cli -u admin
admin@tailf> config
Entering configuration mode private

admin@tailf% set dhcp maxLeaseTime 1s

admin@tailf% commit
Commit complete.

New notification in browser:
>>> Notification >>>
{
  "db": "running",
  "changes": [
    {
      "keypath": "/dhcpd:dhcp/maxLeaseTime",
      "op": "value_set",
      "value": "PT1S"
    }
  ],
  "user": "admin",
  "ip": "127.0.0.1"
}
<<< Notification <<<

#3

Hi cohult,

Thanks for your help.
I’m already aware of subscriptions and comet features/functionalities. But yes I’m looking exact the same thing for “tailf:action” attirbute in Yang Model.

Let me explain it in a clearer way;

  • Assume that you have a yang-model with following configuration
    tailf:action self-ping { tailf:exec "./ping.pl"; output { leaf header { type string; } container response { leaf data { type string; } } container statistics { leaf packet { type string; } leaf time { type string; } } } }

  • Now, you want to subscribe to output attirbute of your yang file to get the returned values simultaneously. At the moment, I’m able to see whole results like in below when I run self-ping command.

header Invoked from : PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. response { data 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.028 ms } response { data 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.016 ms } response { data 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.034 ms } statistics { packet 3 packets transmitted, 3 received, 0% packet loss, time 1998ms time rtt min/avg/max/mdev = 0.016/0.026/0.034/0.007 ms }

What i want is to be informed about these responses one by one when they arrive not whole of them. As far as I understand input and output attributes are not saved inside the database and they are temporary values for tailf:action. Therefore I’m not able to subscribe them.

Hopefully, this time it is more clear for you and everyone.

Thanks,
Bugra


#4

Hi Bugra,

I don’t believe you can have a Comet channel subscribe to the output of a YANG 1.1 action or a tailf:action or a YANG rpc. But you can subscribe to changes in the configration and operational data store.
So if you for example would like to have the action application produce output that you can subscribe to, you could have the action application set YANG config false data in the CDB operational datastore using the CDB API that you then use a Comet channel to subscribe to with the subscribe_cdboper method.
See for example ConfD UG 6.3.1 Chapter 19.3.2 Method subscribe_cdboper.


#5

Hi Cohult,

I found the params of “run_action” have “comet_id” and “handle”, and the UG said both of them are needed to receive notifications. I would like to know what notifications can we get from ‘run_action’ method and how we get those. Because my case is only need to know when the action is done and I would like to know if it still need CDB operational tricks to do so.

Thanks,

Nathan