icinga2/lib/icinga/service.h

317 lines
12 KiB
C
Raw Normal View History

/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2014 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 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"
#include "icinga/macroresolver.h"
2013-03-17 20:19:29 +01:00
#include "icinga/host.h"
#include "icinga/timeperiod.h"
#include "icinga/notification.h"
#include "icinga/comment.h"
#include "icinga/downtime.h"
#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>
#include <boost/thread/once.hpp>
2013-03-16 21:18:53 +01:00
namespace icinga
{
/**
* The state of service flapping.
*
* @ingroup icinga
*/
enum FlappingState
{
FlappingStarted = 0,
FlappingDisabled = 1,
FlappingStopped = 2,
FlappingEnabled = 3
};
/**
* 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
};
class CheckCommand;
class EventCommand;
2012-09-17 13:35:55 +02:00
/**
* An Icinga service.
*
* @ingroup icinga
*/
class I2_ICINGA_API Service : public ObjectImpl<Service>, public MacroResolver
{
public:
DECLARE_PTR_TYPEDEFS(Service);
DECLARE_TYPENAME(Service);
2012-06-27 18:43:34 +02:00
2013-09-01 06:01:27 +02:00
Service(void);
static Service::Ptr GetByNamePair(const String& hostName, const String& serviceName);
Host::Ptr GetHost(void) const;
2013-03-16 21:18:53 +01:00
std::set<Host::Ptr> GetParentHosts(void) const;
std::set<Host::Ptr> GetChildHosts(void) const;
2013-03-16 21:18:53 +01:00
std::set<Service::Ptr> GetParentServices(void) const;
std::set<Service::Ptr> GetChildServices(void) const;
2013-02-07 20:29:35 +01:00
2013-07-09 16:59:31 +02:00
bool IsHostCheck(void) const;
bool IsReachable(DependencyType dt = DependencyState, shared_ptr<Dependency> *failedDependency = NULL, int rstack = 0) const;
AcknowledgementType GetAcknowledgement(void);
void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry = 0, const String& authority = String());
void ClearAcknowledgement(const String& authority = String());
/* Checks */
shared_ptr<CheckCommand> GetCheckCommand(void) const;
void SetCheckCommand(const shared_ptr<CheckCommand>& command);
2013-03-13 16:04:53 +01:00
TimePeriod::Ptr GetCheckPeriod(void) const;
void SetCheckPeriod(const TimePeriod::Ptr& tp);
double GetCheckInterval(void) const;
void SetCheckInterval(double interval);
double GetRetryInterval(void) const;
void SetRetryInterval(double interval);
2012-07-03 14:18:46 +02:00
int GetMaxCheckAttempts(void) const;
void SetMaxCheckAttempts(int attempts);
long GetSchedulingOffset(void);
void SetSchedulingOffset(long offset);
2013-08-28 11:12:20 +02:00
void SetNextCheck(double nextCheck, const String& authority = String());
double GetNextCheck(void);
2012-06-27 18:43:34 +02:00
void UpdateNextCheck(void);
2012-06-25 15:42:46 +02:00
bool HasBeenChecked(void) const;
double GetLastCheck(void) const;
bool GetEnableActiveChecks(void) const;
2013-08-28 11:12:20 +02:00
void SetEnableActiveChecks(bool enabled, const String& authority = String());
bool GetEnablePassiveChecks(void) const;
2013-08-28 11:12:20 +02:00
void SetEnablePassiveChecks(bool enabled, const String& authority = String());
bool GetForceNextCheck(void) const;
2013-08-28 11:12:20 +02:00
void SetForceNextCheck(bool forced, const String& authority = String());
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);
void ProcessCheckResult(const CheckResult::Ptr& cr, const String& authority = String());
int GetModifiedAttributes(void) const;
void SetModifiedAttributes(int flags);
static double CalculateExecutionTime(const CheckResult::Ptr& cr);
static double CalculateLatency(const CheckResult::Ptr& cr);
2013-02-24 01:10:34 +01: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;
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;
static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableNotificationsChanged;
static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableFlappingChanged;
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 Notification::Ptr&, const Service::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 Service::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 Service::Ptr&, const std::set<User::Ptr>&,
const NotificationType&, const CheckResult::Ptr&, const String&,
const String&)> OnNotificationSentToAllUsers;
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;
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;
static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&)> OnDowntimeTriggered;
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;
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
/* 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(),
const String& authority = String());
static void RemoveDowntime(const String& id, bool cancelled, const String& = String());
void TriggerDowntimes(void);
static void TriggerDowntime(const String& id);
static String GetDowntimeIDFromLegacyID(int id);
static Service::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,
2013-08-28 14:59:41 +02:00
const String& text, double expireTime, const String& id = String(), const String& authority = String());
void RemoveAllComments(void);
void RemoveCommentsByType(int type);
2013-08-28 14:59:41 +02:00
static void RemoveComment(const String& id, const String& authority = String());
static String GetCommentIDFromLegacyID(int id);
static Service::Ptr GetOwnerByCommentID(const String& id);
static Comment::Ptr GetCommentByID(const String& id);
2013-02-09 11:42:22 +01:00
/* Notifications */
bool GetEnableNotifications(void) const;
void SetEnableNotifications(bool enabled, const String& authority = String());
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;
void AddNotification(const Notification::Ptr& notification);
void RemoveNotification(const Notification::Ptr& notification);
void SetForceNextNotification(bool force, const String& authority = String());
bool GetForceNextNotification(void) const;
2013-07-18 17:04:09 +02:00
void ResetNotificationNumbers(void);
/* Event Handler */
void ExecuteEventHandler(void);
shared_ptr<EventCommand> GetEventCommand(void) const;
void SetEventCommand(const shared_ptr<EventCommand>& command);
bool GetEnableEventHandler(void) const;
void SetEnableEventHandler(bool enabled);
2013-06-21 10:20:29 +02:00
/* Flapping Detection */
2013-10-26 09:41:45 +02:00
double GetFlappingCurrent(void) const;
bool GetEnableFlapping(void) const;
void SetEnableFlapping(bool enabled, const String& authority = String());
2013-06-21 10:20:29 +02:00
bool IsFlapping(void) const;
void UpdateFlappingStatus(bool stateChange);
/* Performance data */
bool GetEnablePerfdata(void) const;
void SetEnablePerfdata(bool enabled, const String& authority = String());
/* Dependencies */
void AddDependency(const shared_ptr<Dependency>& dep);
void RemoveDependency(const shared_ptr<Dependency>& dep);
std::set<shared_ptr<Dependency> > GetDependencies(void) const;
void AddReverseDependency(const shared_ptr<Dependency>& dep);
void RemoveReverseDependency(const shared_ptr<Dependency>& dep);
std::set<shared_ptr<Dependency> > GetReverseDependencies(void) const;
protected:
virtual void Start(void);
virtual void OnConfigLoaded(void);
virtual void OnStateLoaded(void);
private:
2013-11-10 22:04:18 +01:00
Host::Ptr m_Host;
2013-03-06 11:03:50 +01:00
bool m_CheckRunning;
2013-02-26 10:13:54 +01:00
long m_SchedulingOffset;
/* Downtimes */
static void DowntimesExpireTimerHandler(void);
void RemoveExpiredDowntimes(void);
void AddDowntimesToCache(void);
2013-02-27 15:23:25 +01:00
/* Comments */
static void CommentsExpireTimerHandler(void);
void RemoveExpiredComments(void);
void AddCommentsToCache(void);
2013-02-27 15:23:25 +01:00
2013-02-09 11:42:22 +01:00
/* Notifications */
std::set<Notification::Ptr> m_Notifications;
/* Dependencies */
mutable boost::mutex m_DependencyMutex;
std::set<shared_ptr<Dependency> > m_Dependencies;
std::set<shared_ptr<Dependency> > m_ReverseDependencies;
};
}
#endif /* SERVICE_H */