florentchauveau / go-kamailio-binrpc Goto Github PK
View Code? Open in Web Editor NEWGo implementation of Kamailio BINRPC protocol for invoking RPC functions
License: MIT License
Go implementation of Kamailio BINRPC protocol for invoking RPC functions
License: MIT License
Hello,
I seem to be hitting an issue with the cookie mismatch between WritePacket
and ReadPacket
from the fetchBINRPC (https://github.com/florentchauveau/kamailio_exporter/blob/master/collector.go#L569) in certain cases, in particular when the cookie value is at the lower end of the uint32 range. Here is an example of a cookie with value 10038690.
The WritePacket
within binrpc returns the cookie byte array [0 153 45 162], the
header bytes written to the IO writer is: {[161 3 19 0 153 45 162] 0 0}
However, when we subsequently do a ReadPacket
, which then invokes the ReadHeader
,
the resulting cookie is derived as [153 45 162], It seems the calculation results in a
mismatch with the length of the cookie, possibly here:
https://github.com/florentchauveau/go-kamailio-binrpc/blob/master/binrpc.go#L279-L280
In the case of my example cookie, the first 2 bytes read were: [161 18]. This results in the
sizeOfLength
(=1) and sizeOfCookie
(=3), and the cookie byte array evaluates to [153, 45, 162].
This causes validation failure here (as [153, 45, 162] != [0 153 45 162]):
https://github.com/florentchauveau/go-kamailio-binrpc/blob/master/binrpc.go#L431
The validation failure causes the Prometheus to mark Kamailio as down which then triggers alerts. Are you able to provide any pointers as to what is the best way to resolve this? At present, I don't fully understand the second byte within the buffer when a read is invoked in the ReadHeader
(https://github.com/florentchauveau/kamailio_exporter/blob/master/collector.go#L569), as that is the basis of length and cookie calculation. There are other options, we only look at the higher end of the uint32 range for the cookie. I haven't tried this, so this is a suggestion.
Hi,
Its not an issue but more of a feature request to be able to Marshal the records into JSON so any other external services can interact with the outputs easily. I've seen this package used in kamailio-exporters and in both popular versions the example to parse the dispatcher.list is a dedicated function to parse the output binrpc record.
With the record for any command output in JSON it'll be easy to transform into struct or maps and work with the outputs. I'm trying to write such a function and thought to check with you if this is a good idea or already exists or not needed altogether.
Thanks.
Trying the listed example with below command which gives error:
cookie, err := binrpc.WritePacket(conn, "stats.fetch")
records: [{%!s(int=3) %!s(uint8=0) %!s(int=400)} {%!s(int=41) %!s(uint8=1) Please provide which stats to retrieve}]
However when trying to give specific statistics (or group) it complains that command not found:
cookie, err := binrpc.WritePacket(conn, "stats.fetch current_opened_connections")
records: [{%!s(int=3) %!s(uint8=0) %!s(int=500)} {%!s(int=59) %!s(uint8=1) command stats.fetch current_opened_connections not found}]
cookie, err := binrpc.WritePacket(conn, "stats.fetch tcp:")
records: [{%!s(int=3) %!s(uint8=0) %!s(int=500)} {%!s(int=37) %!s(uint8=1) command stats.fetch tcp: not found}]
Example from kamcmd how the behavior should look like:
$ kamcmd stats.fetch
error: 400 - Please provide which stats to retrieve
$ kamcmd stats.fetch current_opened_connections
{
tcp.current_opened_connections: 0
}
$ kamcmd stats.fetch tcp:
{
tcp.con_reset: 0
tcp.con_timeout: 0
tcp.connect_failed: 0
tcp.connect_success: 0
tcp.current_opened_connections: 0
tcp.current_write_queue_size: 0
tcp.established: 0
tcp.local_reject: 0
tcp.passive_open: 0
tcp.send_timeout: 0
tcp.sendq_full: 0
}
Same requirement as exporter issue #10
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.