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,
|
|
|
|
};
|
|
|
|
|
2012-09-17 13:35:55 +02:00
|
|
|
/**
|
|
|
|
* The state type of a service.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
2012-06-25 15:42:46 +02:00
|
|
|
enum ServiceStateType
|
|
|
|
{
|
2012-06-27 18:43:34 +02:00
|
|
|
StateTypeSoft,
|
|
|
|
StateTypeHard
|
2012-06-25 15:42:46 +02:00
|
|
|
};
|
|
|
|
|
2012-07-26 12:28:29 +02:00
|
|
|
class CheckResultMessage;
|
2012-07-03 14:18:46 +02:00
|
|
|
class ServiceStatusMessage;
|
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;
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
Service(const Dictionary::Ptr& properties);
|
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 bool Exists(const String& name);
|
|
|
|
static Service::Ptr GetByName(const String& name);
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2012-09-05 10:13:24 +02:00
|
|
|
static const int DefaultMaxCheckAttempts;
|
2012-09-03 12:48:20 +02:00
|
|
|
static const int DefaultCheckInterval;
|
|
|
|
static const int MinCheckInterval;
|
|
|
|
static const int CheckIntervalDivisor;
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
String GetAlias(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-01-29 14:19:54 +01:00
|
|
|
Dictionary::Ptr GetDowntimes(void) const;
|
2013-01-29 16:29:09 +01:00
|
|
|
Dictionary::Ptr GetComments(void) const;
|
2012-08-02 09:38:08 +02:00
|
|
|
String GetCheckCommand(void) const;
|
2012-06-13 13:42:55 +02:00
|
|
|
long GetMaxCheckAttempts(void) const;
|
|
|
|
long GetCheckInterval(void) const;
|
|
|
|
long GetRetryInterval(void) const;
|
2012-06-27 18:43:34 +02:00
|
|
|
Dictionary::Ptr GetDependencies(void) const;
|
2012-07-09 10:09:53 +02:00
|
|
|
void GetDependenciesRecursive(const Dictionary::Ptr& result) const;
|
2012-06-30 13:39:55 +02:00
|
|
|
Dictionary::Ptr GetGroups(void) const;
|
2012-07-02 16:19:43 +02:00
|
|
|
Dictionary::Ptr GetCheckers(void) const;
|
2012-06-14 11:18:20 +02:00
|
|
|
|
2012-07-03 15:11:11 +02:00
|
|
|
bool IsReachable(void) const;
|
2013-01-29 14:19:54 +01:00
|
|
|
bool IsInDowntime(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
|
|
|
|
|
|
|
void SetFirstCheck(bool first);
|
|
|
|
bool GetFirstCheck(void) const;
|
|
|
|
|
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
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
void SetChecker(const String& checker);
|
|
|
|
String GetChecker(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;
|
|
|
|
|
|
|
|
void SetStateType(ServiceStateType type);
|
|
|
|
ServiceStateType GetStateType(void) const;
|
|
|
|
|
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
|
|
|
AcknowledgementType GetAcknowledgement(void);
|
|
|
|
void SetAcknowledgement(AcknowledgementType acknowledgement);
|
|
|
|
|
|
|
|
double GetAcknowledgementExpiry(void) const;
|
|
|
|
void SetAcknowledgementExpiry(double timestamp);
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
void ApplyCheckResult(const Dictionary::Ptr& cr);
|
2012-06-27 18:43:34 +02:00
|
|
|
|
2013-01-22 11:07:09 +01:00
|
|
|
void BeginExecuteCheck(const function<void (void)>& callback);
|
|
|
|
void ProcessCheckResult(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
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
static ServiceStateType StateTypeFromString(const String& state);
|
|
|
|
static String StateTypeToString(ServiceStateType state);
|
2012-07-03 14:18:46 +02:00
|
|
|
|
2012-07-27 16:05:02 +02:00
|
|
|
static Dictionary::Ptr ResolveDependencies(const Host::Ptr& host, const Dictionary::Ptr& dependencies);
|
2012-07-26 12:28:29 +02:00
|
|
|
|
2012-07-27 16:05:02 +02:00
|
|
|
static boost::signal<void (const Service::Ptr& service, const CheckResultMessage&)> OnCheckResultReceived;
|
2012-08-03 23:03:58 +02:00
|
|
|
static boost::signal<void (const Service::Ptr&, const String&)> OnCheckerChanged;
|
2013-01-22 12:44:23 +01:00
|
|
|
static boost::signal<void (const Service::Ptr&, const Value&)> OnNextCheckChanged;
|
2012-08-03 23:03:58 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void OnAttributeChanged(const String& name, const Value& oldValue);
|
2013-01-22 11:07:09 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void CheckCompletedHandler(const Dictionary::Ptr& scheduleInfo,
|
|
|
|
const ScriptTask::Ptr& task, const function<void (void)>& callback);
|
2012-06-13 13:42:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-16 20:44:24 +02:00
|
|
|
#endif /* SERVICE_H */
|