ESP32 Zabbix Controller

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
Semo
New user
Posts: 3
Joined: 16 Dec 2022, 09:07

ESP32 Zabbix Controller

#1 Post by Semo » 16 Dec 2022, 09:19

Hey there,

I've been trying to integrate a ESP32 Temp sensor into my Zabbix Dashboard. I've read that a zabbix controller is part of "Collection". (https://espeasy.readthedocs.io/en/lates ... #c017-page)
I've tried Collection A to E but never was able to choose Zabbix as a Controller. (mega-20221105) What am I missing?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Zabbix Controller

#2 Post by TD-er » 16 Dec 2022, 09:27

It should indeed be part of the "Collection" builds.
However, I just checked and it is "undefined" for "LIMIT_BUILD_SIZE" builds.
I guess for ESP32 we still have enough space, so it should be enabled for those... Maybe for ESP8266 we can also enable it for some builds which have room left (Collection E perhaps?)

Semo
New user
Posts: 3
Joined: 16 Dec 2022, 09:07

Re: ESP32 Zabbix Controller

#3 Post by Semo » 16 Dec 2022, 09:39

Thank you for your fast reply!

That means for me I cant access the Zabbix controller when using an ESP32 or ESP8266 when flashing the 4M(ESP32) or 1M(8266) precompiled bins, right?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Zabbix Controller

#4 Post by TD-er » 16 Dec 2022, 09:43

I asked Ton to have a look at this later today.
So there is a significant chance you will have a build including Zabbix later today.
That means for me I cant access the Zabbix controller when using an ESP32 or ESP8266 when flashing the 4M(ESP32) or 1M(8266) precompiled bins, right?
For now, that's correct...

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 Zabbix Controller

#5 Post by Ath » 16 Dec 2022, 09:45

I'll try to fit it in some builds later today.

If you have the skills (or when not but like a challenge 8-)) you could create a Custom build, using the Development manual (using VSCode and PlatformIO, especially about creating a Custom build)
/Ton (PayPal.me)

Semo
New user
Posts: 3
Joined: 16 Dec 2022, 09:07

Re: ESP32 Zabbix Controller

#6 Post by Semo » 16 Dec 2022, 09:46

Again thank you so much!

You don't have to rush for me. I'm setting this up for my work and we do have time untill next year for this whole project.
I'll most likely check again on monday, hope that will be plenty of time for you.

Again, again thank you :)

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 Zabbix Controller

#7 Post by Ath » 16 Dec 2022, 14:45

Created PR #4420 to enable the Zabbix controller in all Collection builds (both ESP8266 and ESP32)
Downloads available from the Github Actions build
/Ton (PayPal.me)

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#8 Post by pp1wvc » 08 Jan 2023, 20:49

I have a customized compilation of ESPEasy where I use the zabbix controller, it is configured with the IP and port of the Zabbix Server according to this information:
USAGE: at Zabbix server you go to Configuration -> Hosts -> Create host
The "Host name" should match exactly the EspEasy name (Config -> Unit Name)
I used the name Digital
Add a group (mandatory) and hit add.
I used the default group
No need to set up IP address or agent.
OK
Go to the newly created host ->Items ->Create Item
Name the item something descriptive
OK
For Key add the EspEasy task Value name (case sensitive)
ADS1115

ype of information select "Numeric (float)" and press add.
OK
Aslo make sure that you enable send to controller (under Data Acquisition in tasks)
OK
and set an interval because you need to actively send the data to Zabbix
OK
Questions:
With Zabix_Sender it works normally, not characterizing a network or firewall problem, what could I be doing wrong?
Problems with the Zabbix plugin?
Attachments
zabbix_plugin.png
zabbix_plugin.png (51.58 KiB) Viewed 25726 times
test zabbix sender.png
test zabbix sender.png (30.76 KiB) Viewed 25726 times
tasksett.png
tasksett.png (22.72 KiB) Viewed 25726 times
Item.png
Item.png (13.06 KiB) Viewed 25726 times
Host.png
Host.png (19.77 KiB) Viewed 25726 times
Controller.png
Controller.png (33.25 KiB) Viewed 25726 times

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 Zabbix Controller

#9 Post by Ath » 08 Jan 2023, 22:34

Does your Zabbix server accept HTTP connections on that port? As ESPEasy doesn't support HTTPS (yet).

And the ADS1115 reporting a value of -32768, most likely isn't correct either, is it actually connected and working?
/Ton (PayPal.me)

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#10 Post by pp1wvc » 08 Jan 2023, 22:39

Hello ATH, thanks for your interest.
The plugin connects through this port, 10051, see the plugin:

#include "src/Helpers/_CPlugin_Helper.h"
#ifdef USES_C017

// #######################################################################################################
// ########################### Controller Plugin 017: ZABBIX ##########################################
// #######################################################################################################
// Based on https://www.zabbix.com/documentation/cu ... ms/trapper
// and https://www.zabbix.com/documentation/4. ... er_datalen

