mirror of https://github.com/Icinga/icinga2.git
Added missing files.
This commit is contained in:
parent
8d781bdc56
commit
4643444913
|
@ -198,7 +198,7 @@ void CompatComponent::DumpDowntimes(ofstream& fp, const DynamicObject::Ptr& owne
|
|||
<< "\t" << "is_in_effect=" << (DowntimeProcessor::IsDowntimeActive(downtime) ? 1 : 0) << "\n"
|
||||
<< "\t" << "author=" << static_cast<String>(downtime->Get("author")) << "\n"
|
||||
<< "\t" << "comment=" << static_cast<String>(downtime->Get("comment")) << "\n"
|
||||
<< "\t" << "trigger_time=" << 0 << "\n"
|
||||
<< "\t" << "trigger_time=" << static_cast<double>(downtime->Get("trigger_time")) << "\n"
|
||||
<< "\t" << "}" << "\n"
|
||||
<< "\n";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 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 "i2-icinga.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
int DowntimeProcessor::m_NextDowntimeID = 1;
|
||||
map<int, DynamicObject::WeakPtr> DowntimeProcessor::m_DowntimeCache;
|
||||
bool DowntimeProcessor::m_DowntimeCacheValid;
|
||||
|
||||
int DowntimeProcessor::GetNextDowntimeID(void)
|
||||
{
|
||||
return m_NextDowntimeID;
|
||||
}
|
||||
|
||||
int DowntimeProcessor::AddDowntime(const DynamicObject::Ptr& owner,
|
||||
const String& author, const String& comment,
|
||||
double startTime, double endTime,
|
||||
bool fixed, int triggeredBy, double duration)
|
||||
{
|
||||
Dictionary::Ptr downtime = boost::make_shared<Dictionary>();
|
||||
downtime->Set("entry_time", Utility::GetTime());
|
||||
downtime->Set("author", author);
|
||||
downtime->Set("comment", comment);
|
||||
downtime->Set("start_time", startTime);
|
||||
downtime->Set("end_time", endTime);
|
||||
downtime->Set("fixed", fixed);
|
||||
downtime->Set("duration", duration);
|
||||
downtime->Set("triggered_by", triggeredBy);
|
||||
downtime->Set("trigger_time", 0);
|
||||
|
||||
Dictionary::Ptr downtimes = owner->Get("downtimes");
|
||||
|
||||
if (!downtimes)
|
||||
downtimes = boost::make_shared<Dictionary>();
|
||||
|
||||
int id = m_NextDowntimeID;
|
||||
m_NextDowntimeID++;
|
||||
|
||||
downtimes->Set(Convert::ToString(id), downtime);
|
||||
owner->Set("downtimes", downtimes);
|
||||
}
|
||||
|
||||
void DowntimeProcessor::RemoveDowntime(int id)
|
||||
{
|
||||
DynamicObject::Ptr dto = GetOwnerByDowntimeID(id);
|
||||
|
||||
Dictionary::Ptr downtimes = dto->Get("downtimes");
|
||||
|
||||
if (downtimes) {
|
||||
downtimes->Remove(Convert::ToString(id));
|
||||
dto->Touch("downtimes");
|
||||
}
|
||||
}
|
||||
|
||||
DynamicObject::Ptr DowntimeProcessor::GetOwnerByDowntimeID(int id)
|
||||
{
|
||||
ValidateDowntimeCache();
|
||||
|
||||
DynamicObject::Ptr dto = m_DowntimeCache[id].lock();
|
||||
return dto;
|
||||
}
|
||||
|
||||
Dictionary::Ptr DowntimeProcessor::GetDowntimeByID(int id)
|
||||
{
|
||||
DynamicObject::Ptr dto = GetOwnerByDowntimeID(id);
|
||||
|
||||
Dictionary::Ptr downtimes = dto->Get("downtimes");
|
||||
|
||||
if (downtimes) {
|
||||
Dictionary::Ptr downtime = downtimes->Get(Convert::ToString(id));
|
||||
return downtime;
|
||||
}
|
||||
|
||||
return Dictionary::Ptr();
|
||||
}
|
||||
|
||||
bool DowntimeProcessor::IsDowntimeActive(const Dictionary::Ptr& downtime)
|
||||
{
|
||||
double now = Utility::GetTime();
|
||||
|
||||
if (now < static_cast<double>(downtime->Get("start_time")) ||
|
||||
now > static_cast<double>(downtime->Get("end_time")))
|
||||
return false;
|
||||
|
||||
if (static_cast<bool>(downtime->Get("fixed")))
|
||||
return true;
|
||||
|
||||
double triggerTime = static_cast<double>(downtime->Get("trigger_time"));
|
||||
|
||||
if (triggerTime == 0)
|
||||
return false;
|
||||
|
||||
return (triggerTime + static_cast<double>(downtime->Get("duration")) < now);
|
||||
}
|
||||
|
||||
void DowntimeProcessor::InvalidateDowntimeCache(void)
|
||||
{
|
||||
m_DowntimeCacheValid = false;
|
||||
m_DowntimeCache.clear();
|
||||
}
|
||||
|
||||
void DowntimeProcessor::AddDowntimesToCache(const DynamicObject::Ptr& owner)
|
||||
{
|
||||
Dictionary::Ptr downtimes = owner->Get("downtimes");
|
||||
|
||||
if (!downtimes)
|
||||
return;
|
||||
|
||||
String sid;
|
||||
BOOST_FOREACH(tie(sid, tuples::ignore), downtimes) {
|
||||
int id = Convert::ToLong(sid);
|
||||
|
||||
if (id > m_NextDowntimeID)
|
||||
m_NextDowntimeID = id;
|
||||
|
||||
m_DowntimeCache[id] = owner;
|
||||
}
|
||||
}
|
||||
|
||||
void DowntimeProcessor::ValidateDowntimeCache(void)
|
||||
{
|
||||
if (m_DowntimeCacheValid)
|
||||
return;
|
||||
|
||||
m_DowntimeCache.clear();
|
||||
|
||||
DynamicObject::Ptr object;
|
||||
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
|
||||
AddDowntimesToCache(object);
|
||||
}
|
||||
|
||||
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
|
||||
AddDowntimesToCache(object);
|
||||
}
|
||||
|
||||
m_DowntimeCacheValid = true;
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 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 DOWNTIMEPROCESSOR_H
|
||||
#define DOWNTIMEPROCESSOR_H
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
/**
|
||||
* Common Information Base class. Holds some statistics (and will likely be
|
||||
* removed/refactored).
|
||||
*
|
||||
* @ingroup icinga
|
||||
*/
|
||||
class I2_ICINGA_API DowntimeProcessor
|
||||
{
|
||||
public:
|
||||
static int GetNextDowntimeID(void);
|
||||
|
||||
static int AddDowntime(const DynamicObject::Ptr& owner,
|
||||
const String& author, const String& comment,
|
||||
double startTime, double endTime,
|
||||
bool fixed, int triggeredBy, double duration);
|
||||
|
||||
static void RemoveDowntime(int id);
|
||||
|
||||
static DynamicObject::Ptr GetOwnerByDowntimeID(int id);
|
||||
static Dictionary::Ptr GetDowntimeByID(int id);
|
||||
|
||||
static bool IsDowntimeActive(const Dictionary::Ptr& downtime);
|
||||
|
||||
static void InvalidateDowntimeCache(void);
|
||||
|
||||
private:
|
||||
static int m_NextDowntimeID;
|
||||
|
||||
static map<int, DynamicObject::WeakPtr> m_DowntimeCache;
|
||||
static bool m_DowntimeCacheValid;
|
||||
|
||||
DowntimeProcessor(void);
|
||||
|
||||
static void AddDowntimesToCache(const DynamicObject::Ptr& owner);
|
||||
static void ValidateDowntimeCache(void);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* DOWNTIMEPROCESSOR_H */
|
Loading…
Reference in New Issue