Skip to content

Commit

Permalink
zabbix trap sender fixed #16
Browse files Browse the repository at this point in the history
  • Loading branch information
roema committed Oct 31, 2021
1 parent 15f215f commit 4fdd030
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 22 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ Very rudimentary. Some parameters will be added in the future.

![alt text](https://ros-it.ch/wp-content/uploads/2020/12/zabbix_2-1024x205.png)

If you have zabbix agent installed on you machine, you can test your server configuration with

```
zabbix_sender -z <you server ip> -p 10051 -s ogn_base -k voltage -o 5.25
```

I am always open to wishes and suggestions, but would also like to emphasize that I do this project in my spare time. I am not responsible for any damage caused by this software.


Expand Down
19 changes: 10 additions & 9 deletions libraries/zabbix-sender/zabbixSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,41 @@ ZabbixSender::~ZabbixSender() {
// String createPayload(const char *hostname, float voltage, float rssi, int uptime, int gnss, int timestamp, int lrx);

String ZabbixSender::createPayload(const char *hostname, float voltage, float rssi, int uptime, int gnss, int timestamp, int lrx) {
DynamicJsonDocument root(1024);
StaticJsonDocument<1024> root;

root["request"] = "sender data";

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

DynamicJsonDocument data_0(768);
JsonObject data_0 = data.createNestedObject();
data_0["host"] = hostname;
data_0["key"] = "voltage";
data_0["value"] = voltage;


DynamicJsonDocument data_1 = data.createNestedObject();
JsonObject data_1 = data.createNestedObject();
data_1["host"] = hostname;
data_1["key"] = "rssi";
data_1["value"] = rssi;

DynamicJsonDocument data_2 = data.createNestedObject();
JsonObject data_2 = data.createNestedObject();
data_2["host"] = hostname;
data_2["key"] = "uptime";
data_2["value"] = uptime;

DynamicJsonDocument data_3 = data.createNestedObject();
JsonObject data_3 = data.createNestedObject();
data_3["host"] = hostname;
data_3["key"] = "gnss";
data_3["value"] = gnss;

DynamicJsonDocument data_4 = data.createNestedObject();
JsonObject data_4 = data.createNestedObject();
data_4["host"] = hostname;
data_4["key"] = "timestamp";
data_4["value"] = timestamp;

DynamicJsonDocument data_5 = data.createNestedObject();
JsonObject data_5 = data.createNestedObject();
data_5["host"] = hostname;
data_5["key"] = "lrx";
data_5["key"] = "maxrange";
data_5["value"] = lrx;


Expand Down
29 changes: 22 additions & 7 deletions ognbase/MONIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
#include "zabbixSender.h"
#include "global.h"
#include "GNSS.h"
#include "Log.h"

#define hours() (millis() / 3600000)


WiFiClient zclient;

bool config_status;

void MONIT_send_trap()
Expand All @@ -39,13 +38,29 @@ void MONIT_send_trap()
{
ZabbixSender zs;
String jsonPayload;
String msg;

msg = "sending zabbix trap to ";
msg += zabbix_server.c_str();
msg += ":";
msg += zabbix_port;
Logger_send_udp(&msg);

jsonPayload = zs.createPayload(zabbix_key.c_str(), Battery_voltage(), RF_last_rssi, int(hours()), gnss.satellites.value(), ThisAircraft.timestamp, largest_range);

String zb_msg = zs.createMessage(jsonPayload);

jsonPayload = zs.createPayload(zabbix_server.c_str(), Battery_voltage(), RF_last_rssi, int(hours()), gnss.satellites.value(), ThisAircraft.timestamp, largest_range);
Logger_send_udp(&jsonPayload);

String msg = zs.createMessage(jsonPayload);
//byte buffer[zb_msg.length() + 1];
//zb_msg.getBytes(buffer, zb_msg.length() + 1);

if (zclient.connect(zabbix_server.c_str(), zabbix_port, timeout))
zclient.print(msg);
zclient.stop();
SoC->WiFi_connect_TCP2(zabbix_server.c_str(), zabbix_port);
SoC->WiFi_transmit_TCP2(zb_msg);
SoC->WiFi_disconnect_TCP2();


//SoC->WiFi_transmit_UDP(zabbix_server.c_str(), zabbix_port, buffer, zb_msg.length() + 1);

}
}
57 changes: 57 additions & 0 deletions ognbase/Platform_ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ lmic_pinmap lmic_pins = {
WebServer server(80);

AXP20X_Class axp;

WiFiClient client;
WiFiClient zclient;

static TFT_eSPI* tft = NULL;

Expand Down Expand Up @@ -716,6 +718,56 @@ static int ESP32_WiFi_isconnected_TCP()
return client.connected();
}

static int ESP32_WiFi_connect_TCP2(const char* host, int port)
{
bool ret = Ping.ping(host, 2);

if (ret)
{
if (!zclient.connect(host, port, 5000))
return 0;
return 1;
}
return 0;
}

static int ESP32_WiFi_disconnect_TCP2()
{
zclient.stop();
}

static int ESP32_WiFi_transmit_TCP2(String message)
{
if (zclient.connected())
{
zclient.print(message);
return 0;
}
return 0;
}

static int ESP32_WiFi_receive_TCP2(char* RXbuffer, int RXbuffer_size)
{
int i = 0;

if (zclient.connected())
{
while (zclient.available() && i < RXbuffer_size - 1) {
RXbuffer[i] = zclient.read();
i++;
RXbuffer[i] = '\0';
}
return i;
}
zclient.stop();
return -1;
}

static int ESP32_WiFi_isconnected_TCP2()
{
return zclient.connected();
}

static void ESP32_WiFiUDP_stopAll()
{
/* not implemented yet */
Expand Down Expand Up @@ -933,6 +985,11 @@ const SoC_ops_t ESP32_ops = {
ESP32_WiFi_transmit_TCP,
ESP32_WiFi_receive_TCP,
ESP32_WiFi_isconnected_TCP,
ESP32_WiFi_connect_TCP2,
ESP32_WiFi_disconnect_TCP2,
ESP32_WiFi_transmit_TCP2,
ESP32_WiFi_receive_TCP2,
ESP32_WiFi_isconnected_TCP2,
ESP32_WiFiUDP_stopAll,
ESP32_WiFi_hostname,
ESP32_WiFi_clients_count,
Expand Down
5 changes: 5 additions & 0 deletions ognbase/SoC.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ typedef struct SoC_ops_struct
int (* WiFi_transmit_TCP)(String);
int (* WiFi_receive_TCP)(char *, int);
int (* WiFi_isconnected_TCP)();
int (* WiFi_connect_TCP2)(const char *, int);
int (* WiFi_disconnect_TCP2)();
int (* WiFi_transmit_TCP2)(String);
int (* WiFi_receive_TCP2)(char *, int);
int (* WiFi_isconnected_TCP2)();
void (* WiFiUDP_stopAll)();
bool (* WiFi_hostname)(String);
int (* WiFi_clients_count)();
Expand Down
10 changes: 5 additions & 5 deletions ognbase/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#define _VERSION_MAJOR 0
#define _VERSION_MINOR 1
#define _VERSION_PATCH 0
#define _VERSION_BUILD 25
#define _VERSION_DATE "24/10/2021"
#define _VERSION_TIME "11:41:12"
#define _VERSION_BUILD 26
#define _VERSION_DATE "31/10/2021"
#define _VERSION_TIME "12:11:36"
#define _VERSION_ONLY "0.1.0"
#define _VERSION_NOBUILD "0.1.0 (24/10/2021)"
#define _VERSION "0.1.0-25"
#define _VERSION_NOBUILD "0.1.0 (31/10/2021)"
#define _VERSION "0.1.0-26"
//The version information is created automatically, more information here: https://github.com/rvdbreemen/autoinc-semver
2 changes: 1 addition & 1 deletion tools/udp_log_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
sys.exit(1)


UDP_IP_ADDRESS = "10.0.1.200"
UDP_IP_ADDRESS = "10.0.0.200"

serverSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
serverSock.bind((UDP_IP_ADDRESS, UDP_PORT_NO))
Expand Down

0 comments on commit 4fdd030

Please sign in to comment.