CLOUDSTACK-7610,CLOUDSTACK-7611,CLOUDSTACK-7612: Fixed following bugs in 
AlertsSyslogAppender 1. Added sync alert. 2. Changed unrecognised alerts are 
send as unknown instead of null. 3. Added unit tests to cover some more 
scenarios.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4eeae5ad
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4eeae5ad
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4eeae5ad

Branch: refs/heads/master
Commit: 4eeae5ad51ce8d35701509cde9b99cee4ecaccc7
Parents: 7972f53
Author: Anshul Gangwar <anshul.gang...@citrix.com>
Authored: Tue Sep 23 14:50:59 2014 +0530
Committer: Devdeep Singh <devd...@gmail.com>
Committed: Fri Sep 26 14:02:50 2014 +0530

----------------------------------------------------------------------
 .../cloudstack/syslog/AlertsSyslogAppender.java | 10 ++++---
 .../syslog/AlertsSyslogAppenderTest.java        | 30 ++++++++++++++++++--
 2 files changed, 34 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eeae5ad/plugins/alert-handlers/syslog-alerts/src/org/apache/cloudstack/syslog/AlertsSyslogAppender.java
----------------------------------------------------------------------
diff --git 
a/plugins/alert-handlers/syslog-alerts/src/org/apache/cloudstack/syslog/AlertsSyslogAppender.java
 
b/plugins/alert-handlers/syslog-alerts/src/org/apache/cloudstack/syslog/AlertsSyslogAppender.java
index 5f6e8ec..7324c20 100644
--- 
a/plugins/alert-handlers/syslog-alerts/src/org/apache/cloudstack/syslog/AlertsSyslogAppender.java
+++ 
b/plugins/alert-handlers/syslog-alerts/src/org/apache/cloudstack/syslog/AlertsSyslogAppender.java
@@ -49,7 +49,7 @@ public class AlertsSyslogAppender extends AppenderSkeleton {
     public static final int LENGTH_OF_STRING_MESSAGE = 8;
     public static final String MESSAGE_DELIMITER_STRING = "   ";
     //add the alertType in this array it its level needs to be set to critical
-    private static final int[] criticalAlerts = {7, 8, 9, 10, 11, 12, 13, 15, 
16, 19, 20};
+    private static final int[] criticalAlerts = {7, 8, 9, 10, 11, 12, 13, 15, 
16, 19, 20, 27};
     private static final Map<Integer, String> alertsMap;
 
     static {
@@ -81,6 +81,7 @@ public class AlertsSyslogAppender extends AppenderSkeleton {
         aMap.put(24, "unallocatedDirectAttachedPublicIp");
         aMap.put(25, "unallocatedLocalStorage");
         aMap.put(26, "resourceLimitExceeded");
+        aMap.put(27, "sync");
 
         alertsMap = Collections.unmodifiableMap(aMap);
     }
@@ -230,7 +231,8 @@ public class AlertsSyslogAppender extends AppenderSkeleton {
         }
 
         if (alertType >= 0) {
-            message.append("alertType").append(_keyValueDelimiter).append(" 
").append(alertsMap.get(alertType)).append(MESSAGE_DELIMITER_STRING);
+            message.append("alertType").append(_keyValueDelimiter).append(" 
").append(alertsMap.containsKey(alertType) ? alertsMap.get(alertType) : 
"unknown")
+                    .append(MESSAGE_DELIMITER_STRING);
             if (dataCenterId != 0) {
                 
message.append("dataCenterId").append(_keyValueDelimiter).append(" 
").append(dataCenterId).append(MESSAGE_DELIMITER_STRING);
             }
@@ -246,10 +248,10 @@ public class AlertsSyslogAppender extends 
AppenderSkeleton {
             if (sysMessage != null) {
                 message.append("message").append(_keyValueDelimiter).append(" 
").append(sysMessage);
             } else {
-                errorHandler.error(" What is the use of alert without message 
");
+                errorHandler.error("What is the use of alert without message 
");
             }
         } else {
-            errorHandler.error(" Invalid alert Type ");
+            errorHandler.error("Invalid alert Type ");
         }
 
         return message.toString();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eeae5ad/plugins/alert-handlers/syslog-alerts/test/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java
----------------------------------------------------------------------
diff --git 
a/plugins/alert-handlers/syslog-alerts/test/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java
 
b/plugins/alert-handlers/syslog-alerts/test/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java
index 5799348..7b7dbe0 100644
--- 
a/plugins/alert-handlers/syslog-alerts/test/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java
+++ 
b/plugins/alert-handlers/syslog-alerts/test/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java
@@ -17,8 +17,8 @@
 
 package org.apache.cloudstack.syslog;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import javax.naming.ConfigurationException;
 
@@ -42,6 +42,12 @@ public class AlertsSyslogAppenderTest {
     }
 
     @Test
+    public void setSyslogAppendersWithPortTest() {
+        _appender.setSyslogHosts("10.1.1.1:897,10.1.1.2");
+        assertEquals(" error Syslog Appenders list size not as expected ", 2, 
_appender._syslogAppenders.size());
+    }
+
+    @Test
     public void setSyslogAppendersNegativeTest() {
         //setting invalid IP for Syslog Hosts
         _appender.setSyslogHosts("10.1.1.");
@@ -57,4 +63,24 @@ public class AlertsSyslogAppenderTest {
             createdMessage.contains("alertType:: managementNode" + 
AlertsSyslogAppender.MESSAGE_DELIMITER_STRING + "message:: Management server 
node 127.0.0.1 is up"));
         assertTrue("severity level not as expected ", 
createdMessage.contains("WARN"));
     }
+
+    @Test
+    public void appendUnknownTest() {
+        String message = "alertType:: 40 // dataCenterId:: 0 // podId:: 0 // 
clusterId:: null // message:: Management" + " server node 127.0.0.1 is up";
+        _appender.parseMessage(message);
+        String createdMessage = _appender.createSyslogMessage();
+        assertTrue(" message is not as expected ",
+                createdMessage.contains("alertType:: unknown" + 
AlertsSyslogAppender.MESSAGE_DELIMITER_STRING + "message:: Management server 
node 127.0.0.1 is up"));
+        assertTrue("severity level not as expected ", 
createdMessage.contains("WARN"));
+    }
+
+    @Test
+    public void appendFirstAlertTest() {
+        String message = "alertType:: 0 // dataCenterId:: 0 // podId:: 0 // 
clusterId:: null // message:: Management" + " server node 127.0.0.1 is up";
+        _appender.parseMessage(message);
+        String createdMessage = _appender.createSyslogMessage();
+        assertTrue(" message is not as expected ",
+                createdMessage.contains("alertType:: availableMemory" + 
AlertsSyslogAppender.MESSAGE_DELIMITER_STRING + "message:: Management server 
node 127.0.0.1 is up"));
+        assertTrue("severity level not as expected ", 
createdMessage.contains("WARN"));
+    }
 }
\ No newline at end of file

Reply via email to