Repository: ambari
Updated Branches:
  refs/heads/trunk 38e18b371 -> a6b34b893


AMBARI-5958. Optimize Nagios alert processing for 2K cluster (ncole)


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

Branch: refs/heads/trunk
Commit: a6b34b893a80a5e70b4365f4a4b419e3db5fa001
Parents: 38e18b3
Author: Nate Cole <[email protected]>
Authored: Fri May 30 10:56:10 2014 -0400
Committer: Nate Cole <[email protected]>
Committed: Fri May 30 12:32:32 2014 -0400

----------------------------------------------------------------------
 .../src/addOns/nagios/scripts/nagios_alerts.php | 36 +++++++-------------
 1 file changed, 13 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a6b34b89/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
----------------------------------------------------------------------
diff --git a/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php 
b/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
index 8b9ccae..e0fd69e 100644
--- a/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
+++ b/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
@@ -297,14 +297,11 @@ function hdp_mon_generate_response( $response_data )
     $services_objects = array ();
     $i = 0;
     foreach ($matches[1] as $object) {
-      $map = getParameterMap($object);
-      $servicestatus = array ();
+      $servicestatus = getParameterMap($object, $servicestatus_attributes);
       switch ($alert_type) {
       case "all":
-        if (empty($host) || getParameterMapValue($map, "host_name") == $host) {
-          foreach ($servicestatus_attributes as $attrib) {
-            $servicestatus[$attrib] = htmlentities(getParameterMapValue($map, 
$attrib), ENT_COMPAT);
-          }
+
+        if (empty($host) || $servicestatus['host_name'] == $host) {
           $servicestatus['service_type'] = 
get_service_type($servicestatus['service_description']);
           $srv_desc = explode ("::",$servicestatus['service_description'],2);
 
@@ -448,27 +445,20 @@ function hdp_mon_generate_response( $response_data )
     return "";
   }
 
-  function getParameterMap($object) {
-    $map = array ();
-
-    $long_key = "long_plugin_output";
-    $found_long = false;
-    foreach (preg_split("/\n/", trim($object)) as $line) {
-      $arr = explode("=", $line, 2);
-      $key = trim($arr[0]);
-      if ($found_long) {
-        $map[$long_key] = trim($line);
-        $found_long = false;
-      } else {
-        $map[$key] = $arr[1];
-        if ($key == $long_key)
-          $found_long = true;
-      }
+
+  function getParameterMap($object, $keynames) {
+
+    $cnt = preg_match_all('/\t([\S]*)=[\n]?[\t]?([\S= ]*)/', $object, 
$matches, PREG_PATTERN_ORDER);
+
+    $tmpmap = array_combine($matches[1], $matches[2]);
+
+    $map = array();
+    foreach ($keynames as $key) {
+      $map[$key] = htmlentities($tmpmap[$key], ENT_COMPAT);
     }
 
     return $map;
   }
-
 function indent($json) {
 
     $result      = '';

Reply via email to