Rev 48 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 48 | Rev 52 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php /* <ViaThinkSoftSignature> |
1 | <?php /* <ViaThinkSoftSignature> |
2 | XdQ9Y3ujgj7pXb9l4iNXGDCzSSPfkX4MJWEcWF3KcYbnzlLwYooi73hdid4ffOGqT |
2 | Wg+EYgkO45tkUYzHp3wFsbyVVQadb07ttd04MjjH7C7i7UygR0ZiFQfpqQ5pc6i6M |
3 | CR732fR/PWWQhWVXxtUPeEyf23Y5iROC6mLGr5bMyPwuOCMXyqjdYsUjGEYTRuWAi |
3 | bd+RpyfWYxeMRU8KLRO/I2CymXtB/L11tisWnZRRVSBBsoVr73xZFIDrZiMC+Amxs |
4 | 7deUSHC8pz2U4NJFf5ochQhcnoNS6CIR4WnwfhUwjp2s/5qC5gnIjpx08dkpwV/YF |
4 | /WqnIRJIVCCniLDPPzp+WlIq7/e8djQukSglqSsL4Dhvk37k7iWJuAkyoFodffOVQ |
5 | TcT9gNlDkkefu/HIiju9BpYbT2C6+VPue3qDXRyFdTxv1/7L9ohhpVRSkjzh1kNCi |
5 | FHLvcfvw/yjzSvLzE/3kAOToZ7OmNBfVhJKcUOYouYINCrxrqvY7FfOWz/GftnHkV |
6 | 8lmtud+Anvc1+9jAxwwBDuTcJdvkYiWucEml1CYUMPF29ipb0Itqm6wfE9TYDgD1E |
6 | 5vjYJrTaoKpYW3N4Xoi0HBVfzTKQjND4ihulrkV4p6PhHdbdD5dXNaXUERgjAqeED |
7 | rsYxXn5SE0rIjZwDhjtmM8j7iZdNP56zoyS6NdoZ7iYYhSaWwc8hbPBo8Uvhhh3CE |
7 | tvpQzPHqA25Q74llkjFDeyNFHkEMKmiqdVbO/LcWHetROqMRu2on6Eghy7BCgqsfD |
8 | 1fsBeh6bn7Ob4fVMU3WzHwD6D7h0/EvQi/ZD9OxtG0DIGsT5ad/b0Zcl0pmpqRols |
8 |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I1UO85pFY8g31WLNM6mexOd6sCu7KW6MYkT1p34QW9inyrymKb8KV9Hji |
16 | QE9XHcjudqlECrbApzMmRzCBb2MVRnuIgaMZ6dizCPWJl/bkuqCjizMV2TbLLUnIx |
17 | r2vVa/Tzg7qTnohDNUZ5fY8kZ1tRNIt7QTe0eCg1BIK2/Rgpnmo+ULyC6KMAu6TgU |
17 | /fRb2YX98uPNsdWRTt8kZJit6QmwPi6YKJO3YKZUkaCtaM7mwjVZ0g/ZNkX2VBZ8k |
18 | i6pXkNaN3JRAgKfJlUcyo0mnLaHUGZ+hqSL3M0gYwuqVnpVeVdyr1AyN1RDBB2aTq |
18 | OW0JumHLXOcbQLCi6dVjsyp4fsEXmiQYLksGQtyhDtGVj/MVDz0MZMJosClcqjfCa |
19 | EOu7KMdKFcQo9aZPM91RmOQ1WsV7QFIyxbzs/Mjq6fIbLPp8qeSxKk7MoMzlmsREy |
19 | M3DD8exxuvwFLIj9+y52IZKxOlsW/fB/fQiBmay/OOsyYHGMfVEpFZNnOMweB13xR |
20 | Xcf4uMTiJOg7WRSsRMNy2vmDXjczYfXi2Ak+oG9M6n4gHy8UqQ4IjamqBOFPkqAFu |
20 | SpB8NaUON7MUCKwG1PfdmQcMZpwA01QREkVW4/u75qPr3OoyyeJ3/zYJhJXSv3md6 |
21 | kp300s3yEdmMowo02L5B69ct7AcSVZgKeiO1xVYUGywdX/wLzEVqzaeJqA2fVz8wy |
21 | V6V53FLy2SG13eHajqVQDLrYDqu56V/GL/tI4JLIoFhKr2gzj2lFJFGyr4peCipRD |
22 | pjNw5bJ6SmecLG4fb1qMndOywS1XRUoNL7goRC8MVC/nRyo2GZrU707JKlX1S5eFD |
22 | ijdZWqbFUcDFJS8c0lJ1P68D1ATEB0m92CDen1ttVUCOUO5CK0+Qc5MbKCTXlr2OY |
23 | g== |
23 | A== |
24 | </ViaThinkSoftSignature> */ ?> |
24 | </ViaThinkSoftSignature> */ ?> |
25 | <?php |
25 | <?php |
26 | 26 | ||
27 | /* |
27 | /* |
28 | 28 | ||
Line 33... | Line 33... | ||
33 | \ V / | | (_| || | | | | | | | | | < ___) | (_) | _| |_ |
33 | \ V / | | (_| || | | | | | | | | | < ___) | (_) | _| |_ |
34 | \_/ |_|\__,_||_| |_| |_|_|_| |_|_|\_\|____/ \___/|_| \__| |
34 | \_/ |_|\__,_||_| |_| |_|_|_| |_|_|\_\|____/ \___/|_| \__| |
35 | 35 | ||
36 | Developed by Daniel Marschall www.viathinksoft.com |
36 | Developed by Daniel Marschall www.viathinksoft.com |
37 | Licensed under the terms of the Apache 2.0 license |
37 | Licensed under the terms of the Apache 2.0 license |
38 | Revision 2022-04-09 |
38 | Revision 2022-06-06 |
39 | 39 | ||
40 | */ |
40 | */ |
41 | 41 | ||
42 | /**************************************************************************************************** |
42 | /**************************************************************************************************** |
43 | 43 | ||
Line 345... | Line 345... | ||
345 | // Returns true for '' or null. Does not return true for value 0 or '0' (like empty() does) |
345 | // Returns true for '' or null. Does not return true for value 0 or '0' (like empty() does) |
346 | return trim($x) == ''; |
346 | return trim($x) == ''; |
347 | } |
347 | } |
348 | 348 | ||
349 | abstract class VNag { |
349 | abstract class VNag { |
350 | /*public*/ const VNAG_VERSION = '2022-04-09'; |
350 | /*public*/ const VNAG_VERSION = '2022-06-06'; |
351 | 351 | ||
352 | // Status 0..3 for STATUSMODEL_SERVICE (the default status model): |
352 | // Status 0..3 for STATUSMODEL_SERVICE (the default status model): |
353 | # The guideline states: "Higher-level errors (such as name resolution errors, socket timeouts, etc) are outside of the control of plugins and should generally NOT be reported as UNKNOWN states." |
353 | # The guideline states: "Higher-level errors (such as name resolution errors, socket timeouts, etc) are outside of the control of plugins and should generally NOT be reported as UNKNOWN states." |
354 | # We choose 4 as exitcode. The plugin developer is free to return any other status. |
354 | # We choose 4 as exitcode. The plugin developer is free to return any other status. |
355 | /*public*/ const STATUS_OK = 0; |
355 | /*public*/ const STATUS_OK = 0; |
Line 1725... | Line 1725... | ||
1725 | 1725 | ||
1726 | class VNagRange { |
1726 | class VNagRange { |
1727 | // see https://nagios-plugins.org/doc/guidelines.html#THRESHOLDFORMAT |
1727 | // see https://nagios-plugins.org/doc/guidelines.html#THRESHOLDFORMAT |
1728 | // We allow UOMs inside the range definition, e.g. "-w @10M:50M" |
1728 | // We allow UOMs inside the range definition, e.g. "-w @10M:50M" |
1729 | 1729 | ||
1730 | public /*VNagValueUomPair|'inf'*/ $start; |
1730 | public /*VNagValueUomPair|'-inf'*/ $start; |
1731 | public /*VNagValueUomPair|'inf'*/ $end; |
1731 | public /*VNagValueUomPair|'inf'*/ $end; |
1732 | public /*boolean*/ $warnInsideRange; |
1732 | public /*boolean*/ $warnInsideRange; |
1733 | 1733 | ||
1734 | public function __construct($rangeDef, $singleValueBehavior=VNag::SINGLEVALUE_RANGE_DEFAULT) { |
1734 | public function __construct($rangeDef, $singleValueBehavior=VNag::SINGLEVALUE_RANGE_DEFAULT) { |
1735 | $m = array(); |
1735 | $m = array(); |
Line 1743... | Line 1743... | ||
1743 | $this->start = null; |
1743 | $this->start = null; |
1744 | $this->end = null; |
1744 | $this->end = null; |
1745 | 1745 | ||
1746 | if ($m[3] === ':') { |
1746 | if ($m[3] === ':') { |
1747 | if ($m[2] === '~') { |
1747 | if ($m[2] === '~') { |
1748 | $this->start = 'inf'; |
1748 | $this->start = '-inf'; |
1749 | } else { |
1749 | } else { |
1750 | $this->start = new VNagValueUomPair($m[2]); |
1750 | $this->start = new VNagValueUomPair($m[2]); |
1751 | } |
1751 | } |
1752 | 1752 | ||
1753 | if (_empty($m[4])) { |
1753 | if (_empty($m[4])) { |
Line 1761... | Line 1761... | ||
1761 | 1761 | ||
1762 | $x = $m[2]; |
1762 | $x = $m[2]; |
1763 | 1763 | ||
1764 | if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_DEFAULT) { |
1764 | if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_DEFAULT) { |
1765 | // Default behavior according to the development guidelines: |
1765 | // Default behavior according to the development guidelines: |
1766 | // x means x:x, which means, everything except x% is bad. |
1766 | // x means 0:x, which means, x>10 is bad |
1767 | // @x means @x:x, which means, x is bad and everything else is good. |
1767 | // @x means @0:x, which means, x<=10 is bad |
1768 | $this->start = new VNagValueUomPair($x); |
1768 | $this->start = new VNagValueUomPair('0'.((new VNagValueUomPair($x))->getUom())); |
1769 | $this->end = new VNagValueUomPair($x); |
1769 | $this->end = new VNagValueUomPair($x); |
1770 | } else if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_VAL_GT_X_BAD) { |
1770 | } else if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_VAL_GT_X_BAD) { |
1771 | // The single value x means, everything > x is bad. @x is not defined. |
1771 | // The single value x means, everything > x is bad. @x is not defined. |
1772 | if ($this->warnInsideRange) throw new VNagInvalidRangeException(VNagLang::$singlevalue_unexpected_at_symbol); |
1772 | if ($this->warnInsideRange) throw new VNagInvalidRangeException(VNagLang::$singlevalue_unexpected_at_symbol); |
1773 | $this->warnInsideRange = 0; |
1773 | $this->warnInsideRange = 0; |
1774 | $this->start = 'inf'; |
1774 | $this->start = '-inf'; |
1775 | $this->end = new VNagValueUomPair($x); |
1775 | $this->end = new VNagValueUomPair($x); |
1776 | } else if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_VAL_GE_X_BAD) { |
1776 | } else if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_VAL_GE_X_BAD) { |
1777 | // The single value x means, everything >= x is bad. @x is not defined. |
1777 | // The single value x means, everything >= x is bad. @x is not defined. |
1778 | if ($this->warnInsideRange) throw new VNagInvalidRangeException(VNagLang::$singlevalue_unexpected_at_symbol); |
1778 | if ($this->warnInsideRange) throw new VNagInvalidRangeException(VNagLang::$singlevalue_unexpected_at_symbol); |
1779 | $this->warnInsideRange = 1; |
1779 | $this->warnInsideRange = 1; |
Line 1787... | Line 1787... | ||
1787 | $this->end = 'inf'; |
1787 | $this->end = 'inf'; |
1788 | } else if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_VAL_LE_X_BAD) { |
1788 | } else if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_VAL_LE_X_BAD) { |
1789 | // The single value x means, everything <= x is bad. @x is not defined. |
1789 | // The single value x means, everything <= x is bad. @x is not defined. |
1790 | if ($this->warnInsideRange) throw new VNagInvalidRangeException(VNagLang::$singlevalue_unexpected_at_symbol); |
1790 | if ($this->warnInsideRange) throw new VNagInvalidRangeException(VNagLang::$singlevalue_unexpected_at_symbol); |
1791 | $this->warnInsideRange = 1; |
1791 | $this->warnInsideRange = 1; |
1792 | $this->start = 'inf'; |
1792 | $this->start = '-inf'; |
1793 | $this->end = new VNagValueUomPair($x); |
1793 | $this->end = new VNagValueUomPair($x); |
1794 | } else { |
1794 | } else { |
1795 | throw new VNagException(VNagLang::$illegalSingleValueBehavior); |
1795 | throw new VNagException(VNagLang::$illegalSingleValueBehavior); |
1796 | } |
1796 | } |
1797 | } |
1797 | } |
Line 1817... | Line 1817... | ||
1817 | $ret = ''; |
1817 | $ret = ''; |
1818 | if ($this->warnInsideRange) { |
1818 | if ($this->warnInsideRange) { |
1819 | $ret = '@'; |
1819 | $ret = '@'; |
1820 | } |
1820 | } |
1821 | 1821 | ||
1822 | if ($this->start === 'inf') { |
1822 | if ($this->start === '-inf') { |
1823 | $ret .= '~'; |
1823 | $ret .= '~'; |
1824 | } else { |
1824 | } else { |
1825 | $ret .= $this->start; |
1825 | $ret .= $this->start; |
1826 | } |
1826 | } |
1827 | 1827 | ||
Line 1839... | Line 1839... | ||
1839 | 1839 | ||
1840 | if (!is_array($values)) $values = array($values); |
1840 | if (!is_array($values)) $values = array($values); |
1841 | foreach ($values as $value) { |
1841 | foreach ($values as $value) { |
1842 | if (!($value instanceof VNagValueUomPair)) $value = new VNagValueUomPair($value); |
1842 | if (!($value instanceof VNagValueUomPair)) $value = new VNagValueUomPair($value); |
1843 | 1843 | ||
1844 | assert(($this->start === 'inf') || ($this->start instanceof VNagValueUomPair)); |
1844 | assert(($this->start === '-inf') || ($this->start instanceof VNagValueUomPair)); |
1845 | assert(($this->end === 'inf') || ($this->end instanceof VNagValueUomPair)); |
1845 | assert(($this->end === 'inf' ) || ($this->end instanceof VNagValueUomPair)); |
1846 | 1846 | ||
1847 | if (($this->start !== 'inf') && (!$this->start->compatibleWith($value))) continue; |
1847 | if (($this->start !== '-inf') && (!$this->start->compatibleWith($value))) continue; |
1848 | if (($this->end !== 'inf') && (!$this->end->compatibleWith($value))) continue; |
1848 | if (($this->end !== 'inf') && (!$this->end->compatibleWith($value))) continue; |
1849 | $compatibleCount++; |
1849 | $compatibleCount++; |
1850 | 1850 | ||
1851 | if ($this->warnInsideRange) { |
1851 | if ($this->warnInsideRange) { |
1852 | return (($this->start === 'inf') || (VNagValueUomPair::compare($value,$this->start) >= 0)) && |
1852 | return (($this->start === '-inf') || (VNagValueUomPair::compare($value,$this->start) >= 0)) && |
1853 | (($this->end === 'inf') || (VNagValueUomPair::compare($value,$this->end) <= 0)); |
1853 | (($this->end === 'inf') || (VNagValueUomPair::compare($value,$this->end) <= 0)); |
1854 | } else { |
1854 | } else { |
1855 | return (($this->start !== 'inf') && (VNagValueUomPair::compare($value,$this->start) < 0)) || |
1855 | return (($this->start !== '-inf') && (VNagValueUomPair::compare($value,$this->start) < 0)) || |
1856 | (($this->end !== 'inf') && (VNagValueUomPair::compare($value,$this->end) > 0)); |
1856 | (($this->end !== 'inf') && (VNagValueUomPair::compare($value,$this->end) > 0)); |
1857 | } |
1857 | } |
1858 | } |
1858 | } |
1859 | 1859 | ||
1860 | if ((count($values) > 0) and ($compatibleCount == 0)) { |
1860 | if ((count($values) > 0) and ($compatibleCount == 0)) { |
Line 1961... | Line 1961... | ||
1961 | $res->uom = 'B'; |
1961 | $res->uom = 'B'; |
1962 | $res->value *= 1024 * 1024; |
1962 | $res->value *= 1024 * 1024; |
1963 | } else if ($target == 'KB') { |
1963 | } else if ($target == 'KB') { |
1964 | $res->uom = 'KB'; |
1964 | $res->uom = 'KB'; |
1965 | $res->value *= 1024; |
1965 | $res->value *= 1024; |
- | 1966 | } else if ($target == 'MB') { |
|
- | 1967 | $res->uom = 'MB'; |
|
- | 1968 | $res->value *= 1; |
|
1966 | } else if ($target == 'GB') { |
1969 | } else if ($target == 'GB') { |
1967 | $res->uom = 'GB'; |
1970 | $res->uom = 'GB'; |
1968 | $res->value /= 1024; |
1971 | $res->value /= 1024; |
1969 | } else if ($target == 'TB') { |
1972 | } else if ($target == 'TB') { |
1970 | $res->uom = 'TB'; |
1973 | $res->uom = 'TB'; |
1971 | $res->value /= 1024 * 1024; |
1974 | $res->value /= 1024 * 1024; |
1972 | } else { |
1975 | } else { |
1973 | throw new VNagUomConvertException($res->uom, $target); |
1976 | throw new VNagUomConvertException($res->uom, $target); |
1974 | } |
1977 | } |
1975 | } else if ($res->uom == 's') { |
1978 | } else if ($res->uom == 's') { |
1976 | if ($target == 'ms') { |
1979 | if ($target == 's') { |
- | 1980 | $res->uom = 's'; |
|
- | 1981 | $res->value /= 1; |
|
- | 1982 | } else if ($target == 'ms') { |
|
1977 | $res->uom = 'ms'; |
1983 | $res->uom = 'ms'; |
1978 | $res->value /= 1000; |
1984 | $res->value /= 1000; |
1979 | } else if ($target == 'us') { |
1985 | } else if ($target == 'us') { |
1980 | $res->uom = 'us'; |
1986 | $res->uom = 'us'; |
1981 | $res->value /= 1000 * 1000; |
1987 | $res->value /= 1000 * 1000; |