diff --git a/Conf.cpp b/Conf.cpp index 66d714c..42327a1 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -51,6 +51,7 @@ m_timeout(120U), m_duplex(true), m_modeHang(10U), m_display(), +m_NagiosStatusFile(), m_rxFrequency(0U), m_txFrequency(0U), m_power(0U), @@ -173,9 +174,12 @@ bool CConf::read() char* value = ::strtok(NULL, "\r\n"); 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; - else if (::strcmp(key, "Timeout") == 0) + } else if (::strcmp(key, "Timeout") == 0) m_timeout = (unsigned int)::atoi(value); else if (::strcmp(key, "Duplex") == 0) m_duplex = ::atoi(value) == 1; @@ -183,6 +187,8 @@ bool CConf::read() m_modeHang = (unsigned int)::atoi(value); else if (::strcmp(key, "Display") == 0) m_display = value; + else if (::strcmp(key, "NagiosStatusFile") == 0) + m_NagiosStatusFile = value; } else if (section == SECTION_INFO) { if (::strcmp(key, "TXFrequency") == 0) m_txFrequency = (unsigned int)::atoi(value); @@ -235,15 +241,18 @@ bool CConf::read() } else if (section == SECTION_DSTAR) { if (::strcmp(key, "Enable") == 0) 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; - else if (::strcmp(key, "SelfOnly") == 0) + } else if (::strcmp(key, "SelfOnly") == 0) m_dstarSelfOnly = ::atoi(value) == 1; else if (::strcmp(key, "BlackList") == 0) { char* p = ::strtok(value, ",\r\n"); while (p != NULL) { 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]); std::string callsign = std::string(p); callsign.resize(DSTAR_LONG_CALLSIGN_LENGTH, ' '); @@ -379,6 +388,12 @@ std::string CConf::getDisplay() const return m_display; } +std::string CConf::getNagiosStatusFile() const +{ + return m_NagiosStatusFile; +} + + unsigned int CConf::getRxFrequency() const { return m_rxFrequency; diff --git a/Conf.h b/Conf.h index d797583..2a69b24 100644 --- a/Conf.h +++ b/Conf.h @@ -36,6 +36,7 @@ public: bool getDuplex() const; unsigned int getModeHang() const; std::string getDisplay() const; + std::string getNagiosStatusFile() const; // The Info section unsigned int getRxFrequency() const; @@ -129,6 +130,7 @@ private: bool m_duplex; unsigned int m_modeHang; std::string m_display; + std::string m_NagiosStatusFile; unsigned int m_rxFrequency; unsigned int m_txFrequency; diff --git a/DMRIPSC.cpp b/DMRIPSC.cpp index 4cf7178..b8f8ef9 100644 --- a/DMRIPSC.cpp +++ b/DMRIPSC.cpp @@ -62,6 +62,7 @@ m_height(0), m_location(), m_description(), m_url(), +m_NagiosStatusFile(), m_beacon(false) { assert(!address.empty()); @@ -96,7 +97,7 @@ CDMRIPSC::~CDMRIPSC() 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_rxFrequency = rxFrequency; @@ -109,6 +110,7 @@ void CDMRIPSC::setConfig(const std::string& callsign, unsigned int rxFrequency, m_location = location; m_description = description; m_url = url; + m_NagiosStatusFile = NagiosStatusFile; } bool CDMRIPSC::open() @@ -396,6 +398,7 @@ void CDMRIPSC::clock(unsigned int ms) m_timeoutTimer.stop(); m_retryTimer.stop(); } + writeNagiosOutput(); } 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); } + + +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; +} + diff --git a/DMRIPSC.h b/DMRIPSC.h index 069febe..aa0d58c 100644 --- a/DMRIPSC.h +++ b/DMRIPSC.h @@ -24,6 +24,9 @@ #include "RingBuffer.h" #include "DMRData.h" +#include +#include + #include #include @@ -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(); - 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(); @@ -91,6 +94,7 @@ private: std::string m_location; std::string m_description; std::string m_url; + std::string m_NagiosStatusFile; bool m_beacon; @@ -99,6 +103,8 @@ private: bool writeConfig(); bool writePing(); + bool writeNagiosOutput(); + bool write(const unsigned char* data, unsigned int length); }; diff --git a/MMDVM.ini b/MMDVM.ini index a4486fa..fd0451f 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -4,6 +4,7 @@ Timeout=180 Duplex=1 ModeHang=10 Display=None +NagiosStatusFile=/dev/shm/MMDVM/Master.info [Info] RXFrequency=435000000 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 3df2979..4c7f556 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -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"); setMode(MODE_IDLE);