2012-07-09 20:32:02 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* 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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2012-06-13 13:42:55 +02:00
|
|
|
#ifndef SERVICE_H
|
|
|
|
#define SERVICE_H
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2012-09-17 13:35:55 +02:00
|
|
|
/**
|
|
|
|
* The state of a service.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
2012-06-25 15:42:46 +02:00
|
|
|
enum ServiceState
|
|
|
|
{
|
|
|
|
StateOK,
|
|
|
|
StateWarning,
|
|
|
|
StateCritical,
|
2012-06-27 18:43:34 +02:00
|
|
|
StateUnknown,
|
2012-06-25 15:42:46 +02:00
|
|
|
StateUncheckable,
|
|
|
|
};
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
/**
|
|
|
|
* The acknowledgement type of a service.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum AcknowledgementType
|
|
|
|
{
|
|
|
|
AcknowledgementNone = 0,
|
|
|
|
AcknowledgementNormal = 1,
|
|
|
|
AcknowledgementSticky = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of a service comment.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum CommentType
|
|
|
|
{
|
|
|
|
CommentUser = 1,
|
|
|
|
CommentDowntime = 2,
|
|
|
|
CommentFlapping = 3,
|
|
|
|
CommentAcknowledgement = 4
|
|
|
|
};
|
|
|
|
|
2012-07-26 12:28:29 +02:00
|
|
|
class CheckResultMessage;
|
2012-06-25 14:13:24 +02:00
|
|
|
|
2012-09-17 13:35:55 +02:00
|
|
|
/**
|
|
|
|
* An Icinga service.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
2012-09-10 14:07:32 +02:00
|
|
|
class I2_ICINGA_API Service : public DynamicObject
|
2012-06-13 13:42:55 +02:00
|
|
|
{
|
|
|
|
public:
|
2012-07-27 16:05:02 +02:00
|
|
|
typedef shared_ptr<Service> Ptr;
|
|
|
|
typedef weak_ptr<Service> WeakPtr;
|
|
|
|
|
2013-03-14 23:52:52 +01:00
|
|
|
explicit Service(const Dictionary::Ptr& serializedUpdate);
|
2013-01-24 15:01:06 +01:00
|
|
|
~Service(void);
|
2012-06-13 13:42:55 +02:00
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
static Service::Ptr GetByName(const String& name);
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2013-02-08 15:38:22 +01:00
|
|
|
static Service::Ptr GetByNamePair(const String& hostName, const String& serviceName);
|
|
|
|
|
2012-09-05 10:13:24 +02:00
|
|
|
static const int DefaultMaxCheckAttempts;
|
2013-03-07 12:04:20 +01:00
|
|
|
static const double DefaultCheckInterval;
|
|
|
|
static const double CheckIntervalDivisor;
|
2012-09-03 12:48:20 +02:00
|
|
|
|
2013-02-09 17:50:47 +01:00
|
|
|
String GetDisplayName(void) const;
|
2012-07-27 16:05:02 +02:00
|
|
|
Host::Ptr GetHost(void) const;
|
2012-06-13 13:42:55 +02:00
|
|
|
Dictionary::Ptr GetMacros(void) const;
|
2013-03-14 12:17:46 +01:00
|
|
|
Array::Ptr GetHostDependencies(void) const;
|
|
|
|
Array::Ptr GetServiceDependencies(void) const;
|
|
|
|
Array::Ptr GetGroups(void) const;
|
2013-02-26 10:13:54 +01:00
|
|
|
String GetHostName(void) const;
|
2013-02-08 15:38:22 +01:00
|
|
|
String GetShortName(void) const;
|
2012-06-14 11:18:20 +02:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
Dictionary::Ptr CalculateDynamicMacros(void) const;
|
2013-03-07 12:04:20 +01:00
|
|
|
Dictionary::Ptr CalculateAllMacros(void) const;
|
2013-02-09 18:39:43 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
set<Host::Ptr> GetParentHosts(void) const;
|
|
|
|
set<Service::Ptr> GetParentServices(void) const;
|
2013-02-07 20:29:35 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
bool IsReachable(void) const;
|
2013-02-09 18:39:43 +01:00
|
|
|
|
|
|
|
AcknowledgementType GetAcknowledgement(void);
|
|
|
|
void SetAcknowledgement(AcknowledgementType acknowledgement);
|
|
|
|
|
|
|
|
/* Checks */
|
2013-03-14 12:17:46 +01:00
|
|
|
Array::Ptr GetCheckers(void) const;
|
2013-02-13 20:08:09 +01:00
|
|
|
Value GetCheckCommand(void) const;
|
2013-02-09 18:39:43 +01:00
|
|
|
long GetMaxCheckAttempts(void) const;
|
2013-03-13 16:04:53 +01:00
|
|
|
TimePeriod::Ptr GetCheckPeriod(void) const;
|
2013-02-09 18:39:43 +01:00
|
|
|
double GetCheckInterval(void) const;
|
|
|
|
double GetRetryInterval(void) const;
|
2012-07-03 14:18:46 +02:00
|
|
|
|
2012-07-25 12:59:17 +02:00
|
|
|
long GetSchedulingOffset(void);
|
|
|
|
void SetSchedulingOffset(long offset);
|
2013-01-23 15:25:00 +01:00
|
|
|
|
2012-07-25 12:59:17 +02:00
|
|
|
void SetNextCheck(double nextCheck);
|
|
|
|
double GetNextCheck(void);
|
2012-06-27 18:43:34 +02:00
|
|
|
void UpdateNextCheck(void);
|
2012-06-25 15:42:46 +02:00
|
|
|
|
2013-02-26 10:13:54 +01:00
|
|
|
void SetCurrentChecker(const String& checker);
|
|
|
|
String GetCurrentChecker(void) const;
|
2012-06-25 14:13:24 +02:00
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
bool IsAllowedChecker(const String& checker) const;
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2012-06-25 15:42:46 +02:00
|
|
|
void SetCurrentCheckAttempt(long attempt);
|
|
|
|
long GetCurrentCheckAttempt(void) const;
|
|
|
|
|
|
|
|
void SetState(ServiceState state);
|
|
|
|
ServiceState GetState(void) const;
|
|
|
|
|
2013-03-07 12:04:20 +01:00
|
|
|
void SetStateType(StateType type);
|
|
|
|
StateType GetStateType(void) const;
|
|
|
|
|
|
|
|
void SetLastState(ServiceState state);
|
|
|
|
ServiceState GetLastState(void) const;
|
|
|
|
|
|
|
|
void SetLastStateType(StateType type);
|
|
|
|
StateType GetLastStateType(void) const;
|
2012-06-25 15:42:46 +02:00
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
void SetLastCheckResult(const Dictionary::Ptr& result);
|
|
|
|
Dictionary::Ptr GetLastCheckResult(void) const;
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2012-07-25 12:59:17 +02:00
|
|
|
void SetLastStateChange(double ts);
|
|
|
|
double GetLastStateChange(void) const;
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2012-07-25 12:59:17 +02:00
|
|
|
void SetLastHardStateChange(double ts);
|
|
|
|
double GetLastHardStateChange(void) const;
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2013-01-24 23:10:07 +01:00
|
|
|
bool GetEnableActiveChecks(void) const;
|
|
|
|
void SetEnableActiveChecks(bool enabled);
|
|
|
|
|
|
|
|
bool GetEnablePassiveChecks(void) const;
|
|
|
|
void SetEnablePassiveChecks(bool enabled);
|
2013-01-22 16:01:08 +01:00
|
|
|
|
|
|
|
bool GetForceNextCheck(void) const;
|
|
|
|
void SetForceNextCheck(bool forced);
|
|
|
|
|
2013-01-23 13:21:07 +01:00
|
|
|
double GetAcknowledgementExpiry(void) const;
|
|
|
|
void SetAcknowledgementExpiry(double timestamp);
|
|
|
|
|
2013-02-11 23:37:39 +01:00
|
|
|
static void UpdateStatistics(const Dictionary::Ptr& cr);
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2013-02-24 12:47:24 +01:00
|
|
|
void AcknowledgeProblem(AcknowledgementType type, double expiry = 0);
|
|
|
|
void ClearAcknowledgement(void);
|
|
|
|
|
2013-03-04 15:52:42 +01:00
|
|
|
void BeginExecuteCheck(const function<void (void)>& callback);
|
2013-01-22 11:07:09 +01:00
|
|
|
void ProcessCheckResult(const Dictionary::Ptr& cr);
|
|
|
|
|
2013-02-24 01:10:34 +01:00
|
|
|
static double CalculateExecutionTime(const Dictionary::Ptr& cr);
|
|
|
|
static double CalculateLatency(const Dictionary::Ptr& cr);
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
static ServiceState StateFromString(const String& state);
|
|
|
|
static String StateToString(ServiceState state);
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2013-03-07 12:04:20 +01:00
|
|
|
static StateType StateTypeFromString(const String& state);
|
|
|
|
static String StateTypeToString(StateType state);
|
2012-07-03 14:18:46 +02:00
|
|
|
|
2013-03-04 15:52:42 +01:00
|
|
|
static signals2::signal<void (const Service::Ptr&)> OnCheckerChanged;
|
|
|
|
static signals2::signal<void (const Service::Ptr&)> OnNextCheckChanged;
|
2012-08-03 23:03:58 +02:00
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
/* Downtimes */
|
|
|
|
static int GetNextDowntimeID(void);
|
|
|
|
|
2013-02-09 18:39:43 +01:00
|
|
|
Dictionary::Ptr GetDowntimes(void) const;
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
String AddDowntime(const String& author, const String& comment,
|
|
|
|
double startTime, double endTime, bool fixed,
|
|
|
|
const String& triggeredBy, double duration);
|
|
|
|
|
|
|
|
static void RemoveDowntime(const String& id);
|
|
|
|
|
|
|
|
void TriggerDowntimes(void);
|
|
|
|
static void TriggerDowntime(const String& id);
|
|
|
|
|
|
|
|
static String GetDowntimeIDFromLegacyID(int id);
|
|
|
|
static Service::Ptr GetOwnerByDowntimeID(const String& id);
|
|
|
|
static Dictionary::Ptr GetDowntimeByID(const String& id);
|
|
|
|
|
|
|
|
static bool IsDowntimeActive(const Dictionary::Ptr& downtime);
|
|
|
|
static bool IsDowntimeExpired(const Dictionary::Ptr& downtime);
|
|
|
|
|
2013-02-27 15:23:25 +01:00
|
|
|
static void InvalidateDowntimesCache(void);
|
2013-02-09 01:16:43 +01:00
|
|
|
|
2013-02-09 18:39:43 +01:00
|
|
|
bool IsInDowntime(void) const;
|
2013-02-11 16:38:16 +01:00
|
|
|
bool IsAcknowledged(void);
|
2013-02-09 18:39:43 +01:00
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
/* Comments */
|
|
|
|
static int GetNextCommentID(void);
|
|
|
|
|
2013-02-09 18:39:43 +01:00
|
|
|
Dictionary::Ptr GetComments(void) const;
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
String AddComment(CommentType entryType, const String& author,
|
|
|
|
const String& text, double expireTime);
|
|
|
|
|
|
|
|
void RemoveAllComments(void);
|
|
|
|
static void RemoveComment(const String& id);
|
|
|
|
|
|
|
|
static String GetCommentIDFromLegacyID(int id);
|
|
|
|
static Service::Ptr GetOwnerByCommentID(const String& id);
|
|
|
|
static Dictionary::Ptr GetCommentByID(const String& id);
|
|
|
|
|
|
|
|
static bool IsCommentExpired(const Dictionary::Ptr& comment);
|
|
|
|
|
2013-02-27 15:23:25 +01:00
|
|
|
static void InvalidateCommentsCache(void);
|
2013-02-09 01:16:43 +01:00
|
|
|
|
2013-02-09 11:42:22 +01:00
|
|
|
/* Notifications */
|
2013-02-26 12:37:25 +01:00
|
|
|
bool GetEnableNotifications(void) const;
|
|
|
|
void SetEnableNotifications(bool enabled);
|
|
|
|
|
2013-02-27 12:44:51 +01:00
|
|
|
double GetNotificationInterval(void) const;
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2013-03-07 12:04:20 +01:00
|
|
|
void RequestNotifications(NotificationType type, const Dictionary::Ptr& cr);
|
|
|
|
void SendNotifications(NotificationType type, const Dictionary::Ptr& cr);
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
set<Notification::Ptr> GetNotifications(void) const;
|
2013-02-27 12:44:51 +01:00
|
|
|
|
2013-02-27 15:23:25 +01:00
|
|
|
static void InvalidateNotificationsCache(void);
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2013-03-04 15:52:42 +01:00
|
|
|
void UpdateSlaveNotifications(void);
|
2013-02-09 15:20:10 +01:00
|
|
|
|
2013-02-09 17:27:32 +01:00
|
|
|
double GetLastNotification(void) const;
|
|
|
|
void SetLastNotification(double time);
|
|
|
|
|
2012-08-03 23:03:58 +02:00
|
|
|
protected:
|
2013-02-20 19:52:25 +01:00
|
|
|
virtual void OnRegistrationCompleted(void);
|
2013-03-04 15:52:42 +01:00
|
|
|
virtual void OnAttributeChanged(const String& name);
|
2013-01-22 11:07:09 +01:00
|
|
|
|
|
|
|
private:
|
2013-02-26 10:13:54 +01:00
|
|
|
Dictionary::Ptr m_SlaveNotifications;
|
|
|
|
|
|
|
|
Attribute<String> m_DisplayName;
|
|
|
|
Attribute<Dictionary::Ptr> m_Macros;
|
2013-03-14 12:17:46 +01:00
|
|
|
Attribute<Array::Ptr> m_HostDependencies;
|
|
|
|
Attribute<Array::Ptr> m_ServiceDependencies;
|
|
|
|
Attribute<Array::Ptr> m_ServiceGroups;
|
2013-02-26 10:13:54 +01:00
|
|
|
Attribute<String> m_ShortName;
|
|
|
|
Attribute<long> m_Acknowledgement;
|
|
|
|
Attribute<double> m_AcknowledgementExpiry;
|
|
|
|
Attribute<String> m_HostName;
|
|
|
|
|
|
|
|
/* Checks */
|
|
|
|
Attribute<Value> m_CheckCommand;
|
|
|
|
Attribute<long> m_MaxCheckAttempts;
|
2013-03-13 16:04:53 +01:00
|
|
|
Attribute<String> m_CheckPeriod;
|
2013-02-26 10:13:54 +01:00
|
|
|
Attribute<double> m_CheckInterval;
|
|
|
|
Attribute<double> m_RetryInterval;
|
|
|
|
Attribute<double> m_NextCheck;
|
2013-03-14 12:17:46 +01:00
|
|
|
Attribute<Array::Ptr> m_Checkers;
|
2013-02-26 10:13:54 +01:00
|
|
|
Attribute<String> m_CurrentChecker;
|
|
|
|
Attribute<long> m_CheckAttempt;
|
|
|
|
Attribute<long> m_State;
|
|
|
|
Attribute<long> m_StateType;
|
2013-03-07 12:04:20 +01:00
|
|
|
Attribute<long> m_LastState;
|
|
|
|
Attribute<long> m_LastStateType;
|
2013-02-26 10:13:54 +01:00
|
|
|
Attribute<Dictionary::Ptr> m_LastResult;
|
|
|
|
Attribute<double> m_LastStateChange;
|
|
|
|
Attribute<double> m_LastHardStateChange;
|
|
|
|
Attribute<bool> m_EnableActiveChecks;
|
|
|
|
Attribute<bool> m_EnablePassiveChecks;
|
|
|
|
Attribute<bool> m_ForceNextCheck;
|
|
|
|
|
|
|
|
ScriptTask::Ptr m_CurrentTask;
|
2013-03-06 11:03:50 +01:00
|
|
|
bool m_CheckRunning;
|
2013-02-26 10:13:54 +01:00
|
|
|
long m_SchedulingOffset;
|
|
|
|
|
2013-02-24 01:10:34 +01:00
|
|
|
void CheckCompletedHandler(const Dictionary::Ptr& checkInfo,
|
2013-02-09 11:42:22 +01:00
|
|
|
const ScriptTask::Ptr& task, const function<void (void)>& callback);
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
/* Downtimes */
|
2013-02-26 10:13:54 +01:00
|
|
|
Attribute<Dictionary::Ptr> m_Downtimes;
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
static int m_NextDowntimeID;
|
|
|
|
|
2013-02-27 12:44:51 +01:00
|
|
|
static boost::mutex m_DowntimeMutex;
|
2013-02-13 22:36:24 +01:00
|
|
|
static map<int, String> m_LegacyDowntimesCache;
|
|
|
|
static map<String, Service::WeakPtr> m_DowntimesCache;
|
2013-03-06 11:03:50 +01:00
|
|
|
static bool m_DowntimesCacheNeedsUpdate;
|
|
|
|
static Timer::Ptr m_DowntimesCacheTimer;
|
2013-02-13 22:36:24 +01:00
|
|
|
static Timer::Ptr m_DowntimesExpireTimer;
|
2013-02-09 01:16:43 +01:00
|
|
|
|
2013-02-13 22:36:24 +01:00
|
|
|
static void DowntimesExpireTimerHandler(void);
|
2013-02-09 01:16:43 +01:00
|
|
|
|
|
|
|
void RemoveExpiredDowntimes(void);
|
|
|
|
|
2013-02-27 15:23:25 +01:00
|
|
|
static void RefreshDowntimesCache(void);
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
/* Comments */
|
2013-02-26 10:13:54 +01:00
|
|
|
Attribute<Dictionary::Ptr> m_Comments;
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
static int m_NextCommentID;
|
|
|
|
|
2013-02-27 12:44:51 +01:00
|
|
|
static boost::mutex m_CommentMutex;
|
2013-02-13 22:36:24 +01:00
|
|
|
static map<int, String> m_LegacyCommentsCache;
|
|
|
|
static map<String, Service::WeakPtr> m_CommentsCache;
|
2013-03-06 11:03:50 +01:00
|
|
|
static bool m_CommentsCacheNeedsUpdate;
|
|
|
|
static Timer::Ptr m_CommentsCacheTimer;
|
2013-02-13 22:36:24 +01:00
|
|
|
static Timer::Ptr m_CommentsExpireTimer;
|
2013-02-09 01:16:43 +01:00
|
|
|
|
2013-02-13 22:36:24 +01:00
|
|
|
static void CommentsExpireTimerHandler(void);
|
2013-02-09 01:16:43 +01:00
|
|
|
|
|
|
|
void AddCommentsToCache(void);
|
|
|
|
void RemoveExpiredComments(void);
|
|
|
|
|
2013-02-27 15:23:25 +01:00
|
|
|
static void RefreshCommentsCache(void);
|
|
|
|
|
2013-02-09 11:42:22 +01:00
|
|
|
/* Notifications */
|
2013-02-26 12:37:25 +01:00
|
|
|
Attribute<bool> m_EnableNotifications;
|
2013-02-26 10:13:54 +01:00
|
|
|
Attribute<double> m_LastNotification;
|
2013-02-27 12:44:51 +01:00
|
|
|
Attribute<double> m_NotificationInterval;
|
2013-02-26 10:13:54 +01:00
|
|
|
|
2013-02-27 12:44:51 +01:00
|
|
|
static boost::mutex m_NotificationMutex;
|
2013-02-09 11:42:22 +01:00
|
|
|
static map<String, set<Notification::WeakPtr> > m_NotificationsCache;
|
2013-03-06 11:03:50 +01:00
|
|
|
static bool m_NotificationsCacheNeedsUpdate;
|
|
|
|
static Timer::Ptr m_NotificationsCacheTimer;
|
2013-02-27 15:23:25 +01:00
|
|
|
|
|
|
|
static void RefreshNotificationsCache(void);
|
2012-06-13 13:42:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-16 20:44:24 +02:00
|
|
|
#endif /* SERVICE_H */
|