Merge pull request #10059 from Icinga/IcingaDB-TimestampToMilliseconds-limit

IcingaDB::TimestampToMilliseconds(): limit output to four year digits
This commit is contained in:
Julian Brost 2024-10-02 09:19:03 +02:00 committed by GitHub
commit 5e9e0bbcdf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 1 deletions

View File

@ -18,6 +18,7 @@
#include "icinga/eventcommand.hpp" #include "icinga/eventcommand.hpp"
#include "icinga/host.hpp" #include "icinga/host.hpp"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <cmath>
#include <map> #include <map>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -245,7 +246,18 @@ String IcingaDB::GetLowerCaseTypeNameDB(const ConfigObject::Ptr& obj)
} }
long long IcingaDB::TimestampToMilliseconds(double timestamp) { long long IcingaDB::TimestampToMilliseconds(double timestamp) {
return static_cast<long long>(timestamp * 1000); // In addition to the limits of the Icinga DB MySQL (0 - 2^64) and PostgreSQL (0 - 2^63) schemata,
// years not fitting in YYYY may cause problems, see e.g. https://github.com/golang/go/issues/4556.
// RFC 3339: "All dates and times are assumed to be (...) somewhere between 0000AD and 9999AD."
//
// The below upper limit includes a safety buffer to make sure the timestamp is within 9999AD in all time zones:
// $ date -ud @253402214400
// Fri Dec 31 00:00:00 UTC 9999
// $ TZ=Asia/Vladivostok date -d @253402214400
// Fri Dec 31 10:00:00 +10 9999
// $ TZ=America/Juneau date -d @253402214400
// Thu Dec 30 15:00:00 AKST 9999
return std::fmin(std::fmax(timestamp, 0.0), 253402214400.0) * 1000.0;
} }
String IcingaDB::IcingaToStreamValue(const Value& value) String IcingaDB::IcingaToStreamValue(const Value& value)