icinga2/lib/icinga/service.h

366 lines
11 KiB
C
Raw Normal View History

/******************************************************************************
* 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 SERVICE_H
#define SERVICE_H
2013-03-17 20:19:29 +01:00
#include "icinga/i2-icinga.h"
#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 "remoting/requestmessage.h"
#include "remoting/endpoint.h"
#include "base/i2-base.h"
2013-03-17 20:19:29 +01:00
#include "base/dynamicobject.h"
#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 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
};
/**
* The state of a service downtime.
*
* @ingroup icinga
*/
enum DowntimeState
{
DowntimeStarted = 0,
DowntimeCancelled = 1,
DowntimeStopped = 2
};
class CheckCommand;
class EventCommand;
2012-09-17 13:35:55 +02:00
/**
* An Icinga service.
*
* @ingroup icinga
*/
class I2_ICINGA_API Service : public DynamicObject, public MacroResolver
{
public:
typedef shared_ptr<Service> Ptr;
typedef weak_ptr<Service> WeakPtr;
2013-03-14 23:52:52 +01:00
explicit Service(const Dictionary::Ptr& serializedUpdate);
~Service(void);
static Service::Ptr GetByName(const String& name);
2012-06-27 18:43:34 +02: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;
String GetDisplayName(void) const;
Host::Ptr GetHost(void) const;
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;
String GetShortName(void) const;
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
bool IsVolatile(void) const;
2013-03-02 09:07:47 +01:00
bool IsReachable(void) const;
AcknowledgementType GetAcknowledgement(void);
void SetAcknowledgement(AcknowledgementType acknowledgement);
/* Checks */
2013-03-14 12:17:46 +01:00
Array::Ptr GetCheckers(void) const;
shared_ptr<CheckCommand> GetCheckCommand(void) const;
long GetMaxCheckAttempts(void) const;
2013-03-13 16:04:53 +01:00
TimePeriod::Ptr GetCheckPeriod(void) const;
double GetCheckInterval(void) const;
double GetRetryInterval(void) const;
2012-07-03 14:18:46 +02:00
long GetSchedulingOffset(void);
void SetSchedulingOffset(long offset);
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;
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
void SetLastCheckResult(const Dictionary::Ptr& result);
Dictionary::Ptr GetLastCheckResult(void) const;
2012-06-27 18:43:34 +02:00
void SetLastStateChange(double ts);
double GetLastStateChange(void) const;
2012-06-27 18:43:34 +02:00
void SetLastHardStateChange(double ts);
double GetLastHardStateChange(void) const;
2012-06-27 18:43:34 +02:00
2013-03-19 13:04:30 +01:00
void SetLastReachable(bool reachable);
bool GetLastReachable(void) const;
bool GetEnableActiveChecks(void) const;
void SetEnableActiveChecks(bool enabled);
bool GetEnablePassiveChecks(void) const;
void SetEnablePassiveChecks(bool enabled);
bool GetForceNextCheck(void) const;
void SetForceNextCheck(bool forced);
double GetAcknowledgementExpiry(void) const;
void SetAcknowledgementExpiry(double timestamp);
static void UpdateStatistics(const Dictionary::Ptr& cr);
2012-06-27 18:43:34 +02:00
void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry = 0);
void ClearAcknowledgement(void);
2013-03-25 18:36:15 +01:00
void ExecuteCheck(void);
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);
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-16 21:18:53 +01:00
static boost::signals2::signal<void (const Service::Ptr&)> OnCheckerChanged;
static boost::signals2::signal<void (const Service::Ptr&)> OnNextCheckChanged;
static boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> OnDowntimeChanged;
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
/* Downtimes */
static int GetNextDowntimeID(void);
Dictionary::Ptr GetDowntimes(void) const;
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);
bool IsInDowntime(void) const;
bool IsAcknowledged(void);
/* Comments */
static int GetNextCommentID(void);
Dictionary::Ptr GetComments(void) const;
String AddComment(CommentType entryType, const String& author,
const String& text, double expireTime);
void RemoveAllComments(void);
void RemoveCommentsByType(int type);
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 11:42:22 +01:00
/* Notifications */
bool GetEnableNotifications(void) const;
void SetEnableNotifications(bool enabled);
void RequestNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author = "", const String& text = "");
void SendNotifications(NotificationType type, const Dictionary::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 SetForceNextNotification(bool force);
bool GetForceNextNotification(void) const;
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);
/* Event Handler */
void ExecuteEventHandler(void);
shared_ptr<EventCommand> GetEventCommand(void) const;
2013-06-21 10:20:29 +02:00
/* Flapping Detection */
bool GetEnableFlapping(void) const;
void SetEnableFlapping(bool enabled);
double GetFlappingThreshold(void) const;
2013-06-21 10:20:29 +02:00
bool IsFlapping(void) const;
void UpdateFlappingStatus(bool stateChange);
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);
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;
Attribute<bool> m_Volatile;
2013-02-26 10:13:54 +01:00
/* Checks */
Attribute<String> m_CheckCommand;
2013-02-26 10:13:54 +01:00
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-03-19 13:04:30 +01:00
Attribute<bool> m_LastReachable;
2013-02-26 10:13:54 +01:00
Attribute<Dictionary::Ptr> m_LastResult;
Attribute<double> m_LastStateChange;
Attribute<double> m_LastHardStateChange;
2013-03-18 12:55:41 +01:00
Attribute<bool> m_LastInDowntime;
2013-02-26 10:13:54 +01:00
Attribute<bool> m_EnableActiveChecks;
Attribute<bool> m_EnablePassiveChecks;
Attribute<bool> m_ForceNextCheck;
2013-03-06 11:03:50 +01:00
bool m_CheckRunning;
2013-02-26 10:13:54 +01:00
long m_SchedulingOffset;
static boost::once_flag m_OnceFlag;
static Endpoint::Ptr m_Endpoint;
static void Initialize(void);
/* Downtimes */
2013-02-26 10:13:54 +01:00
Attribute<Dictionary::Ptr> m_Downtimes;
static void DowntimesExpireTimerHandler(void);
static void DowntimeRequestHandler(const RequestMessage& request);
void RemoveExpiredDowntimes(void);
2013-02-27 15:23:25 +01:00
static void RefreshDowntimesCache(void);
/* Comments */
2013-02-26 10:13:54 +01:00
Attribute<Dictionary::Ptr> m_Comments;
static void CommentsExpireTimerHandler(void);
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 */
Attribute<bool> m_EnableNotifications;
Attribute<bool> m_ForceNextNotification;
2013-02-26 10:13:54 +01:00
2013-02-27 15:23:25 +01:00
static void RefreshNotificationsCache(void);
/* Event Handler */
Attribute<String> m_EventCommand;
2013-06-21 10:20:29 +02:00
/* Flapping */
Attribute<bool> m_EnableFlapping;
2013-06-21 12:51:29 +02:00
Attribute<long> m_FlappingPositive;
Attribute<long> m_FlappingNegative;
2013-06-21 10:20:29 +02:00
Attribute<double> m_FlappingLastChange;
Attribute<double> m_FlappingThreshold;
};
}
#endif /* SERVICE_H */