cd2fed5824db3477d4d8495e81d50daa01ef1e6f
[collectd.git] / bindings / java / org / collectd / api / Notification.java
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  */
18
19 package org.collectd.api;
20
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;
28
29     public static String[] SEVERITY = {
30         "FAILURE",
31         "WARNING",
32         "OKAY",
33         "UNKNOWN"
34     };
35
36     private int _severity;
37     private String _message;
38
39     public Notification (PluginData pd) {
40         super (pd);
41     }
42
43     public void setSeverity (int severity) {
44         if ((severity == FAILURE)
45                 || (severity == WARNING)
46                 || (severity == OKAY))
47             this._severity = severity;
48     }
49
50     public int getSeverity() {
51         return _severity;
52     }
53
54     public String getSeverityString() {
55         switch (_severity) {
56             case FAILURE:
57                 return SEVERITY[0];
58             case WARNING:
59                 return SEVERITY[1];
60             case OKAY:
61                 return SEVERITY[2];
62             default:
63                 return SEVERITY[3];
64         }
65     }
66
67     public void setMessage (String message) {
68         this._message = message;
69     }
70
71     public String getMessage() {
72         return _message;
73     }
74
75     public String toString() {
76         StringBuffer sb = new StringBuffer(super.toString());
77         sb.append(" [").append(getSeverityString()).append("] ");
78         sb.append(_message);
79         return sb.toString();
80     }
81 }