2014-04-03 15:36:13 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2015-01-22 12:00:23 +01:00
|
|
|
* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
|
2014-04-03 15:36:13 +02:00
|
|
|
* *
|
|
|
|
* 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 CHECKABLE_H
|
|
|
|
#define CHECKABLE_H
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/i2-icinga.hpp"
|
|
|
|
#include "icinga/checkable.thpp"
|
|
|
|
#include "icinga/timeperiod.hpp"
|
|
|
|
#include "icinga/notification.hpp"
|
|
|
|
#include "icinga/comment.hpp"
|
|
|
|
#include "icinga/downtime.hpp"
|
2014-11-13 11:23:57 +01:00
|
|
|
#include "remote/endpoint.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "remote/messageorigin.hpp"
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The state of service flapping.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum FlappingState
|
|
|
|
{
|
|
|
|
FlappingStarted = 0,
|
|
|
|
FlappingDisabled = 1,
|
|
|
|
FlappingStopped = 2,
|
|
|
|
FlappingEnabled = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum DependencyType
|
|
|
|
{
|
|
|
|
DependencyState,
|
|
|
|
DependencyCheckExecution,
|
|
|
|
DependencyNotification
|
|
|
|
};
|
|
|
|
|
2014-04-17 11:29:47 +02:00
|
|
|
/**
|
|
|
|
* Checkable Types
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum CheckableType
|
|
|
|
{
|
|
|
|
CheckableHost,
|
|
|
|
CheckableService
|
|
|
|
};
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
class CheckCommand;
|
|
|
|
class EventCommand;
|
|
|
|
class Dependency;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An Icinga service.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
class I2_ICINGA_API Checkable : public ObjectImpl<Checkable>
|
|
|
|
{
|
|
|
|
public:
|
2014-11-03 00:44:04 +01:00
|
|
|
DECLARE_OBJECT(Checkable);
|
|
|
|
DECLARE_OBJECTNAME(Checkable);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
Checkable(void);
|
|
|
|
|
|
|
|
std::set<Checkable::Ptr> GetParents(void) const;
|
|
|
|
std::set<Checkable::Ptr> GetChildren(void) const;
|
|
|
|
|
2014-05-01 23:53:08 +02:00
|
|
|
void AddGroup(const String& name);
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
//bool IsHostCheck(void) const;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
bool IsReachable(DependencyType dt = DependencyState, intrusive_ptr<Dependency> *failedDependency = NULL, int rstack = 0) const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
AcknowledgementType GetAcknowledgement(void);
|
|
|
|
|
2015-02-07 21:39:19 +01:00
|
|
|
void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, double expiry = 0, const MessageOrigin& origin = MessageOrigin());
|
2014-05-03 20:02:22 +02:00
|
|
|
void ClearAcknowledgement(const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
/* Checks */
|
2014-11-08 21:17:16 +01:00
|
|
|
intrusive_ptr<CheckCommand> GetCheckCommand(void) const;
|
|
|
|
void SetCheckCommand(const intrusive_ptr<CheckCommand>& command, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
TimePeriod::Ptr GetCheckPeriod(void) const;
|
2014-08-26 13:25:15 +02:00
|
|
|
void SetCheckPeriod(const TimePeriod::Ptr& tp, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
double GetCheckInterval(void) const;
|
2014-08-26 12:02:55 +02:00
|
|
|
void SetCheckInterval(double interval, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
double GetRetryInterval(void) const;
|
2014-08-26 12:02:55 +02:00
|
|
|
void SetRetryInterval(double interval, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
int GetMaxCheckAttempts(void) const;
|
2014-08-26 13:18:02 +02:00
|
|
|
void SetMaxCheckAttempts(int attempts, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
long GetSchedulingOffset(void);
|
|
|
|
void SetSchedulingOffset(long offset);
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
void SetNextCheck(double nextCheck, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
double GetNextCheck(void);
|
|
|
|
void UpdateNextCheck(void);
|
|
|
|
|
|
|
|
bool HasBeenChecked(void) const;
|
|
|
|
|
|
|
|
double GetLastCheck(void) const;
|
|
|
|
|
|
|
|
bool GetEnableActiveChecks(void) const;
|
2014-05-03 20:02:22 +02:00
|
|
|
void SetEnableActiveChecks(bool enabled, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
bool GetEnablePassiveChecks(void) const;
|
2014-05-03 20:02:22 +02:00
|
|
|
void SetEnablePassiveChecks(bool enabled, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
bool GetForceNextCheck(void) const;
|
2014-05-03 20:02:22 +02:00
|
|
|
void SetForceNextCheck(bool forced, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-05-26 20:56:34 +02:00
|
|
|
static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2015-01-18 22:15:35 +01:00
|
|
|
void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = Dictionary::Ptr());
|
|
|
|
void ExecuteCheck();
|
2014-05-03 20:02:22 +02:00
|
|
|
void ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
int GetModifiedAttributes(void) const;
|
2014-05-10 17:24:39 +02:00
|
|
|
void SetModifiedAttributes(int flags, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-11-13 11:23:57 +01:00
|
|
|
Endpoint::Ptr GetCommandEndpoint(void) const;
|
|
|
|
|
2014-04-12 04:21:09 +02:00
|
|
|
bool IsCheckPending(void) const;
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
static double CalculateExecutionTime(const CheckResult::Ptr& cr);
|
|
|
|
static double CalculateLatency(const CheckResult::Ptr& cr);
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, double, const MessageOrigin&)> OnNextCheckChanged;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> OnForceNextCheckChanged;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> OnForceNextNotificationChanged;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> OnEnableActiveChecksChanged;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> OnEnablePassiveChecksChanged;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> OnEnableNotificationsChanged;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> OnEnableFlappingChanged;
|
2014-05-10 16:24:58 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> OnEnablePerfdataChanged;
|
2014-08-26 11:48:46 +02:00
|
|
|
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> OnEnableEventHandlerChanged;
|
2014-08-26 12:02:55 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, double, const MessageOrigin&)> OnCheckIntervalChanged;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, double, const MessageOrigin&)> OnRetryIntervalChanged;
|
2014-08-26 13:18:02 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, int, const MessageOrigin&)> OnMaxCheckAttemptsChanged;
|
2014-11-08 21:17:16 +01:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const intrusive_ptr<EventCommand>&, const MessageOrigin&)> OnEventCommandChanged;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const intrusive_ptr<CheckCommand>&, const MessageOrigin&)> OnCheckCommandChanged;
|
2014-08-26 13:25:15 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const TimePeriod::Ptr&, const MessageOrigin&)> OnCheckPeriodChanged;
|
2014-08-26 11:48:46 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, const MessageOrigin&)> OnNewCheckResult;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, StateType, const MessageOrigin&)> OnStateChange;
|
2014-12-12 15:53:10 +01:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, std::set<Checkable::Ptr>, const MessageOrigin&)> OnReachabilityChanged;
|
2014-04-03 15:36:13 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, NotificationType, const CheckResult::Ptr&,
|
|
|
|
const String&, const String&)> OnNotificationsRequested;
|
|
|
|
static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const std::set<User::Ptr>&,
|
|
|
|
const NotificationType&, const CheckResult::Ptr&, const String&,
|
|
|
|
const String&)> OnNotificationSendStart;
|
|
|
|
static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const User::Ptr&,
|
|
|
|
const NotificationType&, const CheckResult::Ptr&, const String&,
|
|
|
|
const String&, const String&)> OnNotificationSentToUser;
|
|
|
|
static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const std::set<User::Ptr>&,
|
|
|
|
const NotificationType&, const CheckResult::Ptr&, const String&,
|
|
|
|
const String&)> OnNotificationSentToAllUsers;
|
2014-05-03 20:02:22 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const Comment::Ptr&, const MessageOrigin&)> OnCommentAdded;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const Comment::Ptr&, const MessageOrigin&)> OnCommentRemoved;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&, const MessageOrigin&)> OnDowntimeAdded;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&, const MessageOrigin&)> OnDowntimeRemoved;
|
2014-04-03 15:36:13 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, FlappingState)> OnFlappingChanged;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&)> OnDowntimeTriggered;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType,
|
2015-02-07 21:39:19 +01:00
|
|
|
bool, double, const MessageOrigin&)> OnAcknowledgementSet;
|
2014-05-03 20:02:22 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const MessageOrigin&)> OnAcknowledgementCleared;
|
2014-04-03 15:36:13 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&)> OnEventCommandExecuted;
|
|
|
|
|
|
|
|
/* Downtimes */
|
|
|
|
static int GetNextDowntimeID(void);
|
|
|
|
|
|
|
|
int GetDowntimeDepth(void) const;
|
|
|
|
|
|
|
|
String AddDowntime(const String& author, const String& comment,
|
|
|
|
double startTime, double endTime, bool fixed,
|
|
|
|
const String& triggeredBy, double duration,
|
|
|
|
const String& scheduledBy = String(), const String& id = String(),
|
2014-05-03 20:02:22 +02:00
|
|
|
const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
static void RemoveDowntime(const String& id, bool cancelled, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-08-17 17:57:20 +02:00
|
|
|
void TriggerDowntimes(void);
|
2014-04-03 15:36:13 +02:00
|
|
|
static void TriggerDowntime(const String& id);
|
|
|
|
|
|
|
|
static String GetDowntimeIDFromLegacyID(int id);
|
|
|
|
static Checkable::Ptr GetOwnerByDowntimeID(const String& id);
|
|
|
|
static Downtime::Ptr GetDowntimeByID(const String& id);
|
|
|
|
|
|
|
|
static void StartDowntimesExpiredTimer(void);
|
|
|
|
|
|
|
|
bool IsInDowntime(void) const;
|
|
|
|
bool IsAcknowledged(void);
|
|
|
|
|
|
|
|
/* Comments */
|
|
|
|
static int GetNextCommentID(void);
|
|
|
|
|
|
|
|
String AddComment(CommentType entryType, const String& author,
|
2014-05-03 20:02:22 +02:00
|
|
|
const String& text, double expireTime, const String& id = String(), const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
void RemoveAllComments(void);
|
|
|
|
void RemoveCommentsByType(int type);
|
2014-05-03 20:02:22 +02:00
|
|
|
static void RemoveComment(const String& id, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
static String GetCommentIDFromLegacyID(int id);
|
|
|
|
static Checkable::Ptr GetOwnerByCommentID(const String& id);
|
|
|
|
static Comment::Ptr GetCommentByID(const String& id);
|
|
|
|
|
|
|
|
/* Notifications */
|
|
|
|
bool GetEnableNotifications(void) const;
|
2014-05-03 20:02:22 +02:00
|
|
|
void SetEnableNotifications(bool enabled, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
void SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author = "", const String& text = "");
|
|
|
|
|
|
|
|
std::set<Notification::Ptr> GetNotifications(void) const;
|
|
|
|
void AddNotification(const Notification::Ptr& notification);
|
|
|
|
void RemoveNotification(const Notification::Ptr& notification);
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
void SetForceNextNotification(bool force, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
bool GetForceNextNotification(void) const;
|
|
|
|
|
|
|
|
void ResetNotificationNumbers(void);
|
|
|
|
|
|
|
|
/* Event Handler */
|
2014-11-13 11:23:57 +01:00
|
|
|
void ExecuteEventHandler(const Dictionary::Ptr& resolvedMacros = Dictionary::Ptr(),
|
|
|
|
bool useResolvedMacros = false);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
intrusive_ptr<EventCommand> GetEventCommand(void) const;
|
|
|
|
void SetEventCommand(const intrusive_ptr<EventCommand>& command, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
bool GetEnableEventHandler(void) const;
|
2014-08-26 11:48:46 +02:00
|
|
|
void SetEnableEventHandler(bool enabled, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
/* Flapping Detection */
|
|
|
|
double GetFlappingCurrent(void) const;
|
|
|
|
|
|
|
|
bool GetEnableFlapping(void) const;
|
2014-05-03 20:02:22 +02:00
|
|
|
void SetEnableFlapping(bool enabled, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
bool IsFlapping(void) const;
|
|
|
|
void UpdateFlappingStatus(bool stateChange);
|
|
|
|
|
|
|
|
/* Performance data */
|
|
|
|
bool GetEnablePerfdata(void) const;
|
2014-05-03 20:02:22 +02:00
|
|
|
void SetEnablePerfdata(bool enabled, const MessageOrigin& origin = MessageOrigin());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
/* Dependencies */
|
2014-11-08 21:17:16 +01:00
|
|
|
void AddDependency(const intrusive_ptr<Dependency>& dep);
|
|
|
|
void RemoveDependency(const intrusive_ptr<Dependency>& dep);
|
|
|
|
std::set<intrusive_ptr<Dependency> > GetDependencies(void) const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
void AddReverseDependency(const intrusive_ptr<Dependency>& dep);
|
|
|
|
void RemoveReverseDependency(const intrusive_ptr<Dependency>& dep);
|
|
|
|
std::set<intrusive_ptr<Dependency> > GetReverseDependencies(void) const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-11-30 23:32:13 +01:00
|
|
|
virtual void ValidateCheckIntervalRaw(double value, const ValidationUtils& utils) override;
|
2014-12-05 12:59:57 +01:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
protected:
|
|
|
|
virtual void Start(void);
|
|
|
|
|
|
|
|
virtual void OnStateLoaded(void);
|
|
|
|
|
|
|
|
private:
|
2014-05-01 23:53:08 +02:00
|
|
|
mutable boost::mutex m_CheckableMutex;
|
2014-04-03 15:36:13 +02:00
|
|
|
bool m_CheckRunning;
|
|
|
|
long m_SchedulingOffset;
|
|
|
|
|
|
|
|
/* Downtimes */
|
|
|
|
static void DowntimesExpireTimerHandler(void);
|
|
|
|
void RemoveExpiredDowntimes(void);
|
|
|
|
void AddDowntimesToCache(void);
|
|
|
|
|
|
|
|
/* Comments */
|
|
|
|
static void CommentsExpireTimerHandler(void);
|
|
|
|
void RemoveExpiredComments(void);
|
|
|
|
void AddCommentsToCache(void);
|
|
|
|
|
|
|
|
/* Notifications */
|
|
|
|
std::set<Notification::Ptr> m_Notifications;
|
2015-01-29 13:18:46 +01:00
|
|
|
mutable boost::mutex m_NotificationMutex;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
/* Dependencies */
|
|
|
|
mutable boost::mutex m_DependencyMutex;
|
2014-11-08 21:17:16 +01:00
|
|
|
std::set<intrusive_ptr<Dependency> > m_Dependencies;
|
|
|
|
std::set<intrusive_ptr<Dependency> > m_ReverseDependencies;
|
2014-04-03 15:36:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CHECKABLE_H */
|
2014-11-08 21:17:16 +01:00
|
|
|
|
|
|
|
#include "icinga/dependency.hpp"
|