Ad Widget

Collapse

Zabbix_sender error "Header is missing, ignored message"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veniciusback
    Junior Member
    • Oct 2019
    • 3

    #1

    Zabbix_sender error "Header is missing, ignored message"

    Good evening, how are you?

    Please excuse any grammar and spelling mistakes, as I am using Google Translate!

    Scenario:

    I have a Windows operating system installed and a VM (Debian 12) on it, where Zabbix is ​configured and running.

    In this Windows environment, I have an ESP32, and I am trying to send data from a sensor to be monitored in Zabbix, using zabbix_sender.

    Code:
    String payload = "zabbix_sender -z " + String(zabbix_server) + " -p " + String(zabbix_port) + " -s \Servidor\ -k \sensor.temperatura\ -o \"" + String(random(100)) + "\"";
     
      Serial.println("Enviando dados para o Zabbix...");
      if (client.connect(zabbix_server, zabbix_port)) {
        // Enviar dados
        client.print(payload);
        client.flush();
        client.stop();
        Serial.println("Dados enviados!");
      } else {
        Serial.println("Falha na conexão com o servidor Zabbix");
      }
      Serial.println(payload);​
    When I send the command from Windows and/or from the Debian VM itself, which the ESP32 returns, it inserts the data correctly, but when sent through the ESP32, the Zabbix server reports that the "missing header, message ignored" is present. What could this be?​
  • Brambo
    Senior Member
    • Jul 2023
    • 245

    #2
    Why do you use a \ in the host and itemkeys? As \ isn't allowed in the host name I expect your first line of string payload is setup wrong after the -s and I do expect your -k and -o are setup wrong as well with those \ characters Click image for larger version

Name:	image.png
Views:	159
Size:	25.5 KB
ID:	500638

    Comment


    • veniciusback
      veniciusback commented
      Editing a comment
      Good evening my friend, so from what I researched, the "" within the C++ code serves to "escape" between the "" and the Strings.

      I tested several situations within this code and could not solve it, so I changed to sending via JSON, resulting in a code similar to the one below!
      This was the only way I was able to send the data to Zabbix, via ESP32

      Code:
      #include <WiFi.h>
      #include <WiFiClient.h>
      // Configurações de rede WiFi
      const char* ssid = "Cleci";
      const char* password = "04091960";
      // Configurações do Zabbix
      const char* zabbix_server = "192.168.1.15";  // Exemplo: "192.168.1.100"
      const int zabbix_port = 10051;  // Porta padrão do Zabbix Trapper
      int cont = 0;
      void setup() {
          Serial.begin(115200);
          WiFi.begin(ssid, password);
          while (WiFi.status() != WL_CONNECTED) {
              delay(1000);
              Serial.println("Conectando ao WiFi...");
          }
          Serial.println("Conectado ao WiFi!");
      }
      void loop() {
          cont ++;
          if (WiFi.status() == WL_CONNECTED) {
              WiFiClient client;
              if (client.connect(zabbix_server, zabbix_port)) {
                  Serial.println("Conectado ao Zabbix Server!");
                  // Criando o JSON no formato do protocolo Zabbix Sender
                   String jsonPayload = String("{\"request\":\"sender data\",\"data\":[{\"host\":\"Servidor\",\"key\":\"sensor.temperatura\",\"value\":")
                            + cont
                            + " }]}";
                  // Criando o cabeçalho do protocolo Zabbix Sender
                  char header[] = "ZBXD\1";
                  uint32_t data_len = jsonPayload.length();
                  // Enviar o cabeçalho
                  client.write((const uint8_t*)header, 5);
                  // Enviar o tamanho da mensagem (little-endian)
                  client.write((const uint8_t*)&data_len, 4);
                  client.write((const uint8_t*)"\0\0\0\0", 4);  // 4 bytes adicionais (sempre zero)
                  // Enviar o JSON com os dados
                  client.print(jsonPayload);
                  // Aguardar a resposta do Zabbix Server
                  delay(500);
                  while (client.available()) {
                      String response = client.readString();
                      Serial.println("Resposta do Zabbix: " + response);
                  }
                  client.stop();
              } else {
                  Serial.println("Falha ao conectar ao Zabbix Server!");
              }
          } else {
              Serial.println("WiFi desconectado...");
          }
          delay(1000); // Enviar a cada 10 segundos
      }
      Thank you for your help, big hug!

      So counting this topic as solved!
  • Brambo
    Senior Member
    • Jul 2023
    • 245

    #3
    veniciusback what i meant was:
    Your original code
    Code:
    String payload = "zabbix_sender -z " + String(zabbix_server) + " -p " + String(zabbix_port) + " -s \Servidor\ -k \sensor.temperatura\ -o \"" + String(random(100)) + "\"";
    Should probably be recoded to:
    Code:
    String payload = "zabbix_sender -z " + String(zabbix_server) + " -p " + String(zabbix_port) + " -s Servidor -k sensor.temperatura -o " + String(random(100)) ;
    Give it a try to see if it's works, I'm no C++ coder but do code in other languages

    Comment

    Working...