From e0bfe0a5d093ed30472d69cd7170ca97952d4f63 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 10 May 2017 14:31:34 +0200 Subject: [PATCH] Remove deprecated "DbCat1 | DbCat2" notation for DB IDO categories This allows for a specific config validation function. --- doc/9-object-types.md | 13 ------------- lib/db_ido/dbconnection.cpp | 23 ++++++++++++++--------- lib/db_ido/dbconnection.hpp | 1 + lib/db_ido/dbconnection.ti | 4 +--- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/doc/9-object-types.md b/doc/9-object-types.md index 0629ea6f6..0dda7f9c1 100644 --- a/doc/9-object-types.md +++ b/doc/9-object-types.md @@ -779,12 +779,6 @@ by Icinga Web 2 in the table above. In addition to the category flags listed above the `DbCatEverything` flag may be used as a shortcut for listing all flags. -> **Note** -> -> The previous way of defining the `categories` attribute e.g. -> `DbCatProgramStatus | DbCatState` was deprecated in 2.5 and will -> be removed in future versions. - ## IdoPgSqlConnection IDO database adapter for PostgreSQL. @@ -868,13 +862,6 @@ by Icinga Web 2 in the table above. In addition to the category flags listed above the `DbCatEverything` flag may be used as a shortcut for listing all flags. -> **Note** -> -> The previous way of defining the `categories` attribute e.g. -> `DbCatProgramStatus | DbCatState` was deprecated in 2.5 and will -> be removed in future versions. - - ## InfluxdbWriter Writes check result metrics and performance data to a defined InfluxDB host. diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index e27e18cb1..63ed62c6f 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -48,15 +48,7 @@ void DbConnection::OnConfigLoaded(void) Value categories = GetCategories(); - //TODO: Remove 'cat1 | cat2' notation in 2.6 - if (categories.IsNumber()) { - SetCategoryFilter(categories); - Log(LogWarning, "DbConnection") - << "Specifying flags using '|' for 'categories' for object '" << GetName() - << "' of type '" << GetReflectionType()->GetName() << "'" - << " is deprecated. This functionality will be removed in 2.6.0. Please use an array."; - } else - SetCategoryFilter(FilterArrayToInt(categories, DbQuery::GetCategoryFilterMap(), DbCatEverything)); + SetCategoryFilter(FilterArrayToInt(categories, DbQuery::GetCategoryFilterMap(), DbCatEverything)); if (!GetEnableHa()) { Log(LogDebug, "DbConnection") @@ -498,6 +490,19 @@ void DbConnection::ValidateFailoverTimeout(double value, const ValidationUtils& BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("failover_timeout"), "Failover timeout minimum is 60s.")); } +void DbConnection::ValidateCategories(const Array::Ptr& value, const ValidationUtils& utils) +{ + ObjectImpl::ValidateCategories(value, utils); + + int filter = FilterArrayToInt(value, DbQuery::GetCategoryFilterMap(), 0); + + if (filter == -1 || (filter & ~(DbCatInvalid | DbCatEverything | DbCatConfig | DbCatState | + DbCatAcknowledgement | DbCatComment | DbCatDowntime | DbCatEventHandler | DbCatExternalCommand | + DbCatFlapping | DbCatLog | DbCatNotification | DbCatProgramStatus | DbCatRetention | + DbCatStateHistory)) != 0) + BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("categories"), "categories filter is invalid.")); +} + void DbConnection::IncreaseQueryCount(void) { double now = Utility::GetTime(); diff --git a/lib/db_ido/dbconnection.hpp b/lib/db_ido/dbconnection.hpp index 08933b5d7..b87ada851 100644 --- a/lib/db_ido/dbconnection.hpp +++ b/lib/db_ido/dbconnection.hpp @@ -77,6 +77,7 @@ public: virtual int GetPendingQueryCount(void) const = 0; virtual void ValidateFailoverTimeout(double value, const ValidationUtils& utils) override; + virtual void ValidateCategories(const Array::Ptr& value, const ValidationUtils& utils) override; protected: virtual void OnConfigLoaded(void) override; diff --git a/lib/db_ido/dbconnection.ti b/lib/db_ido/dbconnection.ti index 77d50f6e5..cf922bd79 100644 --- a/lib/db_ido/dbconnection.ti +++ b/lib/db_ido/dbconnection.ti @@ -35,7 +35,7 @@ abstract class DbConnection : ConfigObject default {{{ return new Dictionary(); }}} }; - [config] Value categories { + [config] Array::Ptr categories { default {{{ Array::Ptr cat = new Array(); cat->Add("DbCatConfig"); @@ -90,10 +90,8 @@ validator DbConnection { Number systemcommands_age; }; - Number categories; Array categories { String "*"; - Number "*"; }; };