1 /*******************************************************************************
2 * Copyright (c) 2007, 2014 Massimiliano Ziccardi
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 package it.jnrpe.utils;
17
18 import it.jnrpe.utils.thresholds.LegacyRange;
19
20 import java.math.BigDecimal;
21
22 /**
23 * Utility class for evaluating threshold This class conforms to the nagios
24 * plugin guidelines
25 * (http://nagiosplug.sourceforge.net/developer-guidelines.html
26 * #THRESHOLDFORMAT). The generalised range format is: [@]start:end Values are
27 * interpreted this way:
28 * <ul>
29 * <li>if range is of format "start:" and end is not specified, assume end is
30 * infinity
31 * <li>to specify negative infinity, use "~"
32 * <li>alert is raised if metric is outside start and end range (inclusive of
33 * endpoints)
34 * <li>if range starts with "@", then alert if inside this range (inclusive of
35 * endpoints)
36 * </ul>
37 * start and ":" is not required if start=0.
38 *
39 * @author Massimiliano Ziccardi
40 * @deprecated Use the {@link it.jnrpe.utils.thresholds.ReturnValueBuilder}
41 * together with the
42 * {@link it.jnrpe.utils.thresholds.ThresholdsEvaluatorBuilder} instead.
43 */
44 @Deprecated
45 public final class ThresholdUtil {
46 /**
47 * Private default constructor to avoid instantiation.
48 */
49 private ThresholdUtil() {
50
51 }
52
53 /**
54 * Returns <code>true</code> if the value <code>iValue</code> falls into the
55 * range <code>sRange</code>.
56 *
57 * @param thresholdString
58 * The range
59 * @param value
60 * The value
61 * @return <code>true</code> if the value <code>iValue</code> falls into the
62 * @throws BadThresholdException
63 * -
64 */
65 public static boolean isValueInRange(final String thresholdString,
66 final int value) throws BadThresholdException {
67 return new LegacyRange(thresholdString).isValueInside(value);
68 }
69
70 /**
71 * Returns <code>true</code> if the value <code>dalue</code> falls into the
72 * range <code>sRange</code>.
73 *
74 * @param thresholdString
75 * The range
76 * @param value
77 * The value given range
78 * @return <code>true</code> if the given value falls inside the given range
79 * @throws BadThresholdException
80 * -
81 */
82 public static boolean isValueInRange(final String thresholdString,
83 final BigDecimal value) throws BadThresholdException {
84 return new LegacyRange(thresholdString).isValueInside(value);
85 }
86
87 /**
88 * Returns <code>true</code> if the value <code>dalue</code> falls into the
89 * range <code>sRange</code>.
90 *
91 * @param thresholdString
92 * The range
93 * @param value
94 * The value given range
95 * @return <code>true</code> if the given value falls inside the given range
96 * @throws BadThresholdException
97 * -
98 */
99 public static boolean isValueInRange(final String thresholdString,
100 final Long value) throws BadThresholdException {
101 return new LegacyRange(thresholdString).isValueInside(new BigDecimal(
102 value));
103 }
104 }