如何通过Netopeer2-cli订阅通知获取变更节点的数值?
问题描述
我在不同机器上运行Netopeer2-cli与Netopeer2-server,使用subscribe RPC订阅配置变更通知,但目前仅能获取变更节点的XPath,无法获取更新后的具体数值。尝试该RPC后,仅返回Netopeer2-server侧sysrepo中发生变更的XPath列表,输出示例如下:
<netconf-config-change xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications"> <changed-by> <username>root</username> <session-id>0</session-id> </changed-by> <datastore>running</datastore> <edit> <target xmlns:xyz>*xpath of some node*</target> <operation>create</operation> </edit> <edit> <target xmlns:xyz>**xpath of some node**</target> <operation>create</operation> </edit> </netconf-config-change>
另外,我了解establish-sub RPC会推送周期性通知,但我仅需要叶子节点发生变更时的通知,请问如何获取包含实际变更数值的通知?
解决方法
开启sysrepo的变更数据包含配置
Netopeer2依赖sysrepo提供通知能力,默认netconf-config-change通知仅返回XPath和操作类型,需修改sysrepo的配置让其包含变更数据:
在Netopeer2-cli中执行以下命令:edit-config --target running --config '<notification xmlns="urn:sysrepo:notification"><config-change-include-data>true</config-change-include-data></notification>'该配置会让sysrepo在发送变更通知时,自动附加变更节点的实际数值。
确认订阅的通知类型
确保使用subscribeRPC订阅的是urn:ietf:params:xml:ns:yang:ietf-netconf-notifications模块下的netconf-config-change事件,无需使用establish-sub(后者用于周期性数据推送,不符合你的需求)。验证通知内容
修改任意叶子节点后,收到的通知会在<edit>节点下新增<data>字段,包含变更后的具体数值,示例如下:<netconf-config-change xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications"> <changed-by> <username>root</username> <session-id>0</session-id> </changed-by> <datastore>running</datastore> <edit> <target xmlns:xyz="/xyz:some-node/xyz:leaf"/> <operation>replace</operation> <data xmlns:xyz="urn:example:xyz"> <xyz:some-node> <xyz:leaf>new-updated-value</xyz:leaf> </xyz:some-node> </data> </edit> </netconf-config-change>
内容的提问来源于stack exchange,提问作者Sam Kore
相关产品推荐
相关产品推荐

