source code: add a new tcp protocol

Issue #853 resolved
Former user created an issue

Hi I am trying to add a new protocol, I will release free the source code to tildeslash.

At the moment I updated these files Makefile.am Makefile.in src/protocol.h src/protocol.c and I write the new protocol test code under the folder src/protocols

and compiling,make fails.

I see there are the tokens defined in some files, so I updated also src/l.l src/p.y

Still make fails src/protocols/protocol.o:(.data+0x228): undefined reference to `check_new_protocol'

I see other files listing the tokens, but it seems to me they are made by automatic tools (bison, yacc, etc...) Please help.

Comments (13)

  1. Massimo Sala

    @Tildeslash

    At the moment I create the test functions for ntp, pjl (network printers), rsync, snmp, vnc and x11.

    For snmp I add the community parameter:

    void check_snmp(Socket_T socket, const char * szCommunity)

    How can I integrate them in monit?

  2. Tildeslash repo owner

    The best advise is to see how other protocols are implemented. Especially how parameter values are transferred via the Port_T object during parsing of .monitrc. The signature of the protocol check function should not change.

  3. Massimo Sala

    Ok I see how Port_T is used.

    Pls help, I don’t understand in which files I have to include my new file others.c

    I wrote a new file src/protocol/others.c with this function

    void check_vnc(Socket_T socket)

    file src/protocol/protocol.c

    static Protocol_T protocols[] = {

    \&(struct Protocol_T){"MQTT", check_mqtt},

    \&(struct Protocol_T){"VNC", check_vnc}

    };

    file src/protocol/protocol.h

    typedef enum {

    Protocol_MQTT,

    Protocol\_VNC

    } Protocol_Type;

    make stops with this error:

    undefined reference to `check_vnc'

    Do I have to update Makefile.am or Makefile.in ? How ?

  4. Massimo Sala

    I strictly followed the other src/protocols to create a new one.

    I add its definition to Makefile.am, protocol.h, protocol.c, monit.h

    Compilation works fine, no warning no errors.

    I check the configuration files

    monit -t

    syntax error 'vnc'

    I grep the file src/tokens.h and there isn’t the new protocol.

    @Tildeslash What I have to do?

  5. Massimo Sala

    I strictly followed the other src/protocols to create a new one.

    I add its definition to Makefile.am, protocol.h, protocol.c, monit.h

    Compilation works fine, no warning no errors.

    I check the configuration files

    monit -t

    syntax error 'vnc'

    I grep the file src/tokens.h and there isn’t the new protocol.

    @Tildeslash What I have to do?

  6. Tildeslash repo owner

    you need to add the new protocol lso to src/l.l and src/p.y + run “./bootstrap” and “./configure” afterwards

  7. Massimo Sala

    Sorry to bother you again.

    It wasn't easy for me to setup one host to compile monit. Environment: centos 6.10 servers.

    I discovered many packages provided by yum are quite old and inadeguate.

    I got gcc 6.3, backported by Redhat with the package devtoolset-6-make devtoolset-6-gcc-c++ I got the sources of autoconf, automake, libtool and compile them.

    I read carefully the C sources of the protocols and also src/l.l and p.y

    I wrote my code following the declarations of the other protocols.

    I run “./bootstrap” and “./configure” and now I have this new error:

    src/p.y:1731.19-26: symbol database is used, but is not defined as a token and has no rules
        src/p.y:1742.19-27: symbol community is used, but is not defined as a token and has no rules
        make: *** [src/y.tab.c] Error 1

    I look again at the source code, at the declaration of the other protocols, check_xxxx functions and their optional parameters, but I am stuck.

    Can you please take a look at my C files ?

    I am not sure about these declarations

    l.l at lines 321, 437, 438

    p.y at lines 331, 345

    I want to compile and test my changes. Afterwards I will release to you the sources of these new protocols:

    • PGSQL with correct login to the database (no spurious errors in postgresql logging) and parametrized database, username, password;
    • PJL (also other users on the forum ask to monitor printers; I check this test with about 12 different models from different vendors)
    • SNMP with parameter community
    • VNC
    • X11

    BTW: take a look at chk_string_mask.c

    It is a handy and generic function, to avoid the burden of writing every time specific code to check input values e.g. using scanf : code uneasy to read, maintain and prone to bugs.

    Thanks for your support, Massimo

  8. Massimo Sala

    Ok, I will read. For the moment, can you please take a look at the files and give me feedback to successful compile? Thanks

  9. Massimo Sala

    Hi

    I signed the agreement. I need to compile my routines and test them before a pull request !

    I run “./bootstrap” and “./configure” and now I have this new error:

    src/p.y:1731.19-26: symbol database is used, but is not defined as a token and has no rules src/p.y:1742.19-27: symbol community is used, but is not defined as a token and has no rules make: *** [src/y.tab.c] Error 1

    Could you please take a look at the ZIP file I attached here and let me know?

    https://bitbucket.org/tildeslash/monit/issues/853/source-code-add-a-new-tcp-protocol

    Best regards, Sala

  10. Log in to comment