1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.miloss.fgsms.sla.rules;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.concurrent.atomic.AtomicReference;
26 import org.miloss.fgsms.common.Utility;
27 import org.miloss.fgsms.plugins.sla.SLARuleInterface;
28 import org.miloss.fgsms.services.interfaces.common.MachinePerformanceData;
29 import org.miloss.fgsms.services.interfaces.common.NameValuePair;
30 import org.miloss.fgsms.services.interfaces.common.PolicyType;
31 import org.miloss.fgsms.services.interfaces.common.ProcessPerformanceData;
32 import org.miloss.fgsms.services.interfaces.datacollector.AddDataRequestMsg;
33 import org.miloss.fgsms.services.interfaces.datacollector.BrokerData;
34 import org.miloss.fgsms.services.interfaces.policyconfiguration.MachinePolicy;
35 import org.miloss.fgsms.services.interfaces.policyconfiguration.ServicePolicy;
36 import org.miloss.fgsms.services.interfaces.status.SetStatusRequestMsg;
37 import org.miloss.fgsms.sla.NonTransactionalSLAProcessor;
38
39
40
41
42
43 public class HighNetworkUsageOverTime implements SLARuleInterface {
44
45 @Override
46 public boolean CheckTransactionalRule(SetStatusRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
47 return false;
48 }
49
50 @Override
51 public boolean CheckTransactionalRule(ProcessPerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
52 return false;
53 }
54
55 @Override
56 public boolean CheckTransactionalRule(MachinePerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
57 return false;
58 }
59
60 @Override
61 public boolean CheckTransactionalRule(AddDataRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
62 return false;
63 }
64
65 @Override
66 public boolean CheckTransactionalRule(String url, List<BrokerData> data, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
67 return false;
68 }
69
70 @Override
71 public boolean CheckNonTransactionalRule(ServicePolicy pol, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg, boolean pooled) {
72 if (nullableFaultMsg == null) {
73 nullableFaultMsg = new AtomicReference<String>();
74 }
75 NameValuePair GetNameValuePairByName = Utility.getNameValuePairByName(params, "value");
76 long rate = Long.parseLong(GetNameValuePairByName.getValue());
77 GetNameValuePairByName = Utility.getNameValuePairByName(params, "duration");
78 long duration = Long.parseLong(GetNameValuePairByName.getValue());
79 long faultrate = NonTransactionalSLAProcessor.GetDiskUsageOverTime(pol.getURL(), duration, pooled);
80 if (faultrate > rate) {
81 nullableFaultMsg.set("The measured Disk I/O rate, " + faultrate + " is greater than " + rate + ", " + nullableFaultMsg.get());
82 return true;
83 }
84 return false;
85 }
86
87 @Override
88 public String GetDisplayName() {
89 return "High Disk I/O Rates";
90 }
91
92 @Override
93 public String GetHtmlFormattedHelp() {
94 return "This rule will trigger when the Network I/O utilization rate is greater than the specified value for the specified duration."
95 + "This rule is processed periodically as part of the Non-Transactional SLA Processor, who execution cycle is controled by the administrator. "
96 + "This rule applies to Machine policies.<br><br>"
97 + "Required parameters:"
98 + "<ul>"
99 + "<li>value - must be a positive integer. This is the threshold in KB</li>"
100 + "<li>duration - must be a positive integer or long. This represents time in milliseconds for the duration. It must be one of the values from which"
101 + "statistics are aggregated. By default, the following durations are calculated 5 minutes (300000ms), 15 minutes (900000ms), 1 hour (3600000ms),"
102 + "and 24 hours (1440000ms). Administrators can add additional time periods for aggregation via General Settings."
103 + "</il>"
104 + "</ul>";
105 }
106
107 @Override
108 public List<NameValuePair> GetRequiredParameters() {
109 ArrayList<NameValuePair> arrayList = new ArrayList<NameValuePair>();
110 arrayList.add(Utility.newNameValuePair("value", null, false, false));
111 arrayList.add(Utility.newNameValuePair("duration", null, false, false));
112
113 return arrayList;
114 }
115
116 @Override
117 public List<NameValuePair> GetOptionalParameters() {
118 return new ArrayList<NameValuePair>();
119 }
120
121 @Override
122 public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError,ServicePolicy policy) {
123 if (outError == null) {
124 outError = new AtomicReference<String>();
125 }
126 if (params == null || params.isEmpty()) {
127 outError.set("The parameter 'value' is required. " + outError.get());
128 }
129 if (!(policy instanceof MachinePolicy)) {
130 outError.set("This rule only applies to Machine Policies. " + outError.get());
131 }
132 boolean foundLogger = false;
133 boolean foundduration = false;
134 for (int i = 0; i < params.size(); i++) {
135 if (params.get(i).getName().equals("value")) {
136 foundLogger = true;
137 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
138 outError.set("A value must be specified for the parameter 'value'. " + outError.get());
139 }
140 try {
141 long x = Long.parseLong(params.get(i).getValue());
142 if (x <= 0) {
143 outError.set("The parameter 'value' must be greater than zero. " + outError.get());
144 }
145 } catch (Exception ex) {
146 outError.set("Bad value for parameter 'value'. It must be an integer or long. Message:" + ex.getMessage() + ". " + outError.get());
147 }
148 }
149 if (params.get(i).getName().equals("duration")) {
150 foundduration = true;
151 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
152 outError.set("A value must be specified for the parameter 'duration'. " + outError.get());
153 }
154 try {
155 long x = Long.parseLong(params.get(i).getValue());
156 if (x <= 0) {
157 outError.set("The parameter 'duration' must be greater than zero. " + outError.get());
158 }
159 } catch (Exception ex) {
160 outError.set("Bad value for parameter 'duration'. It must be an integer or long. Message:" + ex.getMessage() + ". " + outError.get());
161 }
162 }
163 }
164 if (!foundLogger) {
165 outError.set("The parameter 'value' is required. " + outError.get());
166 }
167 if (!foundduration) {
168 outError.set("The parameter 'duration' is required. " + outError.get());
169 }
170 if (Utility.stringIsNullOrEmpty(outError.get())) {
171 return true;
172 } else {
173 return false;
174 }
175 }
176
177 @Override
178 public org.miloss.fgsms.plugins.sla.AlertType GetType() {
179 return org.miloss.fgsms.plugins.sla.AlertType.Performance;
180 }
181
182 @Override
183 public String GetHtmlFormattedDisplay(List<NameValuePair> params) {
184 NameValuePair mc = Utility.getNameValuePairByName(params, "value");
185 String item = UNDEFINED_VALUE;
186 if (mc != null) {
187 item = mc.getValue();
188 if (mc.isEncrypted() || mc.isEncryptOnSave()) {
189 item = ENCRYPTED_MASK;
190 }
191 }
192
193 NameValuePair mc2 = Utility.getNameValuePairByName(params, "duration");
194 String item2 = UNDEFINED_VALUE;
195 if (mc2 != null) {
196 item2 = mc2.getValue();
197 if (mc2.isEncrypted() || mc2.isEncryptOnSave()) {
198 item2 = ENCRYPTED_MASK;
199 }
200 }
201 return Utility.encodeHTML(GetDisplayName() + " " + item + "/" + item2+"ms");
202 }
203
204 @Override
205 public List<PolicyType> GetAppliesTo() {
206 List<PolicyType> x = new ArrayList<PolicyType>();
207 x.add(PolicyType.MACHINE);
208
209
210 return x;
211 }
212 }