]> granicus.if.org Git - icinga2/blob - lib/icinga/compatutility.h
Update copyright header.
[icinga2] / lib / icinga / compatutility.h
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef COMPATUTILITY_H
21 #define COMPATUTILITY_H
22
23 #include "icinga/i2-icinga.h"
24 #include "icinga/service.h"
25 #include "icinga/checkcommand.h"
26 #include "base/dictionary.h"
27 #include "base/dynamicobject.h"
28 #include <vector>
29
30 namespace icinga
31 {
32
33 /**
34  * @ingroup icinga
35  */
36 enum CompatObjectType
37 {
38         CompatTypeService,
39         CompatTypeHost
40 };
41
42 typedef struct {
43         int have_2d_coords;
44         String x_2d;
45         String y_2d;
46 } Host2dCoords;
47
48 /**
49  * Compatibility utility functions.
50  *
51  * @ingroup icinga
52  */
53 class I2_ICINGA_API CompatUtility
54 {
55 public:
56
57         /* host */
58         static String GetHostAlias(const Host::Ptr& host);
59         static String GetHostAddress(const Host::Ptr& host);
60         static String GetHostAddress6(const Host::Ptr& host);
61         static Host2dCoords GetHost2dCoords(const Host::Ptr& host);
62         static int GetHostNotifyOnDown(const Host::Ptr& host);
63         static int GetHostNotifyOnUnreachable(const Host::Ptr& host);
64
65         /* service */
66         static int GetServiceCurrentState(const Service::Ptr& service);
67         static int GetServiceShouldBeScheduled(const Service::Ptr& service);
68         static int GetServiceCheckType(const Service::Ptr& service);
69         static double GetServiceCheckInterval(const Service::Ptr& service);
70         static double GetServiceRetryInterval(const Service::Ptr& service);
71         static String GetServiceCheckPeriod(const Service::Ptr& service);
72         static int GetServiceHasBeenChecked(const Service::Ptr& service);
73         static int GetServiceProblemHasBeenAcknowledged(const Service::Ptr& service);
74         static int GetServiceAcknowledgementType(const Service::Ptr& service);
75         static int GetServicePassiveChecksEnabled(const Service::Ptr& service);
76         static int GetServiceActiveChecksEnabled(const Service::Ptr& service);
77         static int GetServiceEventHandlerEnabled(const Service::Ptr& service);
78         static int GetServiceFlapDetectionEnabled(const Service::Ptr& service);
79         static int GetServiceIsFlapping(const Service::Ptr& service);
80         static String GetServicePercentStateChange(const Service::Ptr& service);
81         static int GetServiceProcessPerformanceData(const Service::Ptr& service);
82
83         static String GetServiceEventHandler(const Service::Ptr& service);
84         static String GetServiceCheckCommand(const Service::Ptr& service);
85
86         static int GetServiceIsVolatile(const Service::Ptr& service);
87         static double GetServiceLowFlapThreshold(const Service::Ptr& service);
88         static double GetServiceHighFlapThreshold(const Service::Ptr& service);
89         static int GetServiceFreshnessChecksEnabled(const Service::Ptr& service);
90         static int GetServiceFreshnessThreshold(const Service::Ptr& service);
91         static double GetServiceStaleness(const Service::Ptr& service);
92         static int GetServiceIsAcknowledged(const Service::Ptr& service);
93         static int GetServiceNoMoreNotifications(const Service::Ptr& service);
94         static int GetServiceInCheckPeriod(const Service::Ptr& service);
95         static int GetServiceInNotificationPeriod(const Service::Ptr& service);
96
97         /* notification */
98         static int GetServiceNotificationsEnabled(const Service::Ptr& service);
99         static int GetServiceNotificationLastNotification(const Service::Ptr& service);
100         static int GetServiceNotificationNextNotification(const Service::Ptr& service);
101         static int GetServiceNotificationNotificationNumber(const Service::Ptr& service);
102         static double GetServiceNotificationNotificationInterval(const Service::Ptr& service);
103         static String GetServiceNotificationNotificationPeriod(const Service::Ptr& service);
104         static String GetServiceNotificationNotificationOptions(const Service::Ptr& service);
105         static int GetServiceNotificationTypeFilter(const Service::Ptr& service);
106         static int GetServiceNotificationStateFilter(const Service::Ptr& service);
107         static int GetServiceNotifyOnWarning(const Service::Ptr& service);
108         static int GetServiceNotifyOnCritical(const Service::Ptr& service);
109         static int GetServiceNotifyOnUnknown(const Service::Ptr& service);
110         static int GetServiceNotifyOnRecovery(const Service::Ptr& service);
111         static int GetServiceNotifyOnFlapping(const Service::Ptr& service);
112         static int GetServiceNotifyOnDowntime(const Service::Ptr& service);
113
114         static std::set<User::Ptr> GetServiceNotificationUsers(const Service::Ptr& service);
115         static std::set<UserGroup::Ptr> GetServiceNotificationUserGroups(const Service::Ptr& service);
116
117         /* command */
118         static String GetCommandLine(const Command::Ptr& command);
119
120         /* custom attribute */
121         static String GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name);
122         static Dictionary::Ptr GetCustomVariableConfig(const DynamicObject::Ptr& object);
123
124         /* check result */
125         static String GetCheckResultOutput(const CheckResult::Ptr& cr);
126         static String GetCheckResultLongOutput(const CheckResult::Ptr& cr);
127         static String GetCheckResultPerfdata(const CheckResult::Ptr& cr);
128
129         /* misc */
130         static std::pair<unsigned long, unsigned long> ConvertTimestamp(double time);
131
132         static int MapNotificationReasonType(NotificationType type);
133         static int MapExternalCommandType(const String& name);
134
135         static String EscapeString(const String& str);
136
137 private:
138         CompatUtility(void);
139 };
140
141 }
142
143 #endif /* COMPATUTILITY_H */