2012-07-09 20:32:02 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2013-09-25 07:43:57 +02:00
|
|
|
* Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
|
2012-07-09 20:32:02 +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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2012-06-13 13:42:55 +02:00
|
|
|
#ifndef SERVICE_H
|
|
|
|
#define SERVICE_H
|
|
|
|
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "icinga/i2-icinga.h"
|
2013-10-26 09:41:45 +02:00
|
|
|
#include "icinga/service.th"
|
2013-03-22 14:40:55 +01:00
|
|
|
#include "icinga/macroresolver.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "icinga/host.h"
|
|
|
|
#include "icinga/timeperiod.h"
|
|
|
|
#include "icinga/notification.h"
|
2013-11-09 21:19:52 +01:00
|
|
|
#include "icinga/comment.h"
|
2013-11-09 22:08:26 +01:00
|
|
|
#include "icinga/downtime.h"
|
2013-06-28 16:08:43 +02:00
|
|
|
#include "base/i2-base.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "base/array.h"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include <boost/signals2.hpp>
|
2013-06-28 16:08:43 +02:00
|
|
|
#include <boost/thread/once.hpp>
|
2013-03-16 21:18:53 +01:00
|
|
|
|
2012-06-13 13:42:55 +02:00
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2013-07-01 14:29:07 +02:00
|
|
|
/**
|
2013-08-07 15:39:09 +02:00
|
|
|
* The state of service flapping.
|
2013-07-01 14:29:07 +02:00
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum FlappingState
|
|
|
|
{
|
|
|
|
FlappingStarted = 0,
|
|
|
|
FlappingDisabled = 1,
|
2013-08-20 11:06:04 +02:00
|
|
|
FlappingStopped = 2,
|
|
|
|
FlappingEnabled = 3
|
2013-07-01 14:29:07 +02:00
|
|
|
};
|
|
|
|
|
2013-10-16 11:46:54 +02:00
|
|
|
/**
|
|
|
|
* Modified attributes.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum ModifiedAttributeType
|
|
|
|
{
|
|
|
|
ModAttrNotificationsEnabled = 1,
|
|
|
|
ModAttrActiveChecksEnabled = 2,
|
|
|
|
ModAttrPassiveChecksEnabled = 4,
|
|
|
|
ModAttrEventHandlerEnabled = 8,
|
|
|
|
ModAttrFlapDetectionEnabled = 16,
|
|
|
|
ModAttrFailurePredictionEnabled = 32,
|
|
|
|
ModAttrPerformanceDataEnabled = 64,
|
|
|
|
ModAttrObsessiveHandlerEnabled = 128,
|
|
|
|
ModAttrEventHandlerCommand = 256,
|
|
|
|
ModAttrCheckCommand = 512,
|
|
|
|
ModAttrNormalCheckInterval = 1024,
|
|
|
|
ModAttrRetryCheckInterval = 2048,
|
|
|
|
ModAttrMaxCheckAttempts = 4096,
|
|
|
|
ModAttrFreshnessChecksEnabled = 8192,
|
|
|
|
ModAttrCheckTimeperiod = 16384,
|
|
|
|
ModAttrCustomVariable = 32768,
|
|
|
|
ModAttrNotificationTimeperiod = 65536
|
|
|
|
};
|
|
|
|
|
2013-06-13 11:33:00 +02:00
|
|
|
class CheckCommand;
|
|
|
|
class EventCommand;
|
2012-06-25 14:13:24 +02:00
|
|
|
|
2012-09-17 13:35:55 +02:00
|
|
|
/**
|
|
|
|
* An Icinga service.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
2013-11-04 23:14:34 +01:00
|
|
|
class I2_ICINGA_API Service : public ObjectImpl<Service>, public MacroResolver
|
2012-06-13 13:42:55 +02:00
|
|
|
{
|
|
|
|
public:
|
2013-07-09 08:42:08 +02:00
|
|
|
DECLARE_PTR_TYPEDEFS(Service);
|
2013-08-20 11:06:04 +02:00
|
|
|
DECLARE_TYPENAME(Service);
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2013-09-01 06:01:27 +02:00
|
|
|
Service(void);
|
|
|
|
|
2013-02-08 15:38:22 +01:00
|
|
|
static Service::Ptr GetByNamePair(const String& hostName, const String& serviceName);
|
|
|
|
|
2012-07-27 16:05:02 +02:00
|
|
|
Host::Ptr GetHost(void) const;
|
2012-06-14 11:18:20 +02:00
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<Host::Ptr> GetParentHosts(void) const;
|
|
|
|
std::set<Service::Ptr> GetParentServices(void) const;
|
2013-02-07 20:29:35 +01:00
|
|
|
|
2013-07-09 16:59:31 +02:00
|
|
|
bool IsHostCheck(void) const;
|
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
bool IsReachable(void) const;
|
2013-02-09 18:39:43 +01:00
|
|
|
|
|
|
|
AcknowledgementType GetAcknowledgement(void);
|
2013-08-29 13:48:18 +02:00
|
|
|
|
|
|
|
void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry = 0, const String& authority = String());
|
|
|
|
void ClearAcknowledgement(const String& authority = String());
|
2013-02-09 18:39:43 +01:00
|
|
|
|
|
|
|
/* Checks */
|
2013-06-13 11:33:00 +02:00
|
|
|
shared_ptr<CheckCommand> GetCheckCommand(void) const;
|
2013-03-13 16:04:53 +01:00
|
|
|
TimePeriod::Ptr GetCheckPeriod(void) const;
|
2013-10-16 13:02:21 +02:00
|
|
|
|
2013-02-09 18:39:43 +01:00
|
|
|
double GetCheckInterval(void) const;
|
2013-10-16 13:02:21 +02:00
|
|
|
void SetCheckInterval(double interval);
|
|
|
|
|
2013-02-09 18:39:43 +01:00
|
|
|
double GetRetryInterval(void) const;
|
2013-10-16 13:02:21 +02:00
|
|
|
void SetRetryInterval(double interval);
|
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
|
|
|
|
2013-08-28 11:12:20 +02:00
|
|
|
void SetNextCheck(double nextCheck, const String& authority = String());
|
2012-07-25 12:59:17 +02:00
|
|
|
double GetNextCheck(void);
|
2012-06-27 18:43:34 +02:00
|
|
|
void UpdateNextCheck(void);
|
2012-06-25 15:42:46 +02:00
|
|
|
|
2013-07-05 09:35:49 +02:00
|
|
|
bool HasBeenChecked(void) const;
|
|
|
|
|
|
|
|
double GetLastCheck(void) const;
|
|
|
|
|
2013-01-24 23:10:07 +01:00
|
|
|
bool GetEnableActiveChecks(void) const;
|
2013-08-28 11:12:20 +02:00
|
|
|
void SetEnableActiveChecks(bool enabled, const String& authority = String());
|
2013-01-24 23:10:07 +01:00
|
|
|
|
|
|
|
bool GetEnablePassiveChecks(void) const;
|
2013-08-28 11:12:20 +02:00
|
|
|
void SetEnablePassiveChecks(bool enabled, const String& authority = String());
|
2013-01-22 16:01:08 +01:00
|
|
|
|
|
|
|
bool GetForceNextCheck(void) const;
|
2013-08-28 11:12:20 +02:00
|
|
|
void SetForceNextCheck(bool forced, const String& authority = String());
|
2013-01-22 16:01:08 +01:00
|
|
|
|
2013-11-09 14:22:38 +01:00
|
|
|
static void UpdateStatistics(const CheckResult::Ptr& cr);
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2013-03-25 18:36:15 +01:00
|
|
|
void ExecuteCheck(void);
|
2013-11-09 14:22:38 +01:00
|
|
|
void ProcessCheckResult(const CheckResult::Ptr& cr, const String& authority = String());
|
2013-01-22 11:07:09 +01:00
|
|
|
|
2013-10-16 11:46:54 +02:00
|
|
|
int GetModifiedAttributes(void) const;
|
|
|
|
void SetModifiedAttributes(int flags);
|
|
|
|
|
2013-11-09 14:22:38 +01:00
|
|
|
static double CalculateExecutionTime(const CheckResult::Ptr& cr);
|
|
|
|
static double CalculateLatency(const CheckResult::Ptr& cr);
|
2013-02-24 01:10:34 +01:00
|
|
|
|
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-08-28 11:12:20 +02:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, double, const String&)> OnNextCheckChanged;
|
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnForceNextCheckChanged;
|
2013-08-29 11:37:51 +02:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnForceNextNotificationChanged;
|
2013-08-28 11:12:20 +02:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableActiveChecksChanged;
|
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnablePassiveChecksChanged;
|
2013-08-29 13:06:36 +02:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableNotificationsChanged;
|
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableFlappingChanged;
|
2013-11-09 14:22:38 +01:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, const String&)> OnNewCheckResult;
|
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, StateType, const String&)> OnStateChange;
|
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, NotificationType, const CheckResult::Ptr&, const String&, const String&)> OnNotificationsRequested;
|
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&)> OnNotificationSentToUser;
|
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const std::set<User::Ptr>&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> OnNotificationSentToAllUsers;
|
2013-11-09 21:19:52 +01:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> OnCommentAdded;
|
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> OnCommentRemoved;
|
2013-11-09 22:08:26 +01:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeAdded;
|
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeRemoved;
|
2013-08-29 13:06:36 +02:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
|
2013-11-09 22:08:26 +01:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&)> OnDowntimeTriggered;
|
2013-08-29 13:48:18 +02:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const String&, const String&, AcknowledgementType, double, const String&)> OnAcknowledgementSet;
|
|
|
|
static boost::signals2::signal<void (const Service::Ptr&, const String&)> OnAcknowledgementCleared;
|
2013-10-01 11:04:30 +02:00
|
|
|
static boost::signals2::signal<void (const Service::Ptr&)> OnEventCommandExecuted;
|
2012-08-03 23:03:58 +02:00
|
|
|
|
2013-11-09 14:22:38 +01:00
|
|
|
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
|
2013-03-22 14:40:55 +01:00
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
/* Downtimes */
|
|
|
|
static int GetNextDowntimeID(void);
|
|
|
|
|
2013-07-05 09:35:49 +02:00
|
|
|
int GetDowntimeDepth(void) const;
|
2013-02-09 18:39:43 +01:00
|
|
|
|
2013-11-09 22:08:26 +01:00
|
|
|
String AddDowntime(const String& author, const String& comment,
|
2013-02-09 01:16:43 +01:00
|
|
|
double startTime, double endTime, bool fixed,
|
2013-08-28 16:08:22 +02:00
|
|
|
const String& triggeredBy, double duration,
|
|
|
|
const String& id = String(), const String& authority = String());
|
2013-02-09 01:16:43 +01:00
|
|
|
|
2013-09-18 10:06:31 +02:00
|
|
|
static void RemoveDowntime(const String& id, bool cancelled, const String& = String());
|
2013-02-09 01:16:43 +01:00
|
|
|
|
|
|
|
void TriggerDowntimes(void);
|
|
|
|
static void TriggerDowntime(const String& id);
|
|
|
|
|
|
|
|
static String GetDowntimeIDFromLegacyID(int id);
|
|
|
|
static Service::Ptr GetOwnerByDowntimeID(const String& id);
|
2013-11-09 22:08:26 +01:00
|
|
|
static Downtime::Ptr GetDowntimeByID(const String& id);
|
2013-02-09 01:16:43 +01:00
|
|
|
|
2013-09-17 20:11:29 +02:00
|
|
|
void StartDowntimesExpiredTimer(void);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
String AddComment(CommentType entryType, const String& author,
|
2013-08-28 14:59:41 +02:00
|
|
|
const String& text, double expireTime, const String& id = String(), const String& authority = String());
|
2013-02-09 01:16:43 +01:00
|
|
|
|
|
|
|
void RemoveAllComments(void);
|
2013-06-19 10:57:07 +02:00
|
|
|
void RemoveCommentsByType(int type);
|
2013-08-28 14:59:41 +02:00
|
|
|
static void RemoveComment(const String& id, const String& authority = String());
|
2013-02-09 01:16:43 +01:00
|
|
|
|
|
|
|
static String GetCommentIDFromLegacyID(int id);
|
|
|
|
static Service::Ptr GetOwnerByCommentID(const String& id);
|
2013-11-09 21:19:52 +01:00
|
|
|
static Comment::Ptr GetCommentByID(const String& id);
|
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;
|
2013-08-29 13:06:36 +02:00
|
|
|
void SetEnableNotifications(bool enabled, const String& authority = String());
|
2013-02-26 12:37:25 +01:00
|
|
|
|
2013-11-09 14:22:38 +01:00
|
|
|
void SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author = "", const String& text = "");
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<Notification::Ptr> GetNotifications(void) const;
|
2013-08-20 11:06:04 +02:00
|
|
|
void AddNotification(const Notification::Ptr& notification);
|
|
|
|
void RemoveNotification(const Notification::Ptr& notification);
|
2013-02-27 12:44:51 +01:00
|
|
|
|
2013-08-29 11:37:51 +02:00
|
|
|
void SetForceNextNotification(bool force, const String& authority = String());
|
2013-03-21 13:22:26 +01:00
|
|
|
bool GetForceNextNotification(void) const;
|
|
|
|
|
2013-07-18 17:04:09 +02:00
|
|
|
void ResetNotificationNumbers(void);
|
|
|
|
|
2013-03-04 15:52:42 +01:00
|
|
|
void UpdateSlaveNotifications(void);
|
2013-02-09 15:20:10 +01:00
|
|
|
|
2013-06-13 11:33:00 +02:00
|
|
|
/* Event Handler */
|
|
|
|
void ExecuteEventHandler(void);
|
|
|
|
shared_ptr<EventCommand> GetEventCommand(void) const;
|
2013-10-16 15:20:14 +02:00
|
|
|
|
|
|
|
bool GetEnableEventHandler(void) const;
|
|
|
|
void SetEnableEventHandler(bool enabled);
|
2013-06-13 11:33:00 +02:00
|
|
|
|
2013-06-21 10:20:29 +02:00
|
|
|
/* Flapping Detection */
|
2013-10-26 09:41:45 +02:00
|
|
|
double GetFlappingCurrent(void) const;
|
|
|
|
|
2013-06-21 10:28:21 +02:00
|
|
|
bool GetEnableFlapping(void) const;
|
2013-08-29 13:06:36 +02:00
|
|
|
void SetEnableFlapping(bool enabled, const String& authority = String());
|
2013-06-21 10:28:21 +02:00
|
|
|
|
2013-06-21 10:20:29 +02:00
|
|
|
bool IsFlapping(void) const;
|
|
|
|
void UpdateFlappingStatus(bool stateChange);
|
|
|
|
|
2012-08-03 23:03:58 +02:00
|
|
|
protected:
|
2013-08-20 11:06:04 +02:00
|
|
|
virtual void Start(void);
|
|
|
|
|
2013-08-29 16:53:57 +02:00
|
|
|
virtual void OnConfigLoaded(void);
|
|
|
|
|
2013-01-22 11:07:09 +01:00
|
|
|
private:
|
2013-03-06 11:03:50 +01:00
|
|
|
bool m_CheckRunning;
|
2013-02-26 10:13:54 +01:00
|
|
|
long m_SchedulingOffset;
|
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
/* Downtimes */
|
2013-02-13 22:36:24 +01:00
|
|
|
static void DowntimesExpireTimerHandler(void);
|
2013-02-09 01:16:43 +01:00
|
|
|
void RemoveExpiredDowntimes(void);
|
2013-08-20 11:06:04 +02:00
|
|
|
void AddDowntimesToCache(void);
|
2013-02-27 15:23:25 +01:00
|
|
|
|
2013-02-09 01:16:43 +01:00
|
|
|
/* Comments */
|
2013-02-13 22:36:24 +01:00
|
|
|
static void CommentsExpireTimerHandler(void);
|
2013-02-09 01:16:43 +01:00
|
|
|
void RemoveExpiredComments(void);
|
2013-08-20 11:06:04 +02:00
|
|
|
void AddCommentsToCache(void);
|
2013-02-27 15:23:25 +01:00
|
|
|
|
2013-02-09 11:42:22 +01:00
|
|
|
/* Notifications */
|
2013-08-20 11:06:04 +02:00
|
|
|
std::set<Notification::Ptr> m_Notifications;
|
2012-06-13 13:42:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-16 20:44:24 +02:00
|
|
|
#endif /* SERVICE_H */
|