Skip to content

Commit

Permalink
Livestatus: Add log table.
Browse files Browse the repository at this point in the history
refs #4433
  • Loading branch information
Michael Friedrich committed Oct 30, 2013
1 parent cf55fe9 commit b190326
Show file tree
Hide file tree
Showing 18 changed files with 1,636 additions and 220 deletions.
8 changes: 4 additions & 4 deletions components/compat/compatlogger.cpp
Expand Up @@ -468,12 +468,12 @@ void CompatLogger::ReopenFile(bool rotate)
ObjectLock olock(hc);

std::ostringstream msgbuf;
msgbuf << "HOST STATE: CURRENT;"
msgbuf << "CURRENT HOST STATE: "
<< host->GetName() << ";"
<< Host::StateToString(Host::CalculateState(hc->GetState(), reachable)) << ";"
<< Service::StateTypeToString(hc->GetStateType()) << ";"
<< hc->GetCheckAttempt() << ";"
<< "";
<< hc->GetLastCheckOutput() << "";

WriteLine(msgbuf.str());
}
Expand All @@ -485,13 +485,13 @@ void CompatLogger::ReopenFile(bool rotate)
continue;

std::ostringstream msgbuf;
msgbuf << "SERVICE STATE: CURRENT;"
msgbuf << "CURRENT SERVICE STATE: "
<< host->GetName() << ";"
<< service->GetShortName() << ";"
<< Service::StateToString(service->GetState()) << ";"
<< Service::StateTypeToString(service->GetStateType()) << ";"
<< service->GetCheckAttempt() << ";"
<< "";
<< service->GetLastCheckOutput() << "";

WriteLine(msgbuf.str());
}
Expand Down
6 changes: 6 additions & 0 deletions components/livestatus/commandstable.cpp
Expand Up @@ -65,6 +65,9 @@ Value CommandsTable::NameAccessor(const Value& row)
{
String buf;
Command::Ptr command = static_cast<Command::Ptr>(row);

if (!command)
return Empty;

if (command->GetType() == DynamicType::GetByName("CheckCommand"))
buf += "check_";
Expand All @@ -82,6 +85,9 @@ Value CommandsTable::LineAccessor(const Value& row)
{
String buf;
Command::Ptr command = static_cast<Command::Ptr>(row);

if (!command)
return Empty;

Value commandLine = command->GetCommandLine();

Expand Down
21 changes: 18 additions & 3 deletions components/livestatus/contactgroupstable.cpp
Expand Up @@ -52,19 +52,34 @@ void ContactGroupsTable::FetchRows(const AddRowFunction& addRowFn)

Value ContactGroupsTable::NameAccessor(const Value& row)
{
return static_cast<UserGroup::Ptr>(row)->GetName();
UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);

if(!user_group)
return Empty;

return user_group->GetName();
}

Value ContactGroupsTable::AliasAccessor(const Value& row)
{
return static_cast<UserGroup::Ptr>(row)->GetName();
UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);

if(!user_group)
return Empty;

return user_group->GetName();
}

Value ContactGroupsTable::MembersAccessor(const Value& row)
{
UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);

if(!user_group)
return Empty;

Array::Ptr members = boost::make_shared<Array>();

