Change DB IDO 'categories' attribute to Array notation

Example:
    categories = [ "DbCatProgramStatus", "DbCatState" ]

The old method with constants and OR is still supported but deprecated.

refs #11445
fixes #12024
This commit is contained in:
Michael Friedrich 2016-06-22 16:11:15 +02:00
parent 14fdb794e2
commit 091274e417
7 changed files with 97 additions and 31 deletions

View File

@ -722,7 +722,7 @@ Configuration Attributes:
enable_ha |**Optional.** Enable the high availability functionality. Only valid in a [cluster setup](13-distributed-monitoring-ha.md#high-availability-db-ido). Defaults to "true".
failover_timeout | **Optional.** Set the failover timeout in a [HA cluster](13-distributed-monitoring-ha.md#high-availability-db-ido). Must not be lower than 60s. Defaults to "60s".
cleanup |**Optional.** Dictionary with items for historical table cleanup.
categories |**Optional.** The types of information that should be written to the database.
categories |**Optional.** Array of information types that should be written to the database.
Cleanup Items:
@ -763,9 +763,14 @@ Data Categories:
DbCatRetention | Retention data | Icinga Web 2
DbCatStateHistory | Historical state data | Icinga Web 2
Multiple categories can be combined using the `|` operator. In addition to
the category flags listed above the `DbCatEverything` flag may be used as
a shortcut for listing all flags.
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.
External interfaces like Icinga Web 2 require everything except `DbCatCheck`
which is the default value if `categories` is not set.
@ -806,7 +811,7 @@ Configuration Attributes:
enable_ha |**Optional.** Enable the high availability functionality. Only valid in a [cluster setup](13-distributed-monitoring-ha.md#high-availability-db-ido). Defaults to "true".
failover_timeout | **Optional.** Set the failover timeout in a [HA cluster](13-distributed-monitoring-ha.md#high-availability-db-ido). Must not be lower than 60s. Defaults to "60s".
cleanup |**Optional.** Dictionary with items for historical table cleanup.
categories |**Optional.** The types of information that should be written to the database.
categories |**Optional.** Array of information types that should be written to the database.
Cleanup Items:
@ -847,9 +852,14 @@ Data Categories:
DbCatRetention | Retention data | Icinga Web 2
DbCatStateHistory | Historical state data | Icinga Web 2
Multiple categories can be combined using the `|` operator. In addition to
the category flags listed above the `DbCatEverything` flag may be used as
a shortcut for listing all flags.
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.
External interfaces like Icinga Web 2 require everything except `DbCatCheck`
which is the default value if `categories` is not set.

View File

@ -46,6 +46,14 @@ void DbConnection::OnConfigLoaded(void)
{
ConfigObject::OnConfigLoaded();
Value categories = GetCategories();
//TODO: Remove 'cat1 | cat2' notation in 2.6
if (categories.IsNumber())
SetCategoryFilter(categories);
else
SetCategoryFilter(FilterArrayToInt(categories, DbQuery::GetCategoryFilterMap(), DbCatEverything));
if (!GetEnableHa()) {
Log(LogDebug, "DbConnection")
<< "HA functionality disabled. Won't pause IDO connection: " << GetName();

View File

@ -35,13 +35,27 @@ abstract class DbConnection : ConfigObject
default {{{ return new Dictionary(); }}}
};
[config] int categories {
[config] Value categories {
default {{{
return DbCatConfig | DbCatState | DbCatAcknowledgement |
DbCatComment | DbCatDowntime | DbCatEventHandler | DbCatExternalCommand | DbCatFlapping |
DbCatLog | DbCatNotification | DbCatProgramStatus | DbCatRetention | DbCatStateHistory;
Array::Ptr cat = new Array();
cat->Add("DbCatConfig");
cat->Add("DbCatState");
cat->Add("DbCatAcknowledgement");
cat->Add("DbCatComment");
cat->Add("DbCatDowntime");
cat->Add("DbCatEventHandler");
cat->Add("DbCatExternalCommand");
cat->Add("DbCatFlapping");
cat->Add("DbCatLog");
cat->Add("DbCatNotification");
cat->Add("DbCatProgramStatus");
cat->Add("DbCatRetention");
cat->Add("DbCatStateHistory");
return cat;
}}}
};
int categories_filter_real (CategoryFilter);
[config] bool enable_ha {
default {{{ return true; }}}
@ -77,6 +91,12 @@ validator DbConnection {
Number servicechecks_age;
Number systemcommands_age;
};
Number categories;
Array categories {
String "*";
Number "*";
};
};
}

View File

@ -25,6 +25,8 @@ using namespace icinga;
INITIALIZE_ONCE(&DbQuery::StaticInitialize);
std::map<String, int> DbQuery::m_CategoryFilterMap;
void DbQuery::StaticInitialize(void)
{
ScriptGlobal::Set("DbCatConfig", DbCatConfig);
@ -42,5 +44,26 @@ void DbQuery::StaticInitialize(void)
ScriptGlobal::Set("DbCatRetention", DbCatRetention);
ScriptGlobal::Set("DbCatStateHistory", DbCatStateHistory);
ScriptGlobal::Set("DbCatEverything", ~(unsigned int)0);
ScriptGlobal::Set("DbCatEverything", DbCatEverything);
m_CategoryFilterMap["DbCatConfig"] = DbCatConfig;
m_CategoryFilterMap["DbCatState"] = DbCatState;
m_CategoryFilterMap["DbCatAcknowledgement"] = DbCatAcknowledgement;
m_CategoryFilterMap["DbCatComment"] = DbCatComment;
m_CategoryFilterMap["DbCatDowntime"] = DbCatDowntime;
m_CategoryFilterMap["DbCatEventHandler"] = DbCatEventHandler;
m_CategoryFilterMap["DbCatExternalCommand"] = DbCatExternalCommand;
m_CategoryFilterMap["DbCatFlapping"] = DbCatFlapping;
m_CategoryFilterMap["DbCatCheck"] = DbCatCheck;
m_CategoryFilterMap["DbCatLog"] = DbCatLog;
m_CategoryFilterMap["DbCatNotification"] = DbCatNotification;
m_CategoryFilterMap["DbCatProgramStatus"] = DbCatProgramStatus;
m_CategoryFilterMap["DbCatRetention"] = DbCatRetention;
m_CategoryFilterMap["DbCatStateHistory"] = DbCatStateHistory;
m_CategoryFilterMap["DbCatEverything"] = DbCatEverything;
}
const std::map<String, int>& DbQuery::GetCategoryFilterMap(void)
{
return m_CategoryFilterMap;
}

View File

@ -39,23 +39,23 @@ enum DbQueryType
enum DbQueryCategory
{
DbCatInvalid = -1,
DbCatInvalid = 0, //-1 is required for DbCatEverything
DbCatEverything = ~0,
DbCatConfig = (1 << 0),
DbCatState = (1 << 1),
DbCatAcknowledgement = (1 << 2),
DbCatComment = (1 << 3),
DbCatDowntime = (1 << 4),
DbCatEventHandler = (1 << 5),
DbCatExternalCommand = (1 << 6),
DbCatFlapping = (1 << 7),
DbCatCheck = (1 << 8),
DbCatLog = (1 << 9),
DbCatNotification = (1 << 10),
DbCatProgramStatus = (1 << 11),
DbCatRetention = (1 << 12),
DbCatStateHistory = (1 << 13)
DbCatConfig = 1,
DbCatState = 2,
DbCatAcknowledgement = 4,
DbCatComment = 8,
DbCatDowntime = 16,
DbCatEventHandler = 32,
DbCatExternalCommand = 64,
DbCatFlapping = 128,
DbCatCheck = 256,
DbCatLog = 512,
DbCatNotification = 1024,
DbCatProgramStatus = 2048,
DbCatRetention = 4096,
DbCatStateHistory = 8192
};
class DbObject;
@ -79,6 +79,11 @@ struct I2_DB_IDO_API DbQuery
DbQuery(void)
: Type(0), Category(DbCatInvalid), ConfigUpdate(false), StatusUpdate(false), Priority(PriorityLow)
{ }
static const std::map<String, int>& GetCategoryFilterMap(void);
private:
static std::map<String, int> m_CategoryFilterMap;
};
}

View File

@ -872,7 +872,7 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query, DbQueryType
return;
}
if ((query.Category & GetCategories()) == 0)
if (GetCategoryFilter() != DbCatEverything && (query.Category & GetCategoryFilter()) == 0)
return;
if (query.Object && query.Object->GetObject()->GetExtension("agent_check").ToBool())

View File

@ -734,7 +734,7 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query, DbQueryType
return;
}
if ((query.Category & GetCategories()) == 0)
if (GetCategoryFilter() != DbCatEverything && (query.Category & GetCategoryFilter()) == 0)
return;
if (query.Object && query.Object->GetObject()->GetExtension("agent_check").ToBool())