1 /*
2 * jcollectd
3 * Copyright (C) 2009 Hyperic, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
19 package org.collectd.api;
21 /**
22 * Java representation of collectd/src/plugin.h:notfication_t structure.
23 */
24 public class Notification extends PluginData {
25 public static final int FAILURE = 1;
26 public static final int WARNING = 2;
27 public static final int OKAY = 4;
29 public static String[] SEVERITY = {
30 "FAILURE",
31 "WARNING",
32 "OKAY",
33 "UNKNOWN"
34 };
36 private int _severity;
37 private String _message;
39 public Notification () {
40 _severity = 0;
41 _message = "Initial notification message";
42 }
44 public Notification (PluginData pd) {
45 super (pd);
46 _severity = 0;
47 _message = "Initial notification message";
48 }
50 public void setSeverity (int severity) {
51 if ((severity == FAILURE)
52 || (severity == WARNING)
53 || (severity == OKAY))
54 this._severity = severity;
55 }
57 public int getSeverity() {
58 return _severity;
59 }
61 public String getSeverityString() {
62 switch (_severity) {
63 case FAILURE:
64 return SEVERITY[0];
65 case WARNING:
66 return SEVERITY[1];
67 case OKAY:
68 return SEVERITY[2];
69 default:
70 return SEVERITY[3];
71 }
72 }
74 public void setMessage (String message) {
75 this._message = message;
76 }
78 public String getMessage() {
79 return _message;
80 }
82 public String toString() {
83 StringBuffer sb = new StringBuffer(super.toString());
84 sb.append(" [").append(getSeverityString()).append("] ");
85 sb.append(_message);
86 return sb.toString();
87 }
88 }