netconf notifications
Opened this issue · 5 comments
Currently I have a netconf client session connection to a server. Now I want to receive notifications from the server, so I send a subscribe request. But after I do this, I see that my requests to the server are returning error " expected type rpc-reply but received notification" I am curious to learn how others are subscribing to netconf notifications. Any suggestions/advice will be helpful. Thanks in advance.
Do you have an example of a notification? I have never used the before. The package is setup to be request and response as per the RFC.
I met the same problem and Iwrote onr by myself.Maybe you can take it as reference.
func main() {
sshConfig := &ssh.ClientConfig{
User: "xxx",
Auth: []ssh.AuthMethod{ssh.Password("xxx")},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
s, err := netconf.DialSSH("xxx", sshConfig)
if err != nil {
log.Fatal(err)
}
defer s.Close()
fmt.Println(s.ServerCapabilities)
fmt.Println(s.SessionID)
str := "<create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">NETCONF<filter type="subtree"><hwCPUUtilizationRisingAlarm xmlns="" +
"http://www.huawei.com/netconf/vrp/huawei-sem\"/><hwCPUUtilizationResume xmlns="http://www.huawei.com/netconf/vrp/huawei-sem\" />" +
"<hwStorageUtilizationRisingAlarm xmlns="http://www.huawei.com/netconf/vrp/huawei-sem\" />" +
"2018-11-21T17:28:00Z2018-11-21T17:51:00Z"
rawMethod := netconf.RawMethod(str)
reply, err := s.Exec(rawMethod)
if err != nil {
panic(err)
}
fmt.Println("Reply:", reply.Data)
for {
rawXML, err := s.Transport.Receive()
if err != nil {
seelog.Error(err)
}
reply, err := newRPCReply(rawXML, s.ErrOnWarning, reply.MessageID)
if err != nil {
seelog.Error(err)
}
fmt.Println("Reply:", reply.Data)
}
}
type RPCReply struct {
XMLName xml.Name xml:"notification"
Data string xml:",innerxml"
RawReply string xml:"-"
MessageID string xml:"-"
}
func newRPCReply(rawXML []byte, ErrOnWarning bool, messageID string) (*RPCReply, error) {
reply := &RPCReply{}
reply.RawReply = string(rawXML)
if err := xml.Unmarshal(rawXML, reply); err != nil {
return nil, err
}
reply.MessageID = messageID
return reply, nil
}
I test the example ,wait for about 10 minutes and I am sorry to find that it will wrong by the mistakes:waitWalkFunc failed
Do you have an example of a notification? I have never used the before. The package is setup to be request and response as per the RFC.
you can refer this address this is a notifaction example
This will be supported n v2. No ETA