BOOST_FOREACH(const User::Ptr& user, static_cast<UserGroup::Ptr>(row)->GetMembers()) {
BOOST_FOREACH(const User::Ptr& user, user_group->GetMembers()) {
members->Add(user->GetName());
}

Expand Down
101 changes: 88 additions & 13 deletions components/livestatus/contactstable.cpp
Expand Up @@ -70,17 +70,32 @@ void ContactsTable::FetchRows(const AddRowFunction& addRowFn)

Value ContactsTable::NameAccessor(const Value& row)
{
return static_cast<User::Ptr>(row)->GetName();
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

return user->GetName();
}

Value ContactsTable::AliasAccessor(const Value& row)
{
return static_cast<User::Ptr>(row)->GetDisplayName();
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

return user->GetDisplayName();
}

Value ContactsTable::EmailAccessor(const Value& row)
{
Dictionary::Ptr macros = static_cast<User::Ptr>(row)->GetMacros();
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

Dictionary::Ptr macros = user->GetMacros();

if (!macros)
return Empty;
Expand All @@ -90,7 +105,12 @@ Value ContactsTable::EmailAccessor(const Value& row)

Value ContactsTable::PagerAccessor(const Value& row)
{
Dictionary::Ptr macros = static_cast<User::Ptr>(row)->GetMacros();
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

Dictionary::Ptr macros = user->GetMacros();

if (!macros)
return Empty;
Expand All @@ -100,8 +120,13 @@ Value ContactsTable::PagerAccessor(const Value& row)

Value ContactsTable::HostNotificationPeriodAccessor(const Value& row)
{
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

/* same as service */
TimePeriod::Ptr timeperiod = static_cast<User::Ptr>(row)->GetNotificationPeriod();
TimePeriod::Ptr timeperiod = user->GetNotificationPeriod();

if (!timeperiod)
return Empty;
Expand All @@ -111,7 +136,12 @@ Value ContactsTable::HostNotificationPeriodAccessor(const Value& row)

Value ContactsTable::ServiceNotificationPeriodAccessor(const Value& row)
{
TimePeriod::Ptr timeperiod = static_cast<User::Ptr>(row)->GetNotificationPeriod();
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

TimePeriod::Ptr timeperiod = user->GetNotificationPeriod();

if (!timeperiod)
return Empty;
Expand All @@ -121,17 +151,32 @@ Value ContactsTable::ServiceNotificationPeriodAccessor(const Value& row)

Value ContactsTable::HostNotificationsEnabledAccessor(const Value& row)
{
return (static_cast<User::Ptr>(row)->GetEnableNotifications() ? 1 : 0);
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

return (user->GetEnableNotifications() ? 1 : 0);
}

Value ContactsTable::ServiceNotificationsEnabledAccessor(const Value& row)
{
return (static_cast<User::Ptr>(row)->GetEnableNotifications() ? 1 : 0);
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

return (user->GetEnableNotifications() ? 1 : 0);
}

Value ContactsTable::InHostNotificationPeriodAccessor(const Value& row)
{
TimePeriod::Ptr timeperiod = static_cast<User::Ptr>(row)->GetNotificationPeriod();
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

TimePeriod::Ptr timeperiod = user->GetNotificationPeriod();

if (!timeperiod)
return Empty;
Expand All @@ -141,7 +186,12 @@ Value ContactsTable::InHostNotificationPeriodAccessor(const Value& row)

Value ContactsTable::InServiceNotificationPeriodAccessor(const Value& row)
{
TimePeriod::Ptr timeperiod = static_cast<User::Ptr>(row)->GetNotificationPeriod();
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

TimePeriod::Ptr timeperiod = user->GetNotificationPeriod();

if (!timeperiod)
return Empty;
Expand All @@ -151,7 +201,12 @@ Value ContactsTable::InServiceNotificationPeriodAccessor(const Value& row)

Value ContactsTable::CustomVariableNamesAccessor(const Value& row)
{
Dictionary::Ptr custom = static_cast<User::Ptr>(row)->GetCustom();
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

Dictionary::Ptr custom = user->GetCustom();

if (!custom)
return Empty;
Expand Down Expand Up @@ -179,7 +234,12 @@ Value ContactsTable::CustomVariableNamesAccessor(const Value& row)

Value ContactsTable::CustomVariableValuesAccessor(const Value& row)
{
Dictionary::Ptr custom = static_cast<User::Ptr>(row)->GetCustom();
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

Dictionary::Ptr custom = user->GetCustom();

if (!custom)
return Empty;
Expand Down Expand Up @@ -207,7 +267,12 @@ Value ContactsTable::CustomVariableValuesAccessor(const Value& row)

Value ContactsTable::CustomVariablesAccessor(const Value& row)
{
Dictionary::Ptr custom = static_cast<User::Ptr>(row)->GetCustom();
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

Dictionary::Ptr custom = user->GetCustom();

if (!custom)
return Empty;
Expand Down Expand Up @@ -238,12 +303,22 @@ Value ContactsTable::CustomVariablesAccessor(const Value& row)

Value ContactsTable::ModifiedAttributesAccessor(const Value& row)
{
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

/* not supported */
return Empty;
}

Value ContactsTable::ModifiedAttributesListAccessor(const Value& row)
{
User::Ptr user = static_cast<User::Ptr>(row);

if (!user)
return Empty;

/* not supported */
return Empty;
}

0 comments on commit b190326

Please sign in to comment.