Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DB IDO: Add endpoints/endpointstatus tables.
Refs #5636
- Loading branch information
Michael Friedrich
committed
Mar 20, 2014
1 parent
bf9c89f
commit b9b3859
Showing
7 changed files
with
159 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/****************************************************************************** | ||
* Icinga 2 * | ||
* Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) * | ||
* * | ||
* This program is free software; you can redistribute it and/or * | ||
* modify it under the terms of the GNU General Public License * | ||
* as published by the Free Software Foundation; either version 2 * | ||
* of the License, or (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program; if not, write to the Free Software Foundation * | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * | ||
******************************************************************************/ | ||
|
||
#include "db_ido/endpointdbobject.h" | ||
#include "db_ido/dbtype.h" | ||
#include "db_ido/dbvalue.h" | ||
#include "icinga/icingaapplication.h" | ||
#include "base/objectlock.h" | ||
#include "base/initialize.h" | ||
#include "base/dynamictype.h" | ||
#include "base/utility.h" | ||
#include "base/logger_fwd.h" | ||
#include <boost/foreach.hpp> | ||
|
||
using namespace icinga; | ||
|
||
|
||
REGISTER_DBTYPE(Endpoint, "endpoint", DbObjectTypeEndpoint, "endpoint_object_id", EndpointDbObject); | ||
|
||
INITIALIZE_ONCE(&EndpointDbObject::StaticInitialize); | ||
|
||
void EndpointDbObject::StaticInitialize(void) | ||
{ | ||
Endpoint::OnConnected.connect(boost::bind(&EndpointDbObject::UpdateConnectedStatus, _1)); | ||
Endpoint::OnDisconnected.connect(boost::bind(&EndpointDbObject::UpdateConnectedStatus, _1)); | ||
} | ||
|
||
EndpointDbObject::EndpointDbObject(const DbType::Ptr& type, const String& name1, const String& name2) | ||
: DbObject(type, name1, name2) | ||
{ } | ||
|
||
Dictionary::Ptr EndpointDbObject::GetConfigFields(void) const | ||
{ | ||
Dictionary::Ptr fields = make_shared<Dictionary>(); | ||
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(GetObject()); | ||
|
||
fields->Set("identity", endpoint->GetName()); | ||
fields->Set("node", IcingaApplication::GetInstance()->GetNodeName()); | ||
|
||
return fields; | ||
} | ||
|
||
Dictionary::Ptr EndpointDbObject::GetStatusFields(void) const | ||
{ | ||
Dictionary::Ptr fields = make_shared<Dictionary>(); | ||
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(GetObject()); | ||
|
||
fields->Set("identity", endpoint->GetName()); | ||
fields->Set("node", IcingaApplication::GetInstance()->GetNodeName()); | ||
fields->Set("is_connected", endpoint->IsConnected() ? 1 : 0); | ||
|
||
return fields; | ||
} | ||
|
||
void EndpointDbObject::UpdateConnectedStatus(const Endpoint::Ptr& endpoint) | ||
{ | ||
Log(LogDebug, "db_ido", "update is_connected for endpoint '" + endpoint->GetName() + "'"); | ||
|
||
DbQuery query1; | ||
query1.Table = "endpointstatus"; | ||
query1.Type = DbQueryUpdate; | ||
|
||
Dictionary::Ptr fields1 = make_shared<Dictionary>(); | ||
fields1->Set("is_connected", endpoint->IsConnected() ? 1 : 0); | ||
fields1->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime())); | ||
query1.Fields = fields1; | ||
|
||
query1.WhereCriteria = make_shared<Dictionary>(); | ||
query1.WhereCriteria->Set("endpoint_object_id", endpoint); | ||
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ | ||
|
||
OnQuery(query1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/****************************************************************************** | ||
* Icinga 2 * | ||
* Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) * | ||
* * | ||
* This program is free software; you can redistribute it and/or * | ||
* modify it under the terms of the GNU General Public License * | ||
* as published by the Free Software Foundation; either version 2 * | ||
* of the License, or (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program; if not, write to the Free Software Foundation * | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * | ||
******************************************************************************/ | ||
|
||
#ifndef ENDPOINTDBOBJECT_H | ||
#define ENDPOINTDBOBJECT_H | ||
|
||
#include "db_ido/dbobject.h" | ||
#include "base/dynamicobject.h" | ||
#include "cluster/endpoint.h" | ||
|
||
namespace icinga | ||
{ | ||
|
||
/** | ||
* A Command database object. | ||
* | ||
* @ingroup ido | ||
*/ | ||
class EndpointDbObject : public DbObject | ||
{ | ||
public: | ||
DECLARE_PTR_TYPEDEFS(EndpointDbObject); | ||
|
||
EndpointDbObject(const shared_ptr<DbType>& type, const String& name1, const String& name2); | ||
|
||
static void StaticInitialize(void); | ||
|
||
virtual Dictionary::Ptr GetConfigFields(void) const; | ||
virtual Dictionary::Ptr GetStatusFields(void) const; | ||
|
||
private: | ||
static void UpdateConnectedStatus(const Endpoint::Ptr& endpoint); | ||
}; | ||
|
||
} | ||
|
||
#endif /* ENDPOINTDBOBJECT_H */ |