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.actions;
23
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
27 import java.util.concurrent.atomic.AtomicReference;
28 import org.apache.log4j.Level;
29 import org.miloss.fgsms.common.Logger;;
30 import org.miloss.fgsms.common.Utility;
31 import org.miloss.fgsms.plugins.sla.AlertContainer;
32 import org.miloss.fgsms.plugins.sla.SLAActionInterface;
33 import org.miloss.fgsms.services.interfaces.common.NameValuePair;
34 import org.miloss.fgsms.services.interfaces.common.PolicyType;
35 import org.miloss.fgsms.services.interfaces.policyconfiguration.SLAAction;
36 import org.miloss.fgsms.sla.SLACommon;
37
38
39
40
41
42 public class SLAActionLog implements SLAActionInterface {
43
44 private static Logger log = Logger.getLogger("fgsms.SLAProcessor");
45
46
47 public void ProcessAction(AlertContainer alert) {
48 SendLogger(alert.getFaultMsg(), alert.getSlaActionBaseType(), alert.getModifiedurl(), alert.getIncidentid());
49
50 }
51
52 private static void SendLogger(String msg, SLAAction logAction, String url, String incident) {
53 if (logAction != null) {
54 NameValuePair GetNameValuePairByName = Utility.getNameValuePairByName(logAction.getParameterNameValue(), "Logger");
55 if (GetNameValuePairByName != null) {
56 Logger l = null;
57 if (GetNameValuePairByName.isEncrypted()) {
58 l = Logger.getLogger(Utility.DE(GetNameValuePairByName.getValue()));
59 } else {
60 l = Logger.getLogger((GetNameValuePairByName.getValue()));
61 }
62 l.log(Level.WARN, SLACommon.getBundleString("SLALoggerPrefix")
63 + url + " message: " + msg.toString() + " SLAFaultID: " + incident);
64 }
65 } else {
66 log.warn("log action is null, defaulting");
67 log.log(Level.WARN, SLACommon.getBundleString("SLALoggerPrefix")
68 + url + " message: " + msg.toString() + " SLAFaultID: " + incident);
69 }
70
71 }
72
73 @Override
74 public List<NameValuePair> GetRequiredParameters() {
75 List<NameValuePair> r = new ArrayList<NameValuePair>();
76 r.add(Utility.newNameValuePair("Logger", null, false, false));
77 return r;
78 }
79
80 @Override
81 public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError) {
82 if (outError == null) {
83 outError = new AtomicReference<String>();
84 }
85 if (params == null || params.isEmpty()) {
86 outError.set("The parameter 'Logger' is required for action " + this.GetDisplayName() +". " + outError.get());
87 }
88 boolean foundLogger=false;
89 for (int i = 0; i < params.size(); i++) {
90 if (params.get(i).getName().equals("Logger")) {
91 foundLogger=true;
92 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
93 outError.set("A value must be specified for the parameter 'Logger'. " + outError.get());
94 }
95 }
96 }
97 if (!foundLogger)
98 outError.set("The parameter 'Logger' is required. " + outError.get());
99 if (Utility.stringIsNullOrEmpty(outError.get())) {
100 return true;
101 } else {
102 return false;
103 }
104 }
105
106 @Override
107 public String GetHtmlFormattedHelp() {
108 return "Record an event to log<Br>fgsms has a number of defined Loggers which can be used to configure"
109 + "the Apache Log4j logging system to output logs to a wide variety of things, such as a File, Windows Event Log, Syslog and many more. "
110 + "<Br><br>To use this plugin, you have define the following parameter:"
111 + "<ul><li>Logger - Some built in loggers are: "
112 + "<ul>"
113 + "<li>fgsms.SLAProcessor.SysLog</li>"
114 + "<li>fgsms.SLAProcessor.EventLog</li>"
115 + "<li>fgsms.SLAProcessor.UdpLog</li>"
116 + "<li>fgsms.SLAProcessor.FileLog</li></ul>"
117 + "</li></ul>";
118 }
119
120 @Override
121 public String GetDisplayName() {
122 return "Record a Log message";
123 }
124
125 @Override
126 public List<NameValuePair> GetOptionalParameters() {
127 return new ArrayList<NameValuePair>();
128 }
129
130 @Override
131 public void ProcessAction(AlertContainer alert, List<NameValuePair> params) {
132 SendLogger(alert.getFaultMsg(), alert.getSlaActionBaseType(), alert.getModifiedurl(), alert.getIncidentid());
133 }
134
135 @Override
136 public List<PolicyType> GetAppliesTo() {
137 return Utility.getAllPolicyTypes();
138 }
139 }