Added Nagios formated Output of DMR Master connection
A new config variable called NagiosStatusFile was introduced in section General. Output formated to be used directly in Nagios is generated, preferable to be stored in a ramdisk like /dev/shm/... . If the program is closed, there should be a last write to this status file with status "Unkown", but unfortunately this is not working yet.
This commit is contained in:
parent
0a74e8270f
commit
c71e9ebc4b
6 changed files with 81 additions and 7 deletions
25
Conf.cpp
25
Conf.cpp
|
@ -51,6 +51,7 @@ m_timeout(120U),
|
||||||
m_duplex(true),
|
m_duplex(true),
|
||||||
m_modeHang(10U),
|
m_modeHang(10U),
|
||||||
m_display(),
|
m_display(),
|
||||||
|
m_NagiosStatusFile(),
|
||||||
m_rxFrequency(0U),
|
m_rxFrequency(0U),
|
||||||
m_txFrequency(0U),
|
m_txFrequency(0U),
|
||||||
m_power(0U),
|
m_power(0U),
|
||||||
|
@ -173,9 +174,12 @@ bool CConf::read()
|
||||||
|
|
||||||
char* value = ::strtok(NULL, "\r\n");
|
char* value = ::strtok(NULL, "\r\n");
|
||||||
if (section == SECTION_GENERAL) {
|
if (section == SECTION_GENERAL) {
|
||||||
if (::strcmp(key, "Callsign") == 0)
|
if (::strcmp(key, "Callsign") == 0) {
|
||||||
|
// Convert the callsign to upper case
|
||||||
|
for (unsigned int i = 0U; value[i] != 0; i++)
|
||||||
|
value[i] = ::toupper(value[i]);
|
||||||
m_callsign = value;
|
m_callsign = value;
|
||||||
else if (::strcmp(key, "Timeout") == 0)
|
} else if (::strcmp(key, "Timeout") == 0)
|
||||||
m_timeout = (unsigned int)::atoi(value);
|
m_timeout = (unsigned int)::atoi(value);
|
||||||
else if (::strcmp(key, "Duplex") == 0)
|
else if (::strcmp(key, "Duplex") == 0)
|
||||||
m_duplex = ::atoi(value) == 1;
|
m_duplex = ::atoi(value) == 1;
|
||||||
|
@ -183,6 +187,8 @@ bool CConf::read()
|
||||||
m_modeHang = (unsigned int)::atoi(value);
|
m_modeHang = (unsigned int)::atoi(value);
|
||||||
else if (::strcmp(key, "Display") == 0)
|
else if (::strcmp(key, "Display") == 0)
|
||||||
m_display = value;
|
m_display = value;
|
||||||
|
else if (::strcmp(key, "NagiosStatusFile") == 0)
|
||||||
|
m_NagiosStatusFile = value;
|
||||||
} else if (section == SECTION_INFO) {
|
} else if (section == SECTION_INFO) {
|
||||||
if (::strcmp(key, "TXFrequency") == 0)
|
if (::strcmp(key, "TXFrequency") == 0)
|
||||||
m_txFrequency = (unsigned int)::atoi(value);
|
m_txFrequency = (unsigned int)::atoi(value);
|
||||||
|
@ -235,15 +241,18 @@ bool CConf::read()
|
||||||
} else if (section == SECTION_DSTAR) {
|
} else if (section == SECTION_DSTAR) {
|
||||||
if (::strcmp(key, "Enable") == 0)
|
if (::strcmp(key, "Enable") == 0)
|
||||||
m_dstarEnabled = ::atoi(value) == 1;
|
m_dstarEnabled = ::atoi(value) == 1;
|
||||||
else if (::strcmp(key, "Module") == 0)
|
else if (::strcmp(key, "Module") == 0) {
|
||||||
|
// Convert the module to upper case
|
||||||
|
for (unsigned int i = 0U; value[i] != 0; i++)
|
||||||
|
value[i] = ::toupper(value[i]);
|
||||||
m_dstarModule = value;
|
m_dstarModule = value;
|
||||||
else if (::strcmp(key, "SelfOnly") == 0)
|
} else if (::strcmp(key, "SelfOnly") == 0)
|
||||||
m_dstarSelfOnly = ::atoi(value) == 1;
|
m_dstarSelfOnly = ::atoi(value) == 1;
|
||||||
else if (::strcmp(key, "BlackList") == 0) {
|
else if (::strcmp(key, "BlackList") == 0) {
|
||||||
char* p = ::strtok(value, ",\r\n");
|
char* p = ::strtok(value, ",\r\n");
|
||||||
while (p != NULL) {
|
while (p != NULL) {
|
||||||
if (::strlen(p) > 0U) {
|
if (::strlen(p) > 0U) {
|
||||||
for (unsigned int i = 0U; p[i] != 0U; i++)
|
for (unsigned int i = 0U; p[i] != 0; i++)
|
||||||
p[i] = ::toupper(p[i]);
|
p[i] = ::toupper(p[i]);
|
||||||
std::string callsign = std::string(p);
|
std::string callsign = std::string(p);
|
||||||
callsign.resize(DSTAR_LONG_CALLSIGN_LENGTH, ' ');
|
callsign.resize(DSTAR_LONG_CALLSIGN_LENGTH, ' ');
|
||||||
|
@ -379,6 +388,12 @@ std::string CConf::getDisplay() const
|
||||||
return m_display;
|
return m_display;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CConf::getNagiosStatusFile() const
|
||||||
|
{
|
||||||
|
return m_NagiosStatusFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int CConf::getRxFrequency() const
|
unsigned int CConf::getRxFrequency() const
|
||||||
{
|
{
|
||||||
return m_rxFrequency;
|
return m_rxFrequency;
|
||||||
|
|
2
Conf.h
2
Conf.h
|
@ -36,6 +36,7 @@ public:
|
||||||
bool getDuplex() const;
|
bool getDuplex() const;
|
||||||
unsigned int getModeHang() const;
|
unsigned int getModeHang() const;
|
||||||
std::string getDisplay() const;
|
std::string getDisplay() const;
|
||||||
|
std::string getNagiosStatusFile() const;
|
||||||
|
|
||||||
// The Info section
|
// The Info section
|
||||||
unsigned int getRxFrequency() const;
|
unsigned int getRxFrequency() const;
|
||||||
|
@ -129,6 +130,7 @@ private:
|
||||||
bool m_duplex;
|
bool m_duplex;
|
||||||
unsigned int m_modeHang;
|
unsigned int m_modeHang;
|
||||||
std::string m_display;
|
std::string m_display;
|
||||||
|
std::string m_NagiosStatusFile;
|
||||||
|
|
||||||
unsigned int m_rxFrequency;
|
unsigned int m_rxFrequency;
|
||||||
unsigned int m_txFrequency;
|
unsigned int m_txFrequency;
|
||||||
|
|
43
DMRIPSC.cpp
43
DMRIPSC.cpp
|
@ -62,6 +62,7 @@ m_height(0),
|
||||||
m_location(),
|
m_location(),
|
||||||
m_description(),
|
m_description(),
|
||||||
m_url(),
|
m_url(),
|
||||||
|
m_NagiosStatusFile(),
|
||||||
m_beacon(false)
|
m_beacon(false)
|
||||||
{
|
{
|
||||||
assert(!address.empty());
|
assert(!address.empty());
|
||||||
|
@ -96,7 +97,7 @@ CDMRIPSC::~CDMRIPSC()
|
||||||
delete[] m_id;
|
delete[] m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDMRIPSC::setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, float latitude, float longitude, int height, const std::string& location, const std::string& description, const std::string& url)
|
void CDMRIPSC::setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, float latitude, float longitude, int height, const std::string& location, const std::string& description, const std::string& url, const std::string& NagiosStatusFile)
|
||||||
{
|
{
|
||||||
m_callsign = callsign;
|
m_callsign = callsign;
|
||||||
m_rxFrequency = rxFrequency;
|
m_rxFrequency = rxFrequency;
|
||||||
|
@ -109,6 +110,7 @@ void CDMRIPSC::setConfig(const std::string& callsign, unsigned int rxFrequency,
|
||||||
m_location = location;
|
m_location = location;
|
||||||
m_description = description;
|
m_description = description;
|
||||||
m_url = url;
|
m_url = url;
|
||||||
|
m_NagiosStatusFile = NagiosStatusFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDMRIPSC::open()
|
bool CDMRIPSC::open()
|
||||||
|
@ -396,6 +398,7 @@ void CDMRIPSC::clock(unsigned int ms)
|
||||||
m_timeoutTimer.stop();
|
m_timeoutTimer.stop();
|
||||||
m_retryTimer.stop();
|
m_retryTimer.stop();
|
||||||
}
|
}
|
||||||
|
writeNagiosOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDMRIPSC::writeLogin()
|
bool CDMRIPSC::writeLogin()
|
||||||
|
@ -486,3 +489,41 @@ bool CDMRIPSC::write(const unsigned char* data, unsigned int length)
|
||||||
|
|
||||||
return m_socket.write(data, length, m_address, m_port);
|
return m_socket.write(data, length, m_address, m_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool CDMRIPSC::writeNagiosOutput()
|
||||||
|
{
|
||||||
|
std::ofstream nagiosfile;
|
||||||
|
nagiosfile.open (m_NagiosStatusFile);
|
||||||
|
switch ( m_status ) {
|
||||||
|
|
||||||
|
case RUNNING :
|
||||||
|
nagiosfile << "OK: Logged into the master succesfully" << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DISCONNECTED :
|
||||||
|
nagiosfile << "Critical: No connection to Master" << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WAITING_LOGIN :
|
||||||
|
nagiosfile << "Warning: Waiting to login into Master" << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WAITING_AUTHORISATION :
|
||||||
|
nagiosfile << "Warning: Waiting authorisation with Master" << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case WAITING_CONFIG :
|
||||||
|
nagiosfile << "Warning: Waiting something with config and Master" << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
nagiosfile << "Unknown: No idea of login status" << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
nagiosfile.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
#include "RingBuffer.h"
|
#include "RingBuffer.h"
|
||||||
#include "DMRData.h"
|
#include "DMRData.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
@ -33,7 +36,7 @@ public:
|
||||||
CDMRIPSC(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2);
|
CDMRIPSC(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2);
|
||||||
~CDMRIPSC();
|
~CDMRIPSC();
|
||||||
|
|
||||||
void setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, float latitude, float longitude, int height, const std::string& location, const std::string& description, const std::string& url);
|
void setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, float latitude, float longitude, int height, const std::string& location, const std::string& description, const std::string& url, const std::string& NagiosStatusFile);
|
||||||
|
|
||||||
bool open();
|
bool open();
|
||||||
|
|
||||||
|
@ -91,6 +94,7 @@ private:
|
||||||
std::string m_location;
|
std::string m_location;
|
||||||
std::string m_description;
|
std::string m_description;
|
||||||
std::string m_url;
|
std::string m_url;
|
||||||
|
std::string m_NagiosStatusFile;
|
||||||
|
|
||||||
bool m_beacon;
|
bool m_beacon;
|
||||||
|
|
||||||
|
@ -99,6 +103,8 @@ private:
|
||||||
bool writeConfig();
|
bool writeConfig();
|
||||||
bool writePing();
|
bool writePing();
|
||||||
|
|
||||||
|
bool writeNagiosOutput();
|
||||||
|
|
||||||
bool write(const unsigned char* data, unsigned int length);
|
bool write(const unsigned char* data, unsigned int length);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ Timeout=180
|
||||||
Duplex=1
|
Duplex=1
|
||||||
ModeHang=10
|
ModeHang=10
|
||||||
Display=None
|
Display=None
|
||||||
|
NagiosStatusFile=/dev/shm/MMDVM/Master.info
|
||||||
|
|
||||||
[Info]
|
[Info]
|
||||||
RXFrequency=435000000
|
RXFrequency=435000000
|
||||||
|
|
|
@ -400,6 +400,15 @@ int CMMDVMHost::run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *** NOT WORKING YET on CTRL-C on Linux ***
|
||||||
|
|
||||||
|
// Write status to Nagios file that MMDVMHost is not running any more
|
||||||
|
std::ofstream nagiosfile;
|
||||||
|
nagiosfile.open (m_conf.getNagiosStatusFile());
|
||||||
|
nagiosfile << "Unknown: MMDVM not running" << std::endl;
|
||||||
|
nagiosfile.close();
|
||||||
|
|
||||||
|
|
||||||
LogMessage("MMDVMHost is exiting on receipt of SIGHUP1");
|
LogMessage("MMDVMHost is exiting on receipt of SIGHUP1");
|
||||||
|
|
||||||
setMode(MODE_IDLE);
|
setMode(MODE_IDLE);
|
||||||
|
|
Loading…
Reference in a new issue