GithubHelp home page GithubHelp logo

florentchauveau / go-kamailio-binrpc Goto Github PK

View Code? Open in Web Editor NEW
28.0 3.0 9.0 39 KB

Go implementation of Kamailio BINRPC protocol for invoking RPC functions

License: MIT License

Go 100.00%
golang go kamailio binrpc

go-kamailio-binrpc's People

Contributors

florentchauveau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-kamailio-binrpc's Issues

Cookie mismatch betwen write and read packet

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.

JSON output

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.

Support for RPC commands with arguments

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.