]> granicus.if.org Git - icinga2/blob - lib/icinga/compatutility.hpp
Fix missing custom attributes in backends if name is equal to object attribute
[icinga2] / lib / icinga / compatutility.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2015 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.hpp"
24 #include "icinga/customvarobject.hpp"
25 #include "icinga/host.hpp"
26 #include "icinga/command.hpp"
27 #include "base/dictionary.hpp"
28 #include "base/array.hpp"
29 #include <vector>
30
31 namespace icinga
32 {
33
34 /**
35  * Compatibility utility functions.
36  *
37  * @ingroup icinga
38  */
39 class I2_ICINGA_API CompatUtility
40 {
41 public:
42         /* command */
43         static String GetCommandLine(const Command::Ptr& command);
44         static String GetCommandName(const Command::Ptr command);
45
46         /* host */
47         static String GetHostAlias(const Host::Ptr& host);
48         static int GetHostNotifyOnDown(const Host::Ptr& host);
49         static int GetHostNotifyOnUnreachable(const Host::Ptr& host);
50
51         /* service */
52         static String GetCheckableCommandArgs(const Checkable::Ptr& checkable);
53         static int GetCheckableCheckType(const Checkable::Ptr& checkable);
54         static double GetCheckableCheckInterval(const Checkable::Ptr& checkable);
55         static double GetCheckableRetryInterval(const Checkable::Ptr& checkable);
56         static String GetCheckableCheckPeriod(const Checkable::Ptr& checkable);
57         static int GetCheckableHasBeenChecked(const Checkable::Ptr& checkable);
58         static int GetCheckableProblemHasBeenAcknowledged(const Checkable::Ptr& checkable);
59         static int GetCheckableAcknowledgementType(const Checkable::Ptr& checkable);
60         static int GetCheckablePassiveChecksEnabled(const Checkable::Ptr& checkable);
61         static int GetCheckableActiveChecksEnabled(const Checkable::Ptr& checkable);
62         static int GetCheckableEventHandlerEnabled(const Checkable::Ptr& checkable);
63         static int GetCheckableFlapDetectionEnabled(const Checkable::Ptr& checkable);
64         static int GetCheckableIsFlapping(const Checkable::Ptr& checkable);
65         static int GetCheckableIsReachable(const Checkable::Ptr& checkable);
66         static double GetCheckablePercentStateChange(const Checkable::Ptr& checkable);
67         static int GetCheckableProcessPerformanceData(const Checkable::Ptr& checkable);
68
69         static String GetCheckableEventHandler(const Checkable::Ptr& checkable);
70         static String GetCheckableCheckCommand(const Checkable::Ptr& checkable);
71
72         static int GetCheckableIsVolatile(const Checkable::Ptr& checkable);
73         static double GetCheckableLowFlapThreshold(const Checkable::Ptr& checkable);
74         static double GetCheckableHighFlapThreshold(const Checkable::Ptr& checkable);
75         static int GetCheckableFreshnessChecksEnabled(const Checkable::Ptr& checkable);
76         static int GetCheckableFreshnessThreshold(const Checkable::Ptr& checkable);
77         static double GetCheckableStaleness(const Checkable::Ptr& checkable);
78         static int GetCheckableIsAcknowledged(const Checkable::Ptr& checkable);
79         static int GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable);
80         static int GetCheckableInCheckPeriod(const Checkable::Ptr& checkable);
81         static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable);
82
83         static Array::Ptr GetModifiedAttributesList(const CustomVarObject::Ptr& object);
84
85         /* notification */
86         static int GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable);
87         static int GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable);
88         static int GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable);
89         static int GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable);
90         static double GetCheckableNotificationNotificationInterval(const Checkable::Ptr& checkable);
91         static String GetCheckableNotificationNotificationPeriod(const Checkable::Ptr& checkable);
92         static String GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable);
93         static int GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable);
94         static int GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable);
95         static int GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable);
96         static int GetCheckableNotifyOnCritical(const Checkable::Ptr& checkable);
97         static int GetCheckableNotifyOnUnknown(const Checkable::Ptr& checkable);
98         static int GetCheckableNotifyOnRecovery(const Checkable::Ptr& checkable);
99         static int GetCheckableNotifyOnFlapping(const Checkable::Ptr& checkable);
100         static int GetCheckableNotifyOnDowntime(const Checkable::Ptr& checkable);
101
102         static std::set<User::Ptr> GetCheckableNotificationUsers(const Checkable::Ptr& checkable);
103         static std::set<UserGroup::Ptr> GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable);
104
105         /* custom attribute */
106         static String GetCustomAttributeConfig(const CustomVarObject::Ptr& object, const String& name);
107         static Dictionary::Ptr GetCustomAttributeConfig(const CustomVarObject::Ptr& object);
108
109         /* check result */
110         static String GetCheckResultOutput(const CheckResult::Ptr& cr);
111         static String GetCheckResultLongOutput(const CheckResult::Ptr& cr);
112         static String GetCheckResultPerfdata(const CheckResult::Ptr& cr);
113
114         /* misc */
115         static std::pair<unsigned long, unsigned long> ConvertTimestamp(double time);
116
117         static int MapNotificationReasonType(NotificationType type);
118         static int MapExternalCommandType(const String& name);
119
120         static String EscapeString(const String& str);
121
122 private:
123         CompatUtility(void);
124
125         static String GetCommandNamePrefix(const Command::Ptr command);
126 };
127
128 }
129
130 #endif /* COMPATUTILITY_H */