diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index c7d3df55d..80f730d24 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -18,13 +18,11 @@ ******************************************************************************/ #include "base/utility.h" +#include "base/convert.h" #include "base/application.h" #include "base/logger_fwd.h" #include "base/exception.h" #include -#include -#include -#include #include #include #include @@ -276,14 +274,33 @@ Utility::LoadExtensionLibrary(const String& library) } /** - * Generates a new UUID. + * Generates a new unique ID. * - * @returns The new UUID in text form. + * @returns The new unique ID. */ -String Utility::NewUUID(void) +String Utility::NewUniqueID(void) { - boost::uuids::uuid uuid = boost::uuids::random_generator()(); - return boost::lexical_cast(uuid); + static boost::mutex mutex; + static int next_id = 0; + + /* I'd much rather use UUIDs but RHEL is way too cool to have + * a semi-recent version of boost. Yay. */ + + String id; + + char buf[128]; + if (gethostname(buf, sizeof(buf)) == 0) + id = String(buf) + "-"; + + id += Convert::ToString((long)Utility::GetTime()) + "-"; + + { + boost::mutex::scoped_lock lock(mutex); + id += Convert::ToString(next_id); + next_id++; + } + + return id; } /** diff --git a/lib/base/utility.h b/lib/base/utility.h index f3112bc2f..7288f61fd 100644 --- a/lib/base/utility.h +++ b/lib/base/utility.h @@ -53,7 +53,7 @@ public: static void Sleep(double timeout); - static String NewUUID(void); + static String NewUniqueID(void); static bool Glob(const String& pathSpec, const boost::function& callback); diff --git a/lib/config/configcompilercontext.cpp b/lib/config/configcompilercontext.cpp index a41294313..0a346f3dd 100644 --- a/lib/config/configcompilercontext.cpp +++ b/lib/config/configcompilercontext.cpp @@ -29,7 +29,7 @@ using namespace icinga; ConfigCompilerContext *ConfigCompilerContext::m_Context = NULL; ConfigCompilerContext::ConfigCompilerContext(void) - : m_Unit(Utility::NewUUID()), m_Flags(0) + : m_Unit(Utility::NewUniqueID()), m_Flags(0) { } void ConfigCompilerContext::AddItem(const ConfigItem::Ptr& item) diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp index e41bcca47..23c80af6c 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -81,7 +81,7 @@ String Service::AddComment(CommentType entryType, const String& author, m_Comments = comments; } - String id = Utility::NewUUID(); + String id = Utility::NewUniqueID(); comments->Set(id, comment); Touch("comments"); diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp index eed8990b1..654e3f46f 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -96,7 +96,7 @@ String Service::AddDowntime(const String& author, const String& comment, m_Downtimes = downtimes; } - String id = Utility::NewUUID(); + String id = Utility::NewUniqueID(); downtimes->Set(id, downtime); Touch("downtimes");