]> granicus.if.org Git - icinga2/blob - lib/icinga/compatutility.h
Merge 'macros' and 'custom' attributes into 'vars', part 1.
[icinga2] / lib / icinga / compatutility.h
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2014 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 String GetHost2dCoordX(const Host::Ptr& host);
63         static String GetHost2dCoordY(const Host::Ptr& host);
64         static int GetHostNotifyOnDown(const Host::Ptr& host);
65         static int GetHostNotifyOnUnreachable(const Host::Ptr& host);
66
67         /* service */
68         static int GetServiceCurrentState(const Service::Ptr& service);
69         static int GetServiceShouldBeScheduled(const Service::Ptr& service);
70         static int GetServiceCheckType(const Service::Ptr& service);
71         static double GetServiceCheckInterval(const Service::Ptr& service);
72         static double GetServiceRetryInterval(const Service::Ptr& service);
73         static String GetServiceCheckPeriod(const Service::Ptr& service);
74         static int GetServiceHasBeenChecked(const Service::Ptr& service);
75         static int GetServiceProblemHasBeenAcknowledged(const Service::Ptr& service);
76         static int GetServiceAcknowledgementType(const Service::Ptr& service);
77         static int GetServicePassiveChecksEnabled(const Service::Ptr& service);
78         static int GetServiceActiveChecksEnabled(const Service::Ptr& service);
79         static int GetServiceEventHandlerEnabled(const Service::Ptr& service);
80         static int GetServiceFlapDetectionEnabled(const Service::Ptr& service);
81         static int GetServiceIsFlapping(const Service::Ptr& service);
82         static String GetServicePercentStateChange(const Service::Ptr& service);
83         static int GetServiceProcessPerformanceData(const Service::Ptr& service);
84
85         static String GetServiceEventHandler(const Service::Ptr& service);
86         static String GetServiceCheckCommand(const Service::Ptr& service);
87
88         static int GetServiceIsVolatile(const Service::Ptr& service);
89         static double GetServiceLowFlapThreshold(const Service::Ptr& service);
90         static double GetServiceHighFlapThreshold(const Service::Ptr& service);
91         static int GetServiceFreshnessChecksEnabled(const Service::Ptr& service);
92         static int GetServiceFreshnessThreshold(const Service::Ptr& service);
93         static double GetServiceStaleness(const Service::Ptr& service);
94         static int GetServiceIsAcknowledged(const Service::Ptr& service);
95         static int GetServiceNoMoreNotifications(const Service::Ptr& service);
96         static int GetServiceInCheckPeriod(const Service::Ptr& service);
97         static int GetServiceInNotificationPeriod(const Service::Ptr& service);
98
99         /* notification */
100         static int GetServiceNotificationsEnabled(const Service::Ptr& service);
101         static int GetServiceNotificationLastNotification(const Service::Ptr& service);
102         static int GetServiceNotificationNextNotification(const Service::Ptr& service);
103         static int GetServiceNotificationNotificationNumber(const Service::Ptr& service);
104         static double GetServiceNotificationNotificationInterval(const Service::Ptr& service);
105         static String GetServiceNotificationNotificationPeriod(const Service::Ptr& service);
106         static String GetServiceNotificationNotificationOptions(const Service::Ptr& service);
107         static int GetServiceNotificationTypeFilter(const Service::Ptr& service);
108         static int GetServiceNotificationStateFilter(const Service::Ptr& service);
109         static int GetServiceNotifyOnWarning(const Service::Ptr& service);
110         static int GetServiceNotifyOnCritical(const Service::Ptr& service);
111         static int GetServiceNotifyOnUnknown(const Service::Ptr& service);
112         static int GetServiceNotifyOnRecovery(const Service::Ptr& service);
113         static int GetServiceNotifyOnFlapping(const Service::Ptr& service);
114         static int GetServiceNotifyOnDowntime(const Service::Ptr& service);
115
116         static std::set<User::Ptr> GetServiceNotificationUsers(const Service::Ptr& service);
117         static std::set<UserGroup::Ptr> GetServiceNotificationUserGroups(const Service::Ptr& service);
118
119         /* command */
120         static String GetCommandLine(const Command::Ptr& command);
121
122         /* custom attribute */
123         static String GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name);
124         static Dictionary::Ptr GetCustomAttributeConfig(const DynamicObject::Ptr& object);
125
126         /* check result */
127         static String GetCheckResultOutput(const CheckResult::Ptr& cr);
128         static String GetCheckResultLongOutput(const CheckResult::Ptr& cr);
129         static String GetCheckResultPerfdata(const CheckResult::Ptr& cr);
130
131         /* misc */
132         static std::pair<unsigned long, unsigned long> ConvertTimestamp(double time);
133
134         static int MapNotificationReasonType(NotificationType type);
135         static int MapExternalCommandType(const String& name);
136
137         static String EscapeString(const String& str);
138
139 private:
140         CompatUtility(void);
141 };
142
143 }
144
145 #endif /* COMPATUTILITY_H */