Skip to content

Commit

Permalink
zabbix implementation & update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
roema committed Dec 24, 2020
1 parent bef6e55 commit 8bef0a4
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 96 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,13 @@ should look something like this..

Please note that pictures are not necessarily up to date!

![alt text](https://ros-it.ch/wp-content/uploads/2020/11/OGN_Base.png.png)
![alt text](https://ros-it.ch/wp-content/uploads/2020/12/ogn-768x696.png)

## Simple monitoring with zabbix trapper

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

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

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
111 changes: 111 additions & 0 deletions libraries/zabbix-sender/zabbixSender.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
MIT License
Copyright (c) 2018 IntelliTrend GmbH, http://www.intellitrend.de
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <string>
#include <ArduinoJson.h>
#include "zabbixSender.h"

ZabbixSender::ZabbixSender() {
}

ZabbixSender::ZabbixSender(const ZabbixSender& orig) {
}

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) {
DynamicJsonBuffer jsonBuffer(ZJSONBUFFER_SIZE);
JsonObject& root = jsonBuffer.createObject();
root["request"] = "sender data";

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

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

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

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

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

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

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



String json;
root.printTo(json);
return json;
}

/**
* Create message to send to zabbix based on payload
*/
String ZabbixSender::createMessage(String jsonPayload) {
String header = "ZBXD\x01";
// we will use only 2 bytes, will never exceed length = 65565
String placeholderLen = "12345678";
String msg = header + placeholderLen + jsonPayload;
uint16_t len = jsonPayload.length();

// patch the string
char zNull = '\x00';
unsigned char lenLsb = (unsigned char) (len & 0xFF);
unsigned char lenMsb = (unsigned char) ((len >> 8)& 0xFF);

msg.setCharAt(5, lenLsb);
msg.setCharAt(6, lenMsb);
// len padding
msg.setCharAt(7, zNull);
msg.setCharAt(8, zNull);
msg.setCharAt(9, zNull);
msg.setCharAt(10, zNull);
msg.setCharAt(11, zNull);
msg.setCharAt(12, zNull);

return msg;
}

45 changes: 45 additions & 0 deletions libraries/zabbix-sender/zabbixSender.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
MIT License
Copyright (c) 2018 IntelliTrend GmbH, http://www.intellitrend.de
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef ZABBIXSENDER_H
#define ZABBIXSENDER_H

#include <stdio.h>
#include <string>

#ifndef ZJSONBUFFER_SIZE
#define ZJSONBUFFER_SIZE 1100
#endif

class ZabbixSender {
public:
ZabbixSender();
ZabbixSender(const ZabbixSender& orig);
virtual ~ZabbixSender();
String createPayload(const char *hostname, float voltage, float rssi, int uptime, int gnss, int timestamp, int lrx);
String createMessage(String jsonPayload);
private:
};

#endif /* ZABBIXSENDER_H */
188 changes: 94 additions & 94 deletions ognbase/EEPROM.h
Original file line number Diff line number Diff line change
@@ -1,94 +1,94 @@
/*
* EEPROM.h
* Copyright (C) 2019-2020 Linar Yusupov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef EEPROMHELPER_H
#define EEPROMHELPER_H

#include "SoC.h"

#if !defined(EXCLUDE_EEPROM)
#include <EEPROM.h>
#endif /* EXCLUDE_EEPROM */

#define SOFTRF_EEPROM_MAGIC 0xBABADEDA
#define SOFTRF_EEPROM_VERSION 0x0000005E

typedef struct Settings
{
uint8_t mode;
uint8_t rf_protocol;
uint8_t band;
uint8_t aircraft_type;
uint8_t txpower;
uint8_t volume;
uint8_t led_num;
uint8_t pointer;

bool nmea_g : 1;
bool nmea_p : 1;
bool nmea_l : 1;
bool nmea_s : 1;
bool resvd1 : 1;
uint8_t nmea_out : 3;

uint8_t bluetooth : 3; /* ESP32 built-in Bluetooth */
uint8_t alarm : 3;
bool stealth : 1;
bool no_track : 1;

uint8_t gdl90 : 3;
uint8_t d1090 : 3;
uint8_t json : 2;

uint8_t power_save;
int8_t freq_corr; /* +/-, kHz */
int16_t range; /*OGN Basestation max Range*/
bool sxlna; /*SX1276 agcref settings*/
bool ogndebug; /*debug on*/
uint16_t ogndebugp; /*debug port*/
bool ignore_stealth;
bool ignore_no_track;
uint8_t rf_protocol2;
uint8_t sleep_mode;
uint16_t sleep_after_rx_idle;
uint16_t wake_up_timer;
uint8_t resvd15;
} settings_t;

typedef struct EEPROM_S
{
uint32_t magic;
uint32_t version;
settings_t settings;
} eeprom_struct_t;

typedef union EEPROM_U
{
eeprom_struct_t field;
uint8_t raw[sizeof(eeprom_struct_t)];
} eeprom_t;

void EEPROM_setup(void);

void EEPROM_defaults(void);

void EEPROM_store(void);

extern settings_t* settings;

#endif /* EEPROMHELPER_H */
/*
* EEPROM.h
* Copyright (C) 2019-2020 Linar Yusupov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef EEPROMHELPER_H
#define EEPROMHELPER_H

#include "SoC.h"

#if !defined(EXCLUDE_EEPROM)
#include <EEPROM.h>
#endif /* EXCLUDE_EEPROM */

#define SOFTRF_EEPROM_MAGIC 0xBABADEDA
#define SOFTRF_EEPROM_VERSION 0x0000005E

typedef struct Settings
{
uint8_t mode;
uint8_t rf_protocol;
uint8_t band;
uint8_t aircraft_type;
uint8_t txpower;
uint8_t volume;
uint8_t led_num;
uint8_t pointer;

bool nmea_g : 1;
bool nmea_p : 1;
bool nmea_l : 1;
bool nmea_s : 1;
bool resvd1 : 1;
uint8_t nmea_out : 3;

uint8_t bluetooth : 3; /* ESP32 built-in Bluetooth */
uint8_t alarm : 3;
bool stealth : 1;
bool no_track : 1;

uint8_t gdl90 : 3;
uint8_t d1090 : 3;
uint8_t json : 2;

uint8_t power_save;
int8_t freq_corr; /* +/-, kHz */
int16_t range; /*OGN Basestation max Range*/
bool sxlna; /*SX1276 agcref settings*/
bool ogndebug; /*debug on*/
uint16_t ogndebugp; /*debug port*/
bool ignore_stealth;
bool ignore_no_track;
uint8_t rf_protocol2;
uint8_t sleep_mode;
uint16_t sleep_after_rx_idle;
uint16_t wake_up_timer;
uint8_t zabbix_en;
} settings_t;

typedef struct EEPROM_S
{
uint32_t magic;
uint32_t version;
settings_t settings;
} eeprom_struct_t;

typedef union EEPROM_U
{
eeprom_struct_t field;
uint8_t raw[sizeof(eeprom_struct_t)];
} eeprom_t;

void EEPROM_setup(void);

void EEPROM_defaults(void);

void EEPROM_store(void);

extern settings_t* settings;

#endif /* EEPROMHELPER_H */
Loading

0 comments on commit 8bef0a4

Please sign in to comment.