From a9921e47b22aefc2a15a9d69601699901c648a47 Mon Sep 17 00:00:00 2001 From: probonopd Date: Sun, 17 Nov 2024 11:23:31 +0000 Subject: [PATCH] Add logging over the network to a syslog server This has been tested successfully. FIXME: Don't hardcode IP address, use m_INetworkSyslogServerIPAddress instead Thanks @rsta https://github.com/rsta2/circle/tree/master/sample/33-syslog --- src/config.cpp | 6 ++++++ src/config.h | 2 ++ src/minidexed.cpp | 14 ++++++++++++++ src/minidexed.ini | 1 + 4 files changed, 23 insertions(+) diff --git a/src/config.cpp b/src/config.cpp index 10a4355..40ad095 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -209,6 +209,7 @@ void CConfig::Load (void) m_INetworkSubnetMask = m_Properties.GetIPAddress("NetworkSubnetMask") != 0; m_INetworkDefaultGateway = m_Properties.GetIPAddress("NetworkDefaultGateway") != 0; m_INetworkDNSServer = m_Properties.GetIPAddress("NetworkDNSServer") != 0; + m_INetworkSyslogServerIPAddress = m_Properties.GetIPAddress("NetworkSyslogServerIPAddress") != 0; } unsigned CConfig::GetToneGenerators (void) const @@ -767,3 +768,8 @@ CIPAddress CConfig::GetNetworkDNSServer (void) const { return m_INetworkDNSServer; } + +CIPAddress CConfig::GetNetworkSyslogServerIPAddress (void) const +{ + return m_INetworkSyslogServerIPAddress; +} diff --git a/src/config.h b/src/config.h index b87a94c..7af0bfc 100644 --- a/src/config.h +++ b/src/config.h @@ -248,6 +248,7 @@ public: CIPAddress GetNetworkSubnetMask (void) const; CIPAddress GetNetworkDefaultGateway (void) const; CIPAddress GetNetworkDNSServer (void) const; + CIPAddress GetNetworkSyslogServerIPAddress (void) const; private: CPropertiesFatFsFile m_Properties; @@ -372,6 +373,7 @@ private: CIPAddress m_INetworkSubnetMask; CIPAddress m_INetworkDefaultGateway; CIPAddress m_INetworkDNSServer; + CIPAddress m_INetworkSyslogServerIPAddress; }; #endif diff --git a/src/minidexed.cpp b/src/minidexed.cpp index f4b30a6..f61c835 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include #include @@ -2326,6 +2328,18 @@ bool CMiniDexed::InitNetwork() } m_pNetDevice = CNetDevice::GetNetDevice(NetDeviceType); + + // Syslog configuration + static const u8 SysLogServer[] = {192, 168, 0, 143}; // FIXME: Don't hardcode this, use m_INetworkSyslogServerIPAddress instead + static const u16 usServerPort = 8514; // standard port is 514 + CIPAddress ServerIP (SysLogServer); + CString IPString; + ServerIP.Format (&IPString); + LOGNOTE ( "Sending log messages to %s:%u", + (const char *) IPString, (unsigned) usServerPort); + + new CSysLogDaemon (m_pNet, ServerIP, usServerPort); + } return m_pNet != nullptr; } diff --git a/src/minidexed.ini b/src/minidexed.ini index 644ef4a..ac24026 100644 --- a/src/minidexed.ini +++ b/src/minidexed.ini @@ -153,6 +153,7 @@ NetworkIPAddress=0 NetworkSubnetMask=0 NetworkDefaultGateway=0 NetworkDNSServer=0 +NetworkSyslogServerIPAddress=0 # Performance PerformanceSelectToLoad=1