1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.miloss.fgsms.sla.rules;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.concurrent.atomic.AtomicReference;
27 import org.miloss.fgsms.common.Utility;
28 import org.miloss.fgsms.plugins.sla.AlertType;
29 import org.miloss.fgsms.plugins.sla.SLARuleInterface;
30 import org.miloss.fgsms.services.interfaces.common.MachinePerformanceData;
31 import org.miloss.fgsms.services.interfaces.common.NameValuePair;
32 import org.miloss.fgsms.services.interfaces.common.PolicyType;
33 import org.miloss.fgsms.services.interfaces.common.ProcessPerformanceData;
34 import org.miloss.fgsms.services.interfaces.datacollector.AddDataRequestMsg;
35 import org.miloss.fgsms.services.interfaces.datacollector.BrokerData;
36 import org.miloss.fgsms.services.interfaces.policyconfiguration.ServicePolicy;
37 import org.miloss.fgsms.services.interfaces.policyconfiguration.TransactionalWebServicePolicy;
38 import org.miloss.fgsms.services.interfaces.status.SetStatusRequestMsg;
39
40
41
42
43
44 public class ResponseContentContainsIgnoreCase 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 return false;
54 }
55
56 @Override
57 public boolean CheckTransactionalRule(MachinePerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
58 return false;
59 }
60
61 @Override
62 public boolean CheckTransactionalRule(AddDataRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
63 if (nullableFaultMsg == null) {
64 nullableFaultMsg = new AtomicReference<String>();
65 }
66
67 NameValuePair GetNameValuePairByName = Utility.getNameValuePairByName(params, "value");
68 String item = GetNameValuePairByName.getValue();
69 if (GetNameValuePairByName.isEncrypted()) {
70 item = Utility.DE(GetNameValuePairByName.getValue());
71 }
72 if (req.getXmlResponse() != null
73 && req.getXmlResponse().toLowerCase().contains(item.toLowerCase())) {
74 nullableFaultMsg.set("The response content contained the flag " + item + ". " + nullableFaultMsg.get());
75 return true;
76 }
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 "Response Content Contains, case insensitive";
93 }
94
95 @Override
96 public String GetHtmlFormattedHelp() {
97 return "If the message content of the response of a transactional service contains (value), case insensitive, then this rule will trigger.<Br>"
98 + "Applies to transactional service policies only.<br><br>"
99 + "Required parameters:"
100 + "<ul>"
101 + "<li>value - the string to compare against</li>"
102 + "</ul>";
103 }
104
105 @Override
106 public List<NameValuePair> GetRequiredParameters() {
107 ArrayList<NameValuePair> arrayList = new ArrayList<NameValuePair>();
108 arrayList.add(Utility.newNameValuePair("value", null, false, false));
109 return arrayList;
110 }
111
112 @Override
113 public List<NameValuePair> GetOptionalParameters() {
114
115 return new ArrayList<NameValuePair>();
116 }
117
118 @Override
119 public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError, ServicePolicy policy) {
120 if (outError == null) {
121 outError = new AtomicReference<String>();
122 }
123 if (params == null || params.isEmpty()) {
124 outError.set("The parameter 'value' is required. " + outError.get());
125 }
126 if (!(policy instanceof TransactionalWebServicePolicy)) {
127 outError.set("This rule only applies to Transactional Service Policies. " + outError.get());
128 }
129 if ((policy instanceof TransactionalWebServicePolicy)) {
130 TransactionalWebServicePolicy twp = (TransactionalWebServicePolicy) policy;
131 if (!twp.isRecordResponseMessage() && !twp.isRecordFaultsOnly()) {
132 outError.set("This rule only works when the response is recorded. " + outError.get());
133 }
134 }
135 boolean foundLogger = false;
136 for (int i = 0; i < params.size(); i++) {
137 if (params.get(i).getName().equals("value")) {
138 foundLogger = true;
139 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
140 outError.set("A value must be specified for the parameter 'value'. " + outError.get());
141 }
142 }
143 }
144 if (!foundLogger) {
145 outError.set("The parameter 'value' is required. " + outError.get());
146 }
147 if (Utility.stringIsNullOrEmpty(outError.get())) {
148 return true;
149 } else {
150 return false;
151 }
152 }
153
154 @Override
155 public AlertType GetType() {
156 return AlertType.Performance;
157 }
158
159 @Override
160 public String GetHtmlFormattedDisplay(List<NameValuePair> params) {
161 NameValuePair mc = Utility.getNameValuePairByName(params, "value");
162 String item = UNDEFINED_VALUE;
163 if (mc != null) {
164 item = mc.getValue();
165 if (mc.isEncrypted() || mc.isEncryptOnSave()) {
166 item = ENCRYPTED_MASK;
167 }
168 }
169 return Utility.encodeHTML(GetDisplayName() + " " + item);
170 }
171
172 @Override
173 public List<PolicyType> GetAppliesTo() {
174 List<PolicyType> ret = new ArrayList<PolicyType>();
175 ret.add(PolicyType.TRANSACTIONAL);
176 return ret;
177 }
178 }