Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netconf notifications #36

Open
mjoshiNetElastic opened this issue Feb 13, 2018 · 5 comments
Open

netconf notifications #36

mjoshiNetElastic opened this issue Feb 13, 2018 · 5 comments
Milestone

Comments

@mjoshiNetElastic
Copy link

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.

@nemith
Copy link
Collaborator

nemith commented Feb 18, 2018

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.

@beckyxu
Copy link

beckyxu commented Nov 21, 2018

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

}

@beckyxu
Copy link

beckyxu commented Nov 21, 2018

I test the example ,wait for about 10 minutes and I am sorry to find that it will wrong by the mistakes:waitWalkFunc failed

@jiahui-qin
Copy link

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

@nemith nemith added this to the v2 milestone Jul 22, 2022
@nemith
Copy link
Collaborator

nemith commented Jul 22, 2022

This will be supported n v2. No ETA

nemith added a commit that referenced this issue Mar 13, 2024
Add unittest for RPCMsg encoding and ensure that operation is supplied
when encoding `rpc` request messages (i.e `ReqMSG`) via custom
MarshalXML method.

Future work to make sure structs passed in are named.

**Test Plan:**
```
$ go test . -v -run=MarshalRPCMsg
=== RUN   TestMarshalRPCMsg
=== RUN   TestMarshalRPCMsg/nil
    msg_test.go:55: out: 
=== RUN   TestMarshalRPCMsg/string
    msg_test.go:55: out: <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1"><foo><bar/></foo></rpc>
=== RUN   TestMarshalRPCMsg/byteslice
    msg_test.go:55: out: <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1"><baz><qux/></baz></rpc>
=== RUN   TestMarshalRPCMsg/validate
    msg_test.go:55: out: <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1"><validate><source><running/></source></validate></rpc>
=== RUN   TestMarshalRPCMsg/customStruct
    msg_test.go:55: out: <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1"><command xmlns="http://xml.juniper.net/junos/22.4R0/junos">show bgp neighbors</command></rpc>
--- PASS: TestMarshalRPCMsg (0.00s)
    --- PASS: TestMarshalRPCMsg/nil (0.00s)
    --- PASS: TestMarshalRPCMsg/string (0.00s)
    --- PASS: TestMarshalRPCMsg/byteslice (0.00s)
    --- PASS: TestMarshalRPCMsg/validate (0.00s)
    --- PASS: TestMarshalRPCMsg/customStruct (0.00s)
PASS
ok      github.com/nemith/netconf       (cached)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants