ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject git commit: AMBARI-4496. Filter ignored alerts for Host and Service (ncole)
Date Mon, 03 Feb 2014 19:34:39 GMT
Updated Branches:
  refs/heads/trunk c92863cba -> cf5c6ad64


AMBARI-4496.  Filter ignored alerts for Host and Service (ncole)


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

Branch: refs/heads/trunk
Commit: cf5c6ad6445909bd23fc94affd4e1df6e7daadc7
Parents: c92863c
Author: Nate Cole <ncole@hortonworks.com>
Authored: Fri Jan 31 20:32:51 2014 -0500
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Mon Feb 3 14:10:45 2014 -0500

----------------------------------------------------------------------
 .../server/configuration/Configuration.java     |   2 +
 .../nagios/NagiosPropertyProvider.java          |  37 +++++-
 .../nagios/NagiosPropertyProviderTest.java      | 133 ++++++++++++++++++-
 3 files changed, 167 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/cf5c6ad6/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 293792b..c06c92c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -168,6 +168,8 @@ public class Configuration {
   public static final String JAVAX_SSL_TRUSTSTORE_TYPE = "javax.net.ssl.trustStoreType";
   public static final String GANGLIA_HTTPS_KEY = "ganglia.https";
   public static final String NAGIOS_HTTPS_KEY = "nagios.https";
+  public static final String NAGIOS_IGNORE_FOR_SERVICES_KEY = "nagios.ignore_for_services";
+  public static final String NAGIOS_IGNORE_FOR_HOSTS_KEY = "nagios.ignore_for_hosts";
   public static final String SRVR_TWO_WAY_SSL_PORT_DEFAULT = "8441";
   public static final String SRVR_ONE_WAY_SSL_PORT_DEFAULT = "8440";
   public static final String SRVR_CRT_NAME_DEFAULT = "ca.crt";

http://git-wip-us.apache.org/repos/asf/ambari/blob/cf5c6ad6/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
index 79222af..0b05422 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
@@ -20,9 +20,11 @@ package org.apache.ambari.server.controller.nagios;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -35,6 +37,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.internal.BaseProvider;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.PropertyProvider;
@@ -69,6 +72,13 @@ public class NagiosPropertyProvider extends BaseProvider implements PropertyProv
   private static final String ALERT_SUMMARY_WARNING_PROPERTY_ID = "alerts/summary/WARNING";
   private static final String ALERT_SUMMARY_CRITICAL_PROPERTY_ID = "alerts/summary/CRITICAL";
   
+  private static final List<String> IGNORABLE_FOR_SERVICES = new ArrayList<String>(
+      Arrays.asList("NodeManager health", "NodeManager process", "TaskTracker process",
+      "RegionServer process", "DataNode process", "DataNode space",
+      "ZooKeeper Server process"));
+  
+  private static final List<String> IGNORABLE_FOR_HOSTS = new ArrayList<String>(
+      Arrays.asList("percent"));
   
   // holds alerts for clusters.  clusterName -> AlertStates
   private static final Map<String, AlertState> CLUSTER_ALERTS = new ConcurrentHashMap<String,
AlertState>();
@@ -105,6 +115,20 @@ public class NagiosPropertyProvider extends BaseProvider implements PropertyProv
   @Inject
   public static void init(Injector injector) {
     clusters = injector.getInstance(Clusters.class);
+    Configuration config = injector.getInstance(Configuration.class);
+    
+    String ignores = config.getProperty(Configuration.NAGIOS_IGNORE_FOR_SERVICES_KEY);
+    if (null != ignores) {
+      for (String str : ignores.split(","))
+        IGNORABLE_FOR_SERVICES.add(str);
+    }
+
+    ignores = config.getProperty(Configuration.NAGIOS_IGNORE_FOR_HOSTS_KEY);
+    if (null != ignores) {
+      for (String str : ignores.split(","))
+        IGNORABLE_FOR_HOSTS.add(str);
+    }
+    
   }  
   
   public NagiosPropertyProvider(Resource.Type type,
@@ -133,7 +157,6 @@ public class NagiosPropertyProvider extends BaseProvider implements PropertyProv
 
     Set<String> propertyIds = getRequestPropertyIds(request, predicate);
     
-    
     for (Resource res : resources) {
       String matchValue = res.getPropertyValue(resourceTypeProperty).toString();
       
@@ -182,9 +205,21 @@ public class NagiosPropertyProvider extends BaseProvider implements PropertyProv
       switch (resourceType.getInternalType()) {
         case Service:
           match = alert.getService().equals(matchValue);
+          if (match && null != alert.getDescription() &&
+              IGNORABLE_FOR_SERVICES.contains(alert.getDescription())) {
+            match = false;
+          }
           break;
         case Host:
           match = alert.getHost().equals(matchValue);
+          if (match && null != alert.getDescription()) {
+            String desc = alert.getDescription();
+            Iterator<String> it = IGNORABLE_FOR_HOSTS.iterator();
+            while (it.hasNext() && match) {
+              if (-1 != desc.toLowerCase().indexOf(it.next()))
+                match = false;
+            }
+          }
           break;
         default:
           break;

http://git-wip-us.apache.org/repos/asf/ambari/blob/cf5c6ad6/ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java
index 649f9d8..0b8e6cc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.ganglia.TestStreamProvider;
 import org.apache.ambari.server.controller.internal.ResourceImpl;
 import org.apache.ambari.server.controller.spi.Request;
@@ -52,13 +53,14 @@ import com.google.inject.persist.PersistService;
 public class NagiosPropertyProviderTest {
 
   private static final String HOST = "c6401.ambari.apache.org";
-  
+
+  private InMemoryDefaultTestModule module = null;
   private Clusters clusters = null;
   private Injector injector = null;
 
   @Before
   public void setup() throws Exception {
-    InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
+    module = new InMemoryDefaultTestModule();
 
     injector = Guice.createInjector(module);
     injector.getInstance(GuiceJpaInitializer.class);
@@ -181,7 +183,7 @@ public class NagiosPropertyProviderTest {
     Assert.assertTrue(List.class.isInstance(values.get("alerts").get("detail")));
     
     List<?> list = (List<?>) values.get("alerts").get("detail");
-    Assert.assertTrue(4 == list.size());
+    Assert.assertEquals(Integer.valueOf(3), Integer.valueOf(list.size()));
     for (Object o : list) {
       Assert.assertTrue(Map.class.isInstance(o));
       Map<?, ?> map = (Map<?, ?>) o;
@@ -197,7 +199,7 @@ public class NagiosPropertyProviderTest {
     
     Assert.assertTrue(summary.get("OK").equals(Integer.valueOf(1)));
     Assert.assertTrue(summary.get("WARNING").equals(Integer.valueOf(0)));
-    Assert.assertTrue(summary.get("CRITICAL").equals(Integer.valueOf(3)));
+    Assert.assertTrue(summary.get("CRITICAL").equals(Integer.valueOf(2)));
   }  
   
 
@@ -258,6 +260,129 @@ public class NagiosPropertyProviderTest {
     Assert.assertTrue(summary.get("OK").equals(Integer.valueOf(6)));
     Assert.assertTrue(summary.get("WARNING").equals(Integer.valueOf(0)));
     Assert.assertTrue(summary.get("CRITICAL").equals(Integer.valueOf(1)));
+  }
+  
+  @Test
+  public void testNagiosHostAlertsWithIgnore() throws Exception {
+    Cluster cluster = clusters.getCluster("c1");
+    Service service = cluster.addService("NAGIOS");
+    service.setDesiredStackVersion(new StackId("HDP-2.0.5"));
+    service.persist();
+    
+    ServiceComponent sc = service.addServiceComponent("NAGIOS_SERVER");
+    sc.setDesiredStackVersion(new StackId("HDP-2.0.5"));
+    sc.addServiceComponentHost(HOST);
+    sc.persist();
+    
+    TestStreamProvider streamProvider = new TestStreamProvider("nagios_alerts.txt");
+
+    NagiosPropertyProvider npp = new NagiosPropertyProvider(Resource.Type.Host,
+        streamProvider,
+        "Hosts/cluster_name",
+        "Hosts/host_name");
+    npp.forceReset();
+    
+    Resource resource = new ResourceImpl(Resource.Type.Service);
+    resource.setProperty("Hosts/cluster_name", "c1");
+    resource.setProperty("Hosts/host_name", "c6401.ambari.apache.org");
+    
+    // request with an empty set should get all supported properties
+    Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(),
new HashMap<String, TemporalInfo>());
+
+    Set<Resource> set = npp.populateResources(Collections.singleton(resource), request,
null);
+    Assert.assertEquals(1, set.size());
+    
+    Resource res = set.iterator().next();
+    
+    Map<String, Map<String, Object>> values = res.getPropertiesMap();
+    
+    Assert.assertTrue(values.containsKey("alerts"));
+    Assert.assertTrue(values.containsKey("alerts/summary"));
+    Assert.assertTrue(values.get("alerts").containsKey("detail"));
+    Assert.assertTrue(List.class.isInstance(values.get("alerts").get("detail")));
+    
+    List<?> list = (List<?>) values.get("alerts").get("detail");
+    Assert.assertEquals(Integer.valueOf(16), Integer.valueOf(list.size()));
+    for (Object o : list) {
+      Assert.assertTrue(Map.class.isInstance(o));
+      Map<?, ?> map = (Map<?, ?>) o;
+      Assert.assertTrue(map.containsKey("host_name"));
+      String host = map.get("host_name").toString();
+      Assert.assertEquals("c6401.ambari.apache.org", host);
+    }
+    
+    Map<String, Object> summary = values.get("alerts/summary");
+    Assert.assertTrue(summary.containsKey("OK"));
+    Assert.assertTrue(summary.containsKey("WARNING"));
+    Assert.assertTrue(summary.containsKey("CRITICAL"));
+    
+    Assert.assertEquals(summary.get("OK"), Integer.valueOf(15));
+    Assert.assertEquals(summary.get("WARNING"), Integer.valueOf(0));
+    Assert.assertEquals(summary.get("CRITICAL"), Integer.valueOf(1));
+  }  
+  
+  @Test
+  public void testNagiosServiceAlertsAddIgnore() throws Exception {
+    module.getProperties().setProperty(Configuration.NAGIOS_IGNORE_FOR_SERVICES_KEY,
+        "HBase Master process on c6401.ambari.apache.org");
+    
+    Cluster cluster = clusters.getCluster("c1");
+    Service service = cluster.addService("NAGIOS");
+    service.setDesiredStackVersion(new StackId("HDP-2.0.5"));
+    service.persist();
+    
+    ServiceComponent sc = service.addServiceComponent("NAGIOS_SERVER");
+    sc.setDesiredStackVersion(new StackId("HDP-2.0.5"));
+    sc.addServiceComponentHost(HOST);
+    sc.persist();
+    
+    TestStreamProvider streamProvider = new TestStreamProvider("nagios_alerts.txt");
+
+    NagiosPropertyProvider npp = new NagiosPropertyProvider(Resource.Type.Service,
+        streamProvider,
+        "ServiceInfo/cluster_name",
+        "ServiceInfo/service_name");
+    npp.forceReset();
+    NagiosPropertyProvider.init(injector);
+    
+    Resource resource = new ResourceImpl(Resource.Type.Service);
+    resource.setProperty("ServiceInfo/cluster_name", "c1");
+    resource.setProperty("ServiceInfo/service_name", "HBASE");
+    
+    // request with an empty set should get all supported properties
+    Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(),
new HashMap<String, TemporalInfo>());
+
+    Set<Resource> set = npp.populateResources(Collections.singleton(resource), request,
null);
+    Assert.assertEquals(1, set.size());
+    
+    Resource res = set.iterator().next();
+    
+    Map<String, Map<String, Object>> values = res.getPropertiesMap();
+    
+    Assert.assertTrue(values.containsKey("alerts"));
+    Assert.assertTrue(values.containsKey("alerts/summary"));
+    Assert.assertTrue(values.get("alerts").containsKey("detail"));
+    Assert.assertTrue(List.class.isInstance(values.get("alerts").get("detail")));
+    
+    List<?> list = (List<?>) values.get("alerts").get("detail");
+    // removed an additional one
+    Assert.assertEquals(Integer.valueOf(2), Integer.valueOf(list.size()));
+    for (Object o : list) {
+      Assert.assertTrue(Map.class.isInstance(o));
+      Map<?, ?> map = (Map<?, ?>) o;
+      Assert.assertTrue(map.containsKey("service_name"));
+      String serviceName = map.get("service_name").toString();
+      Assert.assertTrue("expected HBASE", serviceName.equals("HBASE"));
+    }
+    
+    Map<String, Object> summary = values.get("alerts/summary");
+    Assert.assertTrue(summary.containsKey("OK"));
+    Assert.assertTrue(summary.containsKey("WARNING"));
+    Assert.assertTrue(summary.containsKey("CRITICAL"));
+    
+    Assert.assertTrue(summary.get("OK").equals(Integer.valueOf(1)));
+    Assert.assertTrue(summary.get("WARNING").equals(Integer.valueOf(0)));
+    Assert.assertTrue(summary.get("CRITICAL").equals(Integer.valueOf(1)));
   }    
   
 }


Mime
View raw message