]> granicus.if.org Git - icinga2/blob - plugins/thresholds.h
Add Windows plugins
[icinga2] / plugins / thresholds.h
1 #ifndef THRESHOLDS_H
2 #define THRESHOLDS_H
3 #include <string>
4
5 enum Bunit { BunitB = 0, BunitkB = 1, BunitMB = 2, BunitGB = 3, BunitTB = 4 };
6 enum Tunit { TunitMS, TunitS, TunitM, TunitH };
7 enum state { OK = 0, WARNING = 1, CRITICAL = 2 };
8
9 class threshold
10 {
11 public:
12         double lower, upper;
13         //TRUE means everything BELOW upper/outside [lower-upper] is fine
14         bool legal, perc, set;
15
16         threshold(bool l = true)
17                 : set(false), legal(l) {}
18
19         threshold(const double v, const double c, bool l = true, bool p = false)
20                 : lower(v), upper(c), legal(l), perc(p), set(true) {}
21
22         //return TRUE if the threshold is broken
23         bool rend(const double b)
24         {
25                 if (!set)
26                         return set;
27                 if (lower == upper)
28                         return b > upper == legal;
29                 else
30                         return (b < lower || upper < b) != legal;
31         }
32
33         //returns a printable string of the threshold
34         std::wstring pString()
35         {
36                 if (!set)
37                         return L"0";
38
39                 std::wstring s;
40                 if (!legal)
41                         s.append(L"!");
42
43                 if (lower != upper) {
44                         if (perc)
45                                 s.append(L"[").append(std::to_wstring(lower)).append(L"%").append(L"-")
46                                 .append(std::to_wstring(upper)).append(L"%").append(L"]");
47                         else
48                                 s.append(L"[").append(std::to_wstring(lower)).append(L"-")
49                                 .append(std::to_wstring(upper)).append(L"]");
50                 } else {
51                         if (perc)
52                                 s = std::to_wstring(lower).append(L"%");
53                         else
54                                 s = std::to_wstring(lower);
55                 }
56                 return s;
57         }
58 };
59
60 threshold parse(const std::wstring&);
61 Bunit parseBUnit(const wchar_t *);
62 std::wstring BunitStr(const Bunit&);
63 Tunit parseTUnit(const wchar_t *);
64 std::wstring TunitStr(const Tunit&);
65 #endif