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.AlertType;
28 import org.miloss.fgsms.plugins.sla.SLARuleInterface;
29 import org.miloss.fgsms.services.interfaces.common.MachinePerformanceData;
30 import org.miloss.fgsms.services.interfaces.common.NameValuePair;
31 import org.miloss.fgsms.services.interfaces.common.PolicyType;
32 import org.miloss.fgsms.services.interfaces.common.ProcessPerformanceData;
33 import org.miloss.fgsms.services.interfaces.datacollector.AddDataRequestMsg;
34 import org.miloss.fgsms.services.interfaces.datacollector.BrokerData;
35 import org.miloss.fgsms.services.interfaces.policyconfiguration.MachinePolicy;
36 import org.miloss.fgsms.services.interfaces.policyconfiguration.ProcessPolicy;
37 import org.miloss.fgsms.services.interfaces.policyconfiguration.ServicePolicy;
38 import org.miloss.fgsms.services.interfaces.status.SetStatusRequestMsg;
39
40
41
42
43
44 public class HighOpenFileHandles implements SLARuleInterface {
45
46 @Override
47 public boolean CheckTransactionalRule(SetStatusRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
48 return false;
49 }
50
51 @Override
52 public boolean CheckTransactionalRule(ProcessPerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
53 if (nullableFaultMsg != null) {
54 nullableFaultMsg = new AtomicReference<String>();
55 }
56 NameValuePair value = Utility.getNameValuePairByName(params, "value");
57 int x = 0;
58 if (value.isEncrypted()) {
59 x = Integer.parseInt(Utility.DE(value.getValue()));
60 } else {
61 x = Integer.parseInt(value.getValue());
62 }
63 if (x > req.getOpenFileHandles()) {
64 nullableFaultMsg.set("The number of open file handles for a process, " + req.getOpenFileHandles() + " is higher that the threshold value of " + x + ", " + req.getOpenFileHandles());
65 return true;
66 }
67 return false;
68 }
69
70 @Override
71 public boolean CheckTransactionalRule(MachinePerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
72 return false;
73 }
74
75 @Override
76 public boolean CheckTransactionalRule(AddDataRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
77 return false;
78 }
79
80 @Override
81 public boolean CheckTransactionalRule(String url, List<BrokerData> data, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
82 return false;
83 }
84
85 @Override
86 public boolean CheckNonTransactionalRule(ServicePolicy pol, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg, boolean pooled) {
87 return false;
88 }
89
90 @Override
91 public String GetDisplayName() {
92 return "High Open File Handles Count";
93 }
94
95 @Override
96 public String GetHtmlFormattedHelp() {
97 return "This rule will trigger when a process has a high number of open file handles. This applies to process service policies only.<br><br>"
98 + "Required Parameters:"
99 + "<ul>"
100 + "<li>value - some positive integer value representing the threshold such as if the open file count is greater than the value, the rule is triggered.</li>"
101 + "</ul>";
102
103 }
104
105 @Override
106 public List<NameValuePair> GetRequiredParameters() {
107 List<NameValuePair> items = new ArrayList<NameValuePair>();
108 items.add(Utility.newNameValuePair("value", null, false, false));
109 return items;
110 }
111
112 @Override
113 public List<NameValuePair> GetOptionalParameters() {
114 return new ArrayList<NameValuePair>();
115 }
116
117 @Override
118 public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError,ServicePolicy policy) {
119 if (outError == null) {
120 outError = new AtomicReference<String>();
121 }
122 if (params == null || params.isEmpty()) {
123 outError.set("The parameter 'value' is required. " + outError.get());
124 }
125 if (!(policy instanceof ProcessPolicy)) {
126 outError.set("This rule only applies to Process Policies. " + outError.get());
127 }
128 boolean foundSubject = false;
129
130 for (int i = 0; i < params.size(); i++) {
131 if (params.get(i).getName().equals("value")) {
132 foundSubject = true;
133 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
134 outError.set("A value must be specified for the parameter 'value'. " + outError.get());
135 }
136
137 try {
138 int x = -1;
139 if (params.get(i).isEncrypted()) {
140 x = Integer.parseInt(Utility.DE(params.get(i).getValue()));
141 } else {
142 x = Integer.parseInt((params.get(i).getValue()));
143 }
144 if (x < 0) {
145 outError.set("The parameter 'value' must be greater than zero. " + outError.get());
146 }
147 } catch (Exception ex) {
148 outError.set("Could not parse the value of 'value' to an integer. Error: " + ex.getMessage() + ". " + outError.get());
149 }
150 }
151
152 }
153 if (!foundSubject) {
154 outError.set("The parameter 'value' is required. " + outError.get());
155 }
156 if (Utility.stringIsNullOrEmpty(outError.get())) {
157 return true;
158 } else {
159 return false;
160 }
161 }
162
163 @Override
164 public AlertType GetType() {
165 return AlertType.Performance;
166 }
167
168 @Override
169 public String GetHtmlFormattedDisplay(List<NameValuePair> params) {
170 NameValuePair mc = Utility.getNameValuePairByName(params, "value");
171 String item = UNDEFINED_VALUE;
172 if (mc != null) {
173 item = mc.getValue();
174 if (mc.isEncrypted() || mc.isEncryptOnSave()) {
175 item = ENCRYPTED_MASK;
176 }
177 }
178
179
180 return Utility.encodeHTML(GetDisplayName() + " " + item);
181 }
182
183 @Override
184 public List<PolicyType> GetAppliesTo() {
185 List<PolicyType> x = new ArrayList<PolicyType>();
186 x.add(PolicyType.MACHINE);
187 x.add(PolicyType.PROCESS);
188 return x;
189 }
190 }