View Javadoc
1   /**
2    * This Source Code Form is subject to the terms of the Mozilla Public
3    * License, v. 2.0. If a copy of the MPL was not distributed with this
4    * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5    *
6    * If it is not possible or desirable to put the notice in a particular
7    * file, then You may include the notice in a location (such as a LICENSE
8    * file in a relevant directory) where a recipient would be likely to look
9    * for such a notice.
10   *
11   * 
12   */
13  /*  ---------------------------------------------------------------------------
14   *  U.S. Government, Department of the Army
15   *  Army Materiel Command
16   *  Research Development Engineering Command
17   *  Communications Electronics Research Development and Engineering Center
18   *  ---------------------------------------------------------------------------
19   */
20  package org.miloss.fgsms.plugins;
21  
22  import java.sql.Connection;
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.concurrent.atomic.AtomicReference;
26  import org.miloss.fgsms.common.AuditLogger;
27  import org.miloss.fgsms.common.DBSettingsLoader;
28  import org.miloss.fgsms.common.Utility;
29  import org.miloss.fgsms.plugins.sla.AlertType;
30  import org.miloss.fgsms.plugins.sla.SLARuleInterface;
31  import org.miloss.fgsms.services.interfaces.common.MachinePerformanceData;
32  import org.miloss.fgsms.services.interfaces.common.NameValuePair;
33  import org.miloss.fgsms.services.interfaces.common.PolicyType;
34  import org.miloss.fgsms.services.interfaces.common.ProcessPerformanceData;
35  import org.miloss.fgsms.services.interfaces.common.SecurityWrapper;
36  import org.miloss.fgsms.services.interfaces.datacollector.AddDataRequestMsg;
37  import org.miloss.fgsms.services.interfaces.datacollector.BrokerData;
38  import org.miloss.fgsms.services.interfaces.policyconfiguration.KeyNameValueEnc;
39  import org.miloss.fgsms.services.interfaces.policyconfiguration.ServicePolicy;
40  import org.miloss.fgsms.services.interfaces.status.SetStatusRequestMsg;
41  
42  /**
43   * This is a sample plugin for SLA Rules. In this case, all web service
44   * transactions are triggered as SLA faults.
45   *
46   * @author AO
47   */
48  public class CustomSLARule implements SLARuleInterface {
49  
50      @Override
51      public boolean CheckTransactionalRule(SetStatusRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
52          return false;
53      }
54  
55      @Override
56      public boolean CheckTransactionalRule(AddDataRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
57          /*String x;
58          String val = null;
59          KeyNameValueEnc setting = DBSettingsLoader.GetPropertiesFromDB(true, "MyPlugin", "MyName");
60          if (setting != null && setting.getKeyNameValue() != null) {
61              val = setting.getKeyNameValue().getPropertyValue();
62          }
63          AuditLogger.LogItem(this.getClass().getCanonicalName(), "CheckRule", "system", "my message", new SecurityWrapper(), null);
64          Connection con = Utility.getPerformanceDBConnection();
65          try {
66              //do something
67          } catch (Exception ex) {
68              //log some message
69          } finally {
70              if (con != null) {
71                  try {
72                      con.close();
73                  } catch (Exception e) {
74                  }
75              }
76          }
77          nullableFaultMsg.set("Hello World from " + this.getClass().getCanonicalName());
78          */
79          return true;
80      }
81  
82      @Override
83      public boolean CheckTransactionalRule(String url, List<BrokerData> data, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
84          return false;
85      }
86  
87      @Override
88      public boolean CheckNonTransactionalRule(ServicePolicy pol, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg, boolean pooled) {
89          return false;
90      }
91  
92      @Override
93      public boolean CheckTransactionalRule(ProcessPerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
94          return false;
95      }
96  
97      @Override
98      public String GetDisplayName() {
99          return "Hello World Custom Rule";
100     }
101 
102     @Override
103     public String GetHtmlFormattedHelp() {
104         return "Help! for Hello World Custom Rule";
105     }
106 
107     @Override
108     public List<NameValuePair> GetRequiredParameters() {
109         return new ArrayList<NameValuePair>();
110     }
111 
112     @Override
113     public List<NameValuePair> GetOptionalParameters() {
114         return new ArrayList<NameValuePair>();
115     }
116 
117     @Override
118     public boolean CheckTransactionalRule(MachinePerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
119         return false;
120     }
121 
122     @Override
123     public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError, ServicePolicy policy) {
124         return true;
125     }
126 
127     @Override
128     public AlertType GetType() {
129         return AlertType.Performance;
130     }
131 
132     @Override
133     public String GetHtmlFormattedDisplay(List<NameValuePair> params) {
134         return GetDisplayName() + " some logical value to compare against";
135     }
136 
137     @Override
138     public List<PolicyType> GetAppliesTo() {
139         return Utility.getAllPolicyTypes();
140     }
141 
142 }