// USAGE: at Zabbix server you go at Configuration -> Hosts -> Create host
// The "Host name" should match exactly the EspEasy name (Config -> Unit Name)
// Add a group (mandatory) and hit add. No need to set up IP address or agent.
// Go to the newly created host ->Items ->Create Item
// Name the item something descriptive
// For Key add the EspEasy task Value name (case sensitive)
// Type of information select "Numeric (float)" and press add.
// Aslo make sure that you enable send to controller (under Data Acquisition in tasks)
// and set an interval because you need to actively send the data to Zabbix

# define CPLUGIN_017
# define CPLUGIN_ID_017 17
# define CPLUGIN_NAME_017 "Zabbix"
# include <ArduinoJson.h>

bool CPlugin_017(CPlugin::Function function, struct EventStruct *event, String& string)
{
bool success = false;

switch (function)
{
case CPlugin::Function::CPLUGIN_PROTOCOL_ADD:
{
Protocol[++protocolCount].Number = CPLUGIN_ID_017;
Protocol[protocolCount].usesMQTT = false;
Protocol[protocolCount].usesTemplate = false;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = false;
Protocol[protocolCount].usesID = false;
Protocol[protocolCount].defaultPort = 10051;
break;
}

case CPlugin::Function::CPLUGIN_GET_DEVICENAME:
{
string = F(CPLUGIN_NAME_017);
break;
}

case CPlugin::Function::CPLUGIN_INIT:
{
success = init_c017_delay_queue(event->ControllerIndex);
break;
}

case CPlugin::Function::CPLUGIN_EXIT:
{
exit_c017_delay_queue();
break;
}

case CPlugin::Function::CPLUGIN_PROTOCOL_SEND:
{
if (C017_DelayHandler == nullptr) {
break;
}

success = C017_DelayHandler->addToQueue(C017_queue_element(event));
Scheduler.scheduleNextDelayQueue(ESPEasy_Scheduler::IntervalTimer_e::TIMER_C017_DELAY_QUEUE, C017_DelayHandler->getNextScheduleTime());
break;
}

case CPlugin::Function::CPLUGIN_FLUSH:
{
process_c017_delay_queue();
delay(0);
break;
}

default:
break;
}
return success;
}

// Uncrustify may change this into multi line, which will result in failed builds
// *INDENT-OFF*
bool do_process_c017_delay_queue(int controller_number, const C017_queue_element& element, ControllerSettingsStruct& ControllerSettings)
// *INDENT-ON*
{
if (element.valueCount == 0) {
return true; // exit if we don't have anything to send.
}

if (!NetworkConnected(10))
{
return false;
}

WiFiClient client;

if (!try_connect_host(controller_number, client, ControllerSettings, F("ZBX : ")))
{
return false;
}

const size_t capacity = JSON_ARRAY_SIZE(VARS_PER_TASK) + JSON_OBJECT_SIZE(2) + VARS_PER_TASK * JSON_OBJECT_SIZE(3) + VARS_PER_TASK * 50; //Size for esp8266 with 4 variables per task: 288+200
String JSON_packet_content;
{
// Place the JSON document in a separate scope to have it destructed as soon as it is no longer needed.
DynamicJsonDocument root(capacity);

// Create the schafolding
root[F("request")] = F("sender data");
JsonArray data = root.createNestedArray(F("data"));

// Populate JSON with the data
for (uint8_t i = 0; i < element.valueCount; i++)
{
const String taskValueName = getTaskValueName(element.TaskIndex, i);
if (taskValueName.isEmpty()) {
continue; // Zabbix will ignore an empty key anyway
}
JsonObject block = data.createNestedObject();
block[F("host")] = Settings.Name; // Zabbix hostname, Unit Name for the ESP easy
block[F("key")] = taskValueName; // Zabbix item key // Value Name for the ESP easy
float value = 0.0f;
validFloatFromString(element.txt, value);
block[F("value")] = value; // ESPeasy supports only floats
}
serializeJson(root, JSON_packet_content);
}

// Assemble packet
char packet_header[] = "ZBXD\1";

uint64_t payload_len = JSON_packet_content.length();

// addLog(LOG_LEVEL_INFO, String(F("ZBX: ")) + JSON_packet_content);
// Send the packet
client.write(packet_header, sizeof(packet_header) - 1);
client.write(reinterpret_cast<const char *>(&payload_len), sizeof(payload_len));
client.write(JSON_packet_content.c_str(), payload_len);

client.stop();
return true;
}

#endif // ifdef USES_C017

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 Zabbix Controller

#11 Post by Ath » 08 Jan 2023, 22:45

I was asking about your Zabbix server, that is supposed to receive the data from ESPEasy... :o
/Ton (PayPal.me)

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#12 Post by pp1wvc » 08 Jan 2023, 22:46

And the ADS1115 reporting a value of -32768, most likely isn't correct either, is it actually connected and working?
ADS115 is not working, but regardless, zabbix intem is in "float", note that with zabbix-sender this value is accepted by zabbix server. I suspect the plugin is not working for some reason.

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#13 Post by pp1wvc » 08 Jan 2023, 22:54

