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;
17
18 /**
19 * Enumeration of all the supported status.
20 *
21 * @author Massimiliano Ziccardi
22 */
23 public enum Status {
24 /**
25 * Service status 'OK'.
26 */
27 OK(0, 0),
28 /**
29 * Service status 'WARNING'.
30 */
31 WARNING(1, 2),
32 /**
33 * Service status 'CRITICAL'.
34 */
35 CRITICAL(2, 3),
36 /**
37 * Service status 'UNKNOWN'.
38 */
39 UNKNOWN(3, 1);
40
41 /**
42 * Integer constant for the OK status.
43 */
44 private static final int OK_STATUS = 0;
45 /**
46 * Integer constant for the WARNING status.
47 */
48 private static final int WARNING_STATUS = 1;
49 /**
50 * Integer constant for the CRITICAL status.
51 */
52 private static final int CRITICAL_STATUS = 2;
53 /**
54 * Integer constant for the UNKNOWN status.
55 */
56 private static final int UNKNOWN_STATUS = 3;
57
58 /**
59 * The enumeration int value.
60 */
61 private final int intValue;
62
63 /**
64 * The serverity value.
65 */
66 private final int severityValue;
67
68 /**
69 * Builds an enumeration with the given int value.
70 *
71 * @param iValue
72 * The value
73 * @param severity
74 * The severity of the status
75 */
76 Status(final int iValue, final int severity) {
77 intValue = iValue;
78 severityValue = severity;
79 }
80
81 /**
82 * Returns the int value of the enum.
83 *
84 * @return The int value
85 */
86 public int intValue() {
87 return intValue;
88 }
89
90 /**
91 * Returns the enum corresponding with the given int value.
92 *
93 * @param intValue
94 * The int value to be converted
95 * @return A {@link Status} enum. Null if not found
96 */
97 public static Status fromIntValue(final int intValue) {
98 switch (intValue) {
99 case OK_STATUS:
100 return OK;
101 case WARNING_STATUS:
102 return WARNING;
103 case CRITICAL_STATUS:
104 return CRITICAL;
105 case UNKNOWN_STATUS:
106 default:
107 return UNKNOWN;
108 }
109 }
110
111 /**
112 * @return The severity as an int value (higher is more severe)
113 */
114 public int getSeverity() {
115 return severityValue;
116 }
117 }