diff options
author | Arne Juul <arnej@yahooinc.com> | 2023-04-26 10:24:29 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2023-04-26 10:24:29 +0000 |
commit | 3cfbb21fd89ebcb9309b21637b3604691d3c8a79 (patch) | |
tree | a9bc026128dc4793d450e4028eb56833b6b4f596 /logforwarder | |
parent | 9a4376dae10e986c7061633e5a02f18c24a951da (diff) |
write "outputs.conf" if role is configured
Diffstat (limited to 'logforwarder')
3 files changed, 44 insertions, 3 deletions
diff --git a/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp b/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp index 5d17357e74e..849c8311bd0 100644 --- a/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp +++ b/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp @@ -31,11 +31,19 @@ bool isExecutable(const char *path) { } return ((statbuf.st_mode & S_IXOTH) != 0); } + +time_t lastModTime(const vespalib::string &fn) { + if (fn.empty()) return 0; + struct stat info; + if (stat(fn.c_str(), &info) != 0) return 0; + return info.st_mtime; } +} // namespace + void CfHandler::doConfigure() { - std::unique_ptr<LogforwarderConfig> cfg(_handle->getConfig()); - const LogforwarderConfig& config(*cfg); + _lastConfig = _handle->getConfig(); + const LogforwarderConfig& config(*_lastConfig); LOG(debug, "validating splunk home '%s'", config.splunkHome.c_str()); auto program = config.splunkHome + "/bin/splunk"; if (isExecutable(program.c_str())) { @@ -45,10 +53,27 @@ void CfHandler::doConfigure() { } } +vespalib::string CfHandler::clientCertFile() const { + static const vespalib::string certDir = "/var/lib/sia/certs/"; + if (_lastConfig && !_lastConfig->role.empty()) { + return certDir + _lastConfig->role + ".pem"; + } + return ""; +} + +bool CfHandler::certFileChanged() { + time_t modTime = lastModTime(clientCertFile()); + if (modTime != _lastCertFileChange) { + _lastCertFileChange = modTime; + return true; + } + return false; +} + void CfHandler::check() { - if (_subscriber.nextConfigNow()) { + if (_subscriber.nextConfigNow() || certFileChanged()) { doConfigure(); } } diff --git a/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.h b/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.h index c66be0e2099..ceaa0db1011 100644 --- a/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.h +++ b/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.h @@ -10,11 +10,15 @@ class CfHandler { private: config::ConfigSubscriber _subscriber; config::ConfigHandle<LogforwarderConfig>::UP _handle; + std::unique_ptr<LogforwarderConfig> _lastConfig; + time_t _lastCertFileChange = 0; void subscribe(const std::string & configId, std::chrono::milliseconds timeout); void doConfigure(); + bool certFileChanged(); public: CfHandler(); virtual ~CfHandler(); + vespalib::string clientCertFile() const; void start(const char *configId); void check(); diff --git a/logforwarder/src/apps/vespa-logforwarder-start/splunk-starter.cpp b/logforwarder/src/apps/vespa-logforwarder-start/splunk-starter.cpp index 905f4640c92..9c09a426ea7 100644 --- a/logforwarder/src/apps/vespa-logforwarder-start/splunk-starter.cpp +++ b/logforwarder/src/apps/vespa-logforwarder-start/splunk-starter.cpp @@ -81,6 +81,18 @@ void SplunkStarter::gotConfig(const LogforwarderConfig& config) { rename(tmpPath.c_str(), path.c_str()); } } + vespalib::string clientCert = clientCertFile(); + if (! clientCert.empty()) { + path = cfFilePath(config.splunkHome, "outputs.conf"); + tmpPath = path + ".new"; + fp = fopen(tmpPath.c_str(), "w"); + if (fp != NULL) { + fprintf(fp, "[tcpout]\n"); + fprintf(fp, "clientCert = %s\n", clientCert.c_str()); + fclose(fp); + rename(tmpPath.c_str(), path.c_str()); + } + } if (config.clientName.size() == 0 || config.deploymentServer.size() == 0) { |