]> granicus.if.org Git - icinga2/blob - plugins/thresholds.hpp
Merge pull request #6313 from Icinga/fix/win-check-swap
[icinga2] / plugins / thresholds.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
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 THRESHOLDS_H
21 #define THRESHOLDS_H
22
23 #include <string>
24 #include <vector>
25 #include <windows.h>
26
27 enum Bunit
28 {
29         BunitB = 0, BunitkB = 1, BunitMB = 2, BunitGB = 3, BunitTB = 4
30 };
31
32 enum Tunit
33 {
34         TunitMS, TunitS, TunitM, TunitH
35 };
36
37 enum state
38 {
39         OK = 0, WARNING = 1, CRITICAL = 2
40 };
41
42 class threshold
43 {
44 public:
45         // doubles are always enough for ANY 64 bit value
46         double lower;
47         double upper;
48         // true means everything BELOW upper/outside [lower-upper] is fine
49         bool legal;
50         bool perc;
51         bool set;
52
53         threshold();
54
55         threshold(const double v, const double c, bool l = true, bool p = false);
56
57         threshold(const std::wstring&);
58
59         // returns true if the threshold is broken
60         bool rend(const double val, const double max = 100.0);
61
62         // returns a printable string of the threshold
63         std::wstring pString(const double max = 100.0);
64
65         threshold toSeconds(const Tunit& fromUnit);
66 };
67
68 std::wstring removeZero(double);
69 std::vector<std::wstring> splitMultiOptions(const std::wstring&);
70
71 Bunit parseBUnit(const std::wstring&);
72 std::wstring BunitStr(const Bunit&);
73 Tunit parseTUnit(const std::wstring&);
74 std::wstring TunitStr(const Tunit&);
75
76 void printErrorInfo(unsigned long err = 0);
77 std::wstring formatErrorInfo(unsigned long err);
78
79 #endif /* THRESHOLDS_H */