Ad Widget

Collapse

Loadable module issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sadman
    Senior Member
    • Dec 2010
    • 1611

    #1

    Loadable module issue

    Hello

    I try to make loadable module to communicate with remote TCP server.
    I start with Zabbix-agent module and got success.
    Now i want to use that module with Zabbix-server, but can't understand how to get Host IP to subroutine.

    So, i want to use Zabbix Item with key "server.get[params]" and server.get key must call server_get() subroutine, which connect to host's Agent interfaces IP (for example) and do something. But i won't to include IP as key parameter.

    It's possible or that is bad idea?
  • jan.garaj
    Senior Member
    Zabbix Certified Specialist
    • Jan 2010
    • 506

    #2
    No deep dev guide exists. But you have source code, so you can analyze, how real zabbix code is it doing. Then you can include necessary files into your module and you can use it.
    Devops Monitoring Expert advice: Dockerize/automate/monitor all the things.
    My DevOps stack: Docker / Kubernetes / Mesos / ECS / Terraform / Elasticsearch / Zabbix / Grafana / Puppet / Ansible / Vagrant

    Comment

    • sadman
      Senior Member
      • Dec 2010
      • 1611

      #3
      I already do that and found in checks_simple.c:

      Code:
       if (0 == strcmp(request.key, "net.tcp.service"))
              {
                      if (SYSINFO_RET_OK == check_service(&request, item->interface.addr, result, 0))
                              ret = SUCCEED;
              }
      ...
              /* it will execute item from a loadable module if any */
                      if (SUCCEED == process(item->key, PROCESS_MODULE_COMMAND, result))
                              ret = SUCCEED;
      check_service() called with item->interface.addr which going from upper subroutine level, but to loadable module item->key send only. And i suspect, that need change architecture of loadable module's subs calling...

      But i think that somebody know another way to get Item's interface addr inside my module... May be with certain request to global struct's store.

      Comment

      • jan.garaj
        Senior Member
        Zabbix Certified Specialist
        • Jan 2010
        • 506

        #4
        Yes, you are reimplementing poller, so src/zabbix_server/poller/* codes are for you. You have still option to include db.h (dbcache.h) and then you can make direct queries to DB.
        Devops Monitoring Expert advice: Dockerize/automate/monitor all the things.
        My DevOps stack: Docker / Kubernetes / Mesos / ECS / Terraform / Elasticsearch / Zabbix / Grafana / Puppet / Ansible / Vagrant

        Comment

        • sadman
          Senior Member
          • Dec 2010
          • 1611

          #5
          Tanx for idea, but db select so expencive and can't be made without Item ID, but inside the module i have Item Key and params only (i think so). Now i apply the workaround with separate module .conf-file.

          I have one more question to Zabbix experts/programmers.
          My simple module send requests to TCP server and get responses (just text data). If Items a bit, everything works well with open/close sockets any time when requests must be performed - that method used in Zabbix for telnet checks. But, when i try to use my module to serve LLD-created items (big heap of its) - i get tons of TIME_WAIT sockets.

          Now i try to find workaround. My TCP server does not close connection itself and read request/send answers in the loop. I modify main module code to using this feature (all zabbix_log() calls deleted from code fragment):


          Code:
          /* global vars for module */
          zbx_sock_t      s;
          ...
          int     zbx_module_unifi_proxy(AGENT_REQUEST *request, AGENT_RESULT *result)
          {
          ...
          
                  // Socket not opened?
                 if (!s.socket) {
                     if (FAIL == (ret = zbx_tcp_connect(&s, CONFIG_SOURCE_IP, UNIFI_PROXY_SERVER, UNIFI_PROXY_PORT, item_timeout-1))) {
                        SET_MSG_RESULT(result, strdup(zbx_tcp_strerror()));
                        return SYSINFO_RET_FAIL;
                     } }
          
                  // Send request
                  if (SUCCEED == (ret = zbx_tcp_send_raw(&s, send_buf))) {
                      if (SUCCEED == (ret = zbx_tcp_recv(&s))) {
                         zbx_rtrim(s.buffer, "\r\n");
                         SET_STR_RESULT(result, strdup(s.buffer));
                      }  }
          
                  if (FAIL == ret)  {
                          SET_MSG_RESULT(result, strdup(zbx_tcp_strerror()));
                          return SYSINFO_RET_FAIL;
                     }
          
                  return SYSINFO_RET_OK;
          }
          ...
          
          int     zbx_module_uninit()
          {
                  zbx_tcp_close(&s);
                  return ZBX_MODULE_OK;
          }
          All seems OK, no huge list of TIME_WAIT's now, but sometimes i get `communication error: ZBX_TCP_WRITE() failed: [32] Broken pipe` in agent's log (it is my debug printf).

          And i don't know - it's right code for Zabbix architecture or just waste ))

          Can someone comment this situation or have other idea to get keep-alive connection inside Zabbix module? Tanx.

          Comment

          • jan.garaj
            Senior Member
            Zabbix Certified Specialist
            • Jan 2010
            • 506

            #6
            What is wrong with TIME_WAIT state?
            http://stackoverflow.com/questions/2...e-wait-sockets
            Devops Monitoring Expert advice: Dockerize/automate/monitor all the things.
            My DevOps stack: Docker / Kubernetes / Mesos / ECS / Terraform / Elasticsearch / Zabbix / Grafana / Puppet / Ansible / Vagrant

            Comment

            • sadman
              Senior Member
              • Dec 2010
              • 1611

              #7
              Originally posted by jan.garaj
              What is wrong with TIME_WAIT state?
              http://stackoverflow.com/questions/2...e-wait-sockets
              I know, that TIME_WAIT - is not abnormal state.

              Just in my tests i got speed ~1000req/sec (loop without delays, 5000 iterations) with 'open-write-read-close' chain and ~1666 req/sec with 'open_before_loop-write-read-close_after_loop' chain. I tnink, that +50% of speed and only ten sessions opened instead tons of waiting sockets - not so bad.

              Comment

              • asaveljevs
                Zabbix developer
                • Feb 2010
                • 36

                #8
                Unfortunately, the interface IP is currently not available to simple items in modules and ZBXNEXT-2838 asks for this functionality. That feature request also suggests a workaround, where a host's IP can be passed as an item's argument, perhaps using {HOST.IP} macro.

                Comment

                Working...