I was asking about your Zabbix server, that is supposed to receive the data from ESPEasy... :o

Receive only from zabbix-sender. The plugin for some reason cannot send the information to the zabbix server. :(

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 Zabbix Controller

#14 Post by Ath » 08 Jan 2023, 23:02

Ath wrote: 08 Jan 2023, 22:34 Does your Zabbix server accept HTTP connections on that port? As ESPEasy doesn't support HTTPS (yet).
pp1wvc wrote: 08 Jan 2023, 22:54 Receive only from zabbix-sender. The plugin for some reason cannot send the information to the zabbix server. :(
ESPEasy Controller is trying to send to your Zabbix server, don't worry about float or integer values, that's not the issue here.
Is the Zabbix server in your local network or somewhere on the internet?

NB: Please use the Quote button (right top of the message) to repeat something from a previous post.
NB2: No need to post source-code here, we have access to that, and most likely it is not something that needs changes, but some configuration item
/Ton (PayPal.me)

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#15 Post by pp1wvc » 08 Jan 2023, 23:16

Ath wrote: 08 Jan 2023, 23:02
Ath wrote: 08 Jan 2023, 22:34 Does your Zabbix server accept HTTP connections on that port? As ESPEasy doesn't support HTTPS (yet).
pp1wvc wrote: 08 Jan 2023, 22:54 Receive only from zabbix-sender. The plugin for some reason cannot send the information to the zabbix server. :(
ESPEasy Controller is trying to send to your Zabbix server, don't worry about float or integer values, that's not the issue here.
Is the Zabbix server in your local network or somewhere on the internet?

NB: Please use the Quote button (right top of the message) to repeat something from a previous post.
NB2: No need to post source-code here, we have access to that, and most likely it is not something that needs changes, but some configuration item

The Zabbix Server is on the same network and receives requests from the zabbix-sender with the same "IP" as Espeasy, this test was performed, it is not a firewall.
Could you send a backup with evidence of this plug-in working?

RB: Sorry for the repeated posts, I'm new to the forum.

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 Zabbix Controller

#16 Post by Ath » 09 Jan 2023, 10:11

It seems the ESPEasy unit is not allowed to connect to the Zabbix server. The fact it works from your computer isn't relevant, as that's not from the ESP. Can you try to use the SendToHTTP command to connect to the Zabbix server:

Code: Select all

SendToHTTP,<zabbix-ip>,10051,<some-url>
You can enter this on the Tools page of ESPEasy, to validate that the ESP can actually reach the server
/Ton (PayPal.me)

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#17 Post by pp1wvc » 09 Jan 2023, 11:51

Ath wrote: 09 Jan 2023, 10:11 It seems the ESPEasy unit is not allowed to connect to the Zabbix server. The fact it works from your computer isn't relevant, as that's not from the ESP. Can you try to use the SendToHTTP command to connect to the Zabbix server:

Code: Select all

SendToHTTP,<zabbix-ip>,10051,<some-url>
You can enter this on the Tools page of ESPEasy, to validate that the ESP can actually reach the server
Excuse my ignorance, but I don't know the meaning of <some-url>:
What does it mean?

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 Zabbix Controller

#18 Post by Ath » 09 Jan 2023, 12:01

You can type anything there, even a / would be enough to test the connection
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Zabbix Controller

#19 Post by TD-er » 09 Jan 2023, 12:13

I don't think the Zabbix controller uses HTTP calls.
If I remember correctly, it only makes a TCP (??) connection to some port.

So the main thing I can think of here is probably the timeout of the controller?

Does it make a difference when using an ESP8266 or ESP32? Problem is that the WiFiClient object on the ESP32 doesn't handle set timeouts well as all other platforms and classes set a timeout in msec and the WiFiClient on ESP32 sets it in seconds.

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#20 Post by pp1wvc » 09 Jan 2023, 17:13

Ath wrote: 09 Jan 2023, 12:01 You can type anything there, even a / would be enough to test the connection
Failed Command

Would it be possible to indicate which command to list the IP, DNS and Gateway through Espeasy?
Attachments
Evidencias SendToHTTP.jpg
Evidencias SendToHTTP.jpg (80.13 KiB) Viewed 25630 times

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#21 Post by pp1wvc » 09 Jan 2023, 17:17

TD-er wrote: 09 Jan 2023, 12:13 I don't think the Zabbix controller uses HTTP calls.
If I remember correctly, it only makes a TCP (??) connection to some port.

So the main thing I can think of here is probably the timeout of the controller?

Does it make a difference when using an ESP8266 or ESP32? Problem is that the WiFiClient object on the ESP32 doesn't handle set timeouts well as all other platforms and classes set a timeout in msec and the WiFiClient on ESP32 sets it in seconds.
As far as my knowledge goes, calls should be being received in TCP through these ports.

root@ubuntu:~# sudo netstat -ntpl | grep zabbix
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 2828/zabbix_server
tcp6 0 0 :::10050 :::* LISTEN 1359/zabbix_agent2
tcp6 0 0 :::10051 :::* LISTEN 2828/zabbix_server

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#22 Post by pp1wvc » 09 Jan 2023, 18:03

Ath wrote: 09 Jan 2023, 10:11 It seems the ESPEasy unit is not allowed to connect to the Zabbix server. The fact it works from your computer isn't relevant, as that's not from the ESP. Can you try to use the SendToHTTP command to connect to the Zabbix server:

Code: Select all

SendToHTTP,<zabbix-ip>,10051,<some-url>
You can enter this on the Tools page of ESPEasy, to validate that the ESP can actually reach the server
Through port 80 Espeasy reaches Zabbix Server
Attachments
SendToHTTP Port 80 OK.png
SendToHTTP Port 80 OK.png (23.58 KiB) Viewed 25625 times

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#23 Post by pp1wvc » 10 Jan 2023, 11:07

pp1wvc wrote: 09 Jan 2023, 11:51
Ath wrote: 09 Jan 2023, 10:11 It seems the ESPEasy unit is not allowed to connect to the Zabbix server. The fact it works from your computer isn't relevant, as that's not from the ESP. Can you try to use the SendToHTTP command to connect to the Zabbix server:

Code: Select all

SendToHTTP,<zabbix-ip>,10051,<some-url>
You can enter this on the Tools page of ESPEasy, to validate that the ESP can actually reach the server
Excuse my ignorance, but I don't know the meaning of <some-url>:
What does it mean?
TON, this is the Zabbix Server response to the command sent by ESPeasy:
Attachments
evidencia send test value.jpg
evidencia send test value.jpg (67.35 KiB) Viewed 25566 times
evidencias repostas zabbix server.jpg
evidencias repostas zabbix server.jpg (76.54 KiB) Viewed 25566 times

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 Zabbix Controller

#24 Post by Ath » 10 Jan 2023, 11:31

I think it is expecting a JSON message, you can have a hand-crafted one, on one line:

Code: Select all

SendToHTTP,<zabbix-ip>,10051,'{"data":["host":"EspEasy","key":"ADS1115","value":[ADS1115#Analog]]}'
(This seems to be the absolute minimum, if I'm reading the controller source correctly...)
(Instead of [ADS1115#Analog] you could also include a fixed numeric value)
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Zabbix Controller

#25 Post by TD-er » 10 Jan 2023, 12:31

Hmm maybe you should also check to see if the JSON requirements of Zabbix need a numerical be with or without quotes.
It may very well be the Zabbix implementation requires a string, even though it could very well be represented as a numerical.

Edit:
Just browsed back to the beginning of this topic.
The original issue is about not being able to connect to the server.
So the need for extra quotes (if any) should not trouble this issue.

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#26 Post by pp1wvc » 10 Jan 2023, 23:40

Ath wrote: 10 Jan 2023, 11:31 I think it is expecting a JSON message, you can have a hand-crafted one, on one line:

Code: Select all

SendToHTTP,<zabbix-ip>,10051,'{"data":["host":"EspEasy","key":"ADS1115","value":[ADS1115#Analog]]}'
(This seems to be the absolute minimum, if I'm reading the controller source correctly...)
(Instead of [ADS1115#Analog] you could also include a fixed numeric value)
TON, unsuccessful
Attachments
testHTPSend01.png
testHTPSend01.png (23.94 KiB) Viewed 25510 times
logEspasy.png
logEspasy.png (13.67 KiB) Viewed 25510 times
logZabbixServer.png
logZabbixServer.png (22.24 KiB) Viewed 25510 times

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#27 Post by pp1wvc » 15 Jan 2023, 17:59

TD-er wrote: 10 Jan 2023, 12:31 Hmm maybe you should also check to see if the JSON requirements of Zabbix need a numerical be with or without quotes.
It may very well be the Zabbix implementation requires a string, even though it could very well be represented as a numerical.

Edit:
Just browsed back to the beginning of this topic.
The original issue is about not being able to connect to the server.
So the need for extra quotes (if any) should not trouble this issue.
The zabbix controller is definitely not working. I suggest reviewing the publication of this controller. I don't know about plugin development, but to work with Espeasy I'll need to adapt. Any suggestions on where to look for plugin development other than the official documentation?
Attachments
Esp32senderOK.png
Esp32senderOK.png (17.57 KiB) Viewed 25425 times

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 Zabbix Controller

#28 Post by Ath » 15 Jan 2023, 19:40

Does the logging on the Zabbix side give some more information of what is not correct, other than saying "it's wrong"?

Trouble here is that I don't have a Zabbix server running, and as the Controller has been included for a really long time, without any modification, it either is working as intended for others, or it is not used at all. In the latter case that would be to 'blame' on the original author of the Controller.

The original issue, of not being able to connect seems to be resolved, correct? As you currently seem to get data from ESPEasy into Zabbix.

BTW, it's not unthinkable that the Zabbix protocol has changed over time to require any JSON numeric values to not/no longer be quoted, as the example shows. Maybe that can be configured in Zabbix to be backward compatible?
There is no setting in ESPEasy for that, so that would mean a small change in code has to be applied. I'll work on that.
/Ton (PayPal.me)

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#29 Post by pp1wvc » 15 Jan 2023, 20:46

The zabbix zabbix server ignores the message, just see the previous prints, I left it on record.
I can solve your problem, making my zabbix server available to carry out the tests, but there is a shorter way.
I'll leave the code that worked to transform it into a controller plugin, it's already working perfectly, follow the attached print.

Code: Select all

#include <ESP32ZabbixSender.h>

ESP32ZabbixSender zSender;

/* WiFi settings */
String ssid = "xxxyyy";
String pass = "xxxxyyyy";

/* Zabbix server setting */
#define SERVERADDR xxx, xxx, xx, xx // Zabbix server Address
#define ZABBIXPORT 10051			// Zabbix erver Port
#define ZABBIXAGHOST "Display"  // Zabbix item's host name
int val = 0;
boolean checkConnection();

void setup() {
	Serial.begin(115200);
	WiFi.mode(WIFI_STA);
	WiFi.disconnect();
	delay(100);
	WiFi.begin(ssid.c_str(), pass.c_str());
	while (!checkConnection()) {
	}
	zSender.Init(IPAddress(SERVERADDR), ZABBIXPORT, ZABBIXAGHOST); // Init zabbix server information
}

void loop() {
	val = hallRead();
	static int counter1 = 1;
	//static int counter2 = 1;
	checkConnection();							  // Check wifi connection
	zSender.ClearItem();						  // Clear ZabbixSender's item list
	zSender.AddItem("ADS1115", (float)val); // Exmaple value of zabbix trapper item
	//zSender.AddItem("counter2", (float)counter2); // Exmaple value of zabbix trapper item
	if (zSender.Send() == EXIT_SUCCESS) {		  // Send zabbix items
		Serial.println("ZABBIX SEND: OK");
	} else {
		Serial.println("ZABBIX SEND: NG");
	}
	counter1 += 1;
	//counter2 *= 2;
	delay(5000); // wait 1sec
}

boolean checkConnection() {
	int count = 0;
	Serial.print("Waiting for Wi-Fi connection");
	while (count < 300) {
		if (WiFi.status() == WL_CONNECTED) {
			Serial.println();
			Serial.println("Connected!");
			return (true);
		}
		delay(500);
		Serial.print(".");
		count++;
	}
	Serial.println("Timed out.");
	return false;
}
https://github.com/leruetkins/ESP32ZabbixSender
Attachments
ZabbixSenderOK.png
ZabbixSenderOK.png (36.78 KiB) Viewed 25405 times

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#30 Post by pp1wvc » 15 Jan 2023, 20:50

Ath wrote: 15 Jan 2023, 19:40 Does the logging on the Zabbix side give some more information of what is not correct, other than saying "it's wrong"?

Trouble here is that I don't have a Zabbix server running, and as the Controller has been included for a really long time, without any modification, it either is working as intended for others, or it is not used at all. In the latter case that would be to 'blame' on the original author of the Controller.

The original issue, of not being able to connect seems to be resolved, correct? As you currently seem to get data from ESPEasy into Zabbix.

BTW, it's not unthinkable that the Zabbix protocol has changed over time to require any JSON numeric values to not/no longer be quoted, as the example shows. Maybe that can be configured in Zabbix to be backward compatible?
There is no setting in ESPEasy for that, so that would mean a small change in code has to be applied. I'll work on that.
Sorry I myself am not able to turn it into a plugin, I know very little about the structure of espeasy, it will take a long time, the only way I can thank you for the development is to collaborate as a donor, which is what I will do.

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 Zabbix Controller

#31 Post by Ath » 15 Jan 2023, 21:51

I'll see if I can find that ESP32ZabbixSender code and find out what our Controller code does differently, as it already uses quite similar code.
/Ton (PayPal.me)

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#32 Post by pp1wvc » 15 Jan 2023, 22:50

Follow the link again TON.
https://github.com/leruetkins/ESP32ZabbixSender
I believe it is a simple task for someone who already knows how to build Espeasy plugins.

clumsy
New user
Posts: 6
Joined: 15 Apr 2018, 17:19

Re: ESP32 Zabbix Controller

#33 Post by clumsy » 29 Jan 2023, 20:12

I'm just migrating from LibreNMS to Zabbix to monitor my netowrk. For my ESPEasy devices I made a Zabbix-Template (WIP) that basically reads the JSON output via HTTP and puts it in Zabbix Items. Currently only System, Wifi and Task information is available, no sensor data though, as I use FHEM for processing the sensor data. My intension was really to monitor the ESPEasy's on a "System" availability and Information level (roughly 50 items are generated and can be monitored).

I have now ~50 ESPEasy's activated and actively monitored, which seems to work fine.

If anyone is interested, I'm happy to share the template. But be aware, still WIP ;)

regards

See also: https://github.com/letscontrolit/ESPEas ... 1407744288

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#34 Post by pp1wvc » 30 Jan 2023, 02:13

clumsy wrote: 29 Jan 2023, 20:12 I'm just migrating from LibreNMS to Zabbix to monitor my netowrk. For my ESPEasy devices I made a Zabbix-Template (WIP) that basically reads the JSON output via HTTP and puts it in Zabbix Items. Currently only System, Wifi and Task information is available, no sensor data though, as I use FHEM for processing the sensor data. My intension was really to monitor the ESPEasy's on a "System" availability and Information level (roughly 50 items are generated and can be monitored).

I have now ~50 ESPEasy's activated and actively monitored, which seems to work fine.

If anyone is interested, I'm happy to share the template. But be aware, still WIP ;)

regards

See also: https://github.com/letscontrolit/ESPEas ... 1407744288


Hello clumsy:
Could you share the template?
I don't understand what "WIP" is? :?:

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Zabbix Controller

#35 Post by TD-er » 30 Jan 2023, 08:32

WIP = Work-In-Progress :)

clumsy
New user
Posts: 6
Joined: 15 Apr 2018, 17:19

Re: ESP32 Zabbix Controller

#36 Post by clumsy » 30 Jan 2023, 08:53

pp1wvc wrote: 30 Jan 2023, 02:13 Could you share the template?
Sure, I attach the current version here. As TD-er mentioned correctly, this is still work in progress and changed often (adding items, triggers, graphs, finetuning of parameters, etc.). Can't attach yaml files, so I had to zip it...

Just to make it clear again, this template uses active HTTP-Polling of the nodes by Zabbix and NOT the zabbix controller from ESPEasy!! JSON has to be included in the ESPEasy build! Only system and task data, no sensor values!

Feel free to ask if something is not clear or suggest changes/updates!
Attachments
template_fhem_http.zip
(4.53 KiB) Downloaded 128 times

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#37 Post by pp1wvc » 13 Mar 2023, 15:13

clumsy wrote: 30 Jan 2023, 08:53
pp1wvc wrote: 30 Jan 2023, 02:13 Could you share the template?
Sure, I attach the current version here. As TD-er mentioned correctly, this is still work in progress and changed often (adding items, triggers, graphs, finetuning of parameters, etc.). Can't attach yaml files, so I had to zip it...

Just to make it clear again, this template uses active HTTP-Polling of the nodes by Zabbix and NOT the zabbix controller from ESPEasy!! JSON has to be included in the ESPEasy build! Only system and task data, no sensor values!

Feel free to ask if something is not clear or suggest changes/updates!
Thanks for posting your zabbix examples.
Would it be possible to post the configuration you used in espeasy?
I'm venturing into studies to fix the zabbix controller part. :)

clumsy
New user
Posts: 6
Joined: 15 Apr 2018, 17:19

Re: ESP32 Zabbix Controller

#38 Post by clumsy » 13 Mar 2023, 15:18

pp1wvc wrote: 13 Mar 2023, 15:13 Would it be possible to post the configuration you used in espeasy?
Sure, but which config? As said I don't use the zabbix controller of ESPEasy at all (not even compiled in in my versions)...

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#39 Post by pp1wvc » 13 Mar 2023, 15:29

clumsy wrote: 13 Mar 2023, 15:18
pp1wvc wrote: 13 Mar 2023, 15:13 Would it be possible to post the configuration you used in espeasy?
Sure, but which config? As said I don't use the zabbix controller of ESPEasy at all (not even compiled in in my versions)...
clumsy thanks for the feedback and interest in answering.
I need espeasy settings that send device state information (HTTP-Polling of the nodes by Zabbix...)
Just to really understand how you are using it and how zabbix is ​​handling this information.
I'm studying ways to convert the .ino file to .cpp (https://docs.platformio.org/en/latest/f ... o-cpp.html)
I believe this is the way to my solution :idea:

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Zabbix Controller

#40 Post by TD-er » 13 Mar 2023, 15:38

That's absolutely not needed to do.
ESPEasy does still have some .ino files and it can be compiled just fine using PlatformIO.

clumsy
New user
Posts: 6
Joined: 15 Apr 2018, 17:19

Re: ESP32 Zabbix Controller

#41 Post by clumsy » 13 Mar 2023, 15:53

pp1wvc wrote: 13 Mar 2023, 15:29 I need espeasy settings that send device state information (HTTP-Polling of the nodes by Zabbix...)
My nodes do not send anything actively to Zabbix. Zabbix is calling the /json page of the node (eg. http://node.my.domain/json) and then parse and evaluate the JSON information received (whatever is in there). This should work with any ESPEasy version that has JSON compiled in.

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#42 Post by pp1wvc » 13 Mar 2023, 15:59

TD-er wrote: 13 Mar 2023, 15:38 That's absolutely not needed to do.
ESPEasy does still have some .ino files and it can be compiled just fine using PlatformIO.
Zabbix expects information in this format;
Json += "{\"host\":\"" + zItemHost + "\",\"key\":\"" + zabbixItemList.key + "\",\"value\":\" " + zabbixItemList.val + "\"}";
I'm studying to understand the conversion because espeasy is being updated natively to this format, correct?
The Zabbix Controller used by espeasy is not sending in this format, so it doesn't work. :|

clumsy
New user
Posts: 6
Joined: 15 Apr 2018, 17:19

Re: ESP32 Zabbix Controller

#43 Post by clumsy » 13 Mar 2023, 16:03

pp1wvc wrote: 13 Mar 2023, 15:59
Zabbix expects information in this format;
Json += "{\"host\":\"" + zItemHost + "\",\"key\":\"" + zabbixItemList.key + "\",\"value\":\" " + zabbixItemList.val + "\"}";
I'm studying to understand the conversion because espeasy is being updated natively to this format, correct?
The Zabbix Controller used by espeasy is not sending in this format, so it doesn't work. :|


That's why I use the possibility in Zabbix to grab an URL with a HTTP call and then parse the result (especially easy when the answer is in JSON format).

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#44 Post by pp1wvc » 13 Mar 2023, 16:04

clumsy wrote: 13 Mar 2023, 15:53
pp1wvc wrote: 13 Mar 2023, 15:29 I need espeasy settings that send device state information (HTTP-Polling of the nodes by Zabbix...)
My nodes do not send anything actively to Zabbix. Zabbix is calling the /json page of the node (eg. http://node.my.domain/json) and then parse and evaluate the JSON information received (whatever is in there). This should work with any ESPEasy version that has JSON compiled in.
I understand, but there is a difficulty in practical scenarios where you use CGNAT, the easiest way would be to send the information to the zabbix server. ;)

clumsy
New user
Posts: 6
Joined: 15 Apr 2018, 17:19

Re: ESP32 Zabbix Controller

#45 Post by clumsy » 13 Mar 2023, 16:06

pp1wvc wrote: 13 Mar 2023, 16:04 I understand, but there is a difficulty in practical scenarios where you use CGNAT, the easiest way would be to send the information to the zabbix server. ;)
So feel free to implement, I'm happy to test the controller then.

However, as I only need system information on my Zabbix (and no sensor data) I'm quite happy with the HTTP call (as this I also can test if the node is still alive). Sensor data is sent with a different controller to my HA server.. And I try to keep my binaries as small as possible and only include what I really need when compiling it.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Zabbix Controller

#46 Post by TD-er » 13 Mar 2023, 16:13

pp1wvc wrote: 13 Mar 2023, 15:59
TD-er wrote: 13 Mar 2023, 15:38 That's absolutely not needed to do.
ESPEasy does still have some .ino files and it can be compiled just fine using PlatformIO.
Zabbix expects information in this format;
Json += "{\"host\":\"" + zItemHost + "\",\"key\":\"" + zabbixItemList.key + "\",\"value\":\" " + zabbixItemList.val + "\"}";
I'm studying to understand the conversion because espeasy is being updated natively to this format, correct?
The Zabbix Controller used by espeasy is not sending in this format, so it doesn't work. :|


Still you don't need to convert .ino files to .cpp/.h files in order to build it using PlatformIO.
So better not waste time in that research area :)
Not saying it isn't good to know how and why such a conversion might be useful, but to be honest it has extremely little to do with the problem you're trying to solve.

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#47 Post by pp1wvc » 14 Mar 2023, 09:41

TD-er wrote: 13 Mar 2023, 16:13
pp1wvc wrote: 13 Mar 2023, 15:59
TD-er wrote: 13 Mar 2023, 15:38 That's absolutely not needed to do.
ESPEasy does still have some .ino files and it can be compiled just fine using PlatformIO.
Zabbix expects information in this format;
Json += "{\"host\":\"" + zItemHost + "\",\"key\":\"" + zabbixItemList.key + "\",\"value\":\" " + zabbixItemList.val + "\"}";
I'm studying to understand the conversion because espeasy is being updated natively to this format, correct?
The Zabbix Controller used by espeasy is not sending in this format, so it doesn't work. :|


Still you don't need to convert .ino files to .cpp/.h files in order to build it using PlatformIO.
So better not waste time in that research area :)
Not saying it isn't good to know how and why such a conversion might be useful, but to be honest it has extremely little to do with the problem you're trying to solve.


My problem boils down to the zabbix controller not working. Being very objective, my problem can be summarized in these few lines:
WiFiClient client;

if (!try_connect_host(controller_number, client, ControllerSettings, F("ZBX : ")))
{
return false;
}

It tries to create a TCP connection through WiFiClient which does not work in the latest versions of zabbix.
I suggest that you remove this controller in the next versions, as it is not working, unless you really have a solution.

The solution I'm looking for is to create a new controller based on a .ino file that is tested and working and convert it to the controller format.
There is no controller example in espeasy, only a plugin example, it could help me a lot, guiding which example targets would best suit my research within the structure of Espeasy. ;)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Zabbix Controller

#48 Post by TD-er » 14 Mar 2023, 10:50

I don't see how creating a new one is better than just fixing what's apparently broken.

Just a few pointers for you to test/check as I don't have a Zabbix server/service running here.

- Check the timeout in the controller and set it to as high as possible to make sure this isn't a timeout issue. (e.g. 1000 msec)
- Test with both waiting for a reply and ignoring it in both the controller settings as well as in the tools->Advanced settings on "SendToHTTP"
- Try adding some debug code to see why making the connection fails. (e.g. http error code could help here)

pp1wvc
Normal user
Posts: 38
Joined: 06 Jan 2023, 12:02
Location: Brazil

Re: ESP32 Zabbix Controller

#49 Post by pp1wvc » 14 Mar 2023, 11:11

TD-er wrote: 13 Mar 2023, 16:13
pp1wvc wrote: 13 Mar 2023, 15:59
TD-er wrote: 13 Mar 2023, 15:38 That's absolutely not needed to do.
ESPEasy does still have some .ino files and it can be compiled just fine using PlatformIO.
Zabbix expects information in this format;
Json += "{\"host\":\"" + zItemHost + "\",\"key\":\"" + zabbixItemList.key + "\",\"value\":\" " + zabbixItemList.val + "\"}";
I'm studying to understand the conversion because espeasy is being updated natively to this format, correct?
The Zabbix Controller used by espeasy is not sending in this format, so it doesn't work. :|


Still you don't need to convert .ino files to .cpp/.h files in order to build it using PlatformIO.
So better not waste time in that research area :)
Not saying it isn't good to know how and why such a conversion might be useful, but to be honest it has extremely little to do with the problem you're trying to solve.


you don't understand, the zabbix controller is not broken. The new versions of Zabbix do not accept this type of work, I have already tested it in other ways and it did not work.
This example works in zabbix 4.2, but is no longer supported in the latest versions:

#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <ArduinoJson.h>

const char* ssid = "YourAccessPointName";
const char* password = "YourAccessPointPassword";
const char* zbx_server = "YourZabbixServerIPaddr";

Ticker ticker;
bool readyForTicker = false;

void setReadyForTicker() {
// A flag
readyForTicker = true;
}

int value = 0;
void doBlockingIO() {

uint64_t payloadsize ;

// dummy value increment
++value;

// create "zabbix sender format" json data for sending zabbix server
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["request"] = "sender data";

JsonArray& data = root.createNestedArray("data");

JsonObject& item = jsonBuffer.createObject();
item["host"] = "Home Network";
item["key"] = "test";
item["value"] = value;
data.add(item);

/*
// zabbix sender can send more items at once
JsonObject& item2 = jsonBuffer.createObject();
item2["host"] = "Home Network";
item2["key"] = "test2";
item2["value"] = "hello";
data.add(item2);
*/

Serial.println();
Serial.println("== request ================");
root.printTo(Serial);

Serial.println("");
Serial.println("============================");
char buffer[256];
root.printTo(buffer, sizeof(buffer));
Serial.print("payload json size: ");
Serial.println(strlen(buffer));
Serial.println("============================");


//////////////////////////////
// connect to zabbix server
Serial.print("connecting to ");
Serial.println(zabbix_server);

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int zabbixPort = 10051 ;
if (!client.connect(zabbix_server, zabbixPort)) {
Serial.println("connection failed");
return;
}


//////////////////////////////
// send the zabbix_sender's format data to server

// send fixed header to zabbix server
client.print(String("ZBXD") );
client.write(0x01);

// send json size to zabbix server
payloadsize = strlen(buffer);
for (int i = 0; i < 64; i += 8) {
client.write(lowByte(payloadsize >> i));
}

// send json to zabbix server
client.print(buffer);
//////////////////////////////


unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}

// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.println("== response ================");
Serial.print(line);
Serial.println("");
Serial.println("============================");
}

Serial.println();
Serial.println("closing connection");

// Drop the flag
readyForTicker = false;
}

void setup() {
Serial.begin(115200);
delay(10);

// We start by connecting to a WiFi network

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());


// call setReadyForTicker() every 60 seconds
ticker.attach(60, setReadyForTicker);
}

void loop() {
if (readyForTicker) {
doBlockingIO();
}
}




https://qiita.com/mutz0623/items/2c7eae0f762d760875bb

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 Zabbix Controller

#50 Post by TD-er » 14 Mar 2023, 11:20

OK, so there is a new way to interact with Zabbix.
This might indeed warrant a new controller, or if the protocol isn't that different, a checkbox in the controller settings for Zabbix to set the right protocol.

But this doesn't mean all existing Zabbix environments out there will immediately be phased out, so if the Zabbix controller in ESPEasy is still working with older versions, we should not remove the (current) Zabbix controller from ESPEasy.

Or am I still missing the point here?

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests