From 116551dec7e618ec9278b2192dc427f1767bbd8a Mon Sep 17 00:00:00 2001
From: Fabian Herschel <fabian.herschel@suse.com>
Date: Thu, 12 Dec 2024 14:24:56 +0100
Subject: [PATCH] fix for bsc#1234342 and fixed indentations for better code
 maintenance

---
 bin/SAPHanaSR-monitor  | 131 ++++++------
 test/SAPHanaSRTools.pm | 381 ++++++++++++++++++---------------
 2 files changed, 284 insertions(+), 228 deletions(-)

diff --git a/bin/SAPHanaSR-monitor b/bin/SAPHanaSR-monitor
index da6bf080..3e93fca8 100755
--- a/bin/SAPHanaSR-monitor
+++ b/bin/SAPHanaSR-monitor
@@ -2,15 +2,15 @@
 #
 # 
 # (c) 2014 SUSE Linux Products GmbH, Nuremberg, Germany
-# (c) 2015-2018 SUSE Linux GmbH, Nuremberg, Germany
-# Author: Fabian Herschel
+# (c) 2015-2024 SUSE Linux GmbH, Nuremberg, Germany
+# Author: Fabian Herschel <fabian.herschel@suse.com>
 # License: GPL v2+
-use strict;
-my $Version="0.16.2018.05.09.2";
+my $Version="0.17.2024.12.12.1";
 #
 ##################################################################
 #
 use POSIX;
+use strict;
 use Sys::Syslog;
 use Sys::Hostname;
 use File::Path;
@@ -29,11 +29,6 @@ my $sortBy="";
 # my $table_titleH = "Host";
 my %Name;
 my %Host;
-my %Site;
-my %Global;
-my %HName;
-my %SName;
-my %GName;
 my $help;
 my $version;
 my $cibFile="";
@@ -69,26 +64,23 @@ sub init()
 ################ BEGIN CUT - MOVE THAT TO AN PERL-LIBRARY LATER
 #
 
-
-
-sub  print_page($$$$$$$$$$$$$$$$$$$$$$$$$)
+sub  print_page
 {
-  my ($format, $sid, $sid_color, $hana1stat, $node1, $hana2stat, $node2, $syncstat, $syncdir, $crm_out, $crm_col, $crm_errors, $attr_out, $attr_col, $attr_errors, $score_out, $score_col, $score_errors, $log_out, $log_col, $log_errors,
-     $ftd_out, $ftd_col, $ftd_errors, $check_lpa_col, $check_lpa_msg);
-  $format=shift();
-  $sid=shift(); $sid_color=shift();
-  $hana1stat=shift(); $node1=shift(); 
-  $hana2stat=shift(); $node2=shift(); 
-  $syncstat=shift(); $syncdir=shift();
-  $crm_out=shift(); $crm_col=shift(); $crm_errors=shift(); 
-  $attr_out=shift(); $attr_col=shift(); $attr_errors=shift();
-  $score_out=shift(); $score_col=shift(); $score_errors=shift();
-  $log_out=shift(); $log_col=shift(); $log_errors=shift();
-  $ftd_out=shift(); $ftd_col=shift(); $ftd_errors=shift();
-  $check_lpa_col=shift(); $check_lpa_msg=shift();
+  my %P = @_;
+  my $format=$P{format}; my  $sid=$P{sid}; my  $sid_color=$P{sidColor};
+  my  $hana1stat=$P{hanaStatusA}; my  $node1=$P{nodeListA};
+  my  $hana2stat=$P{hanaStatusB}; my  $node2=$P{nodeListB};
+  my  $syncstat=$P{syncColor}; my  $syncdir=$P{syncDirection};
+  my  $crm_out=$P{crmOut}; my  $crm_col=$P{crmColor}; my  $crm_errors=$P{crmErrors}; my  $crm_cfg=$P{crmConfig};
+  my  $attr_out=$P{attrOut}; my  $attr_col=$P{attrColor}; my  $attr_errors=$P{attrErrors};
+  my  $score_out=$P{scoreOut}; my  $score_col=$P{scoreColor}; my  $score_errors=$P{scoreErrors};
+  my  $log_out=$P{logOut}; my  $log_col=$P{logColor}; my  $log_errors=$P{logErrors};
+  my  $ftd_out=$P{ftdOut}; my  $ftd_col=$P{ftdColor}; my  $ftd_errors=$P{ftdErrors};
+  my  $check_lpa_col=$P{lpaColor}; my  $check_lpa_msg=$P{lpaMessage};
+  my  $cibtime=$P{cibTime} ;
   # in the page layout $score_col is ignored right now
-  # TODO: Check id we add more and more parameters to the print_page or if we will use an hash as parameter or 
-  #       id we (recover) more values here inside of the function like for the lpa values:
+  # TODO: Check id we add more and more parameters to the print_page or if we will use an hash as parameter or
+  #       if we (recover) more values here inside of the function like for the lpa values:
     my $lpa_node1=get_lpa_by_host($sid, $node1);
     my $lpa_node2=get_lpa_by_host($sid, $node2);
 
@@ -96,13 +88,14 @@ sub  print_page($$$$$$$$$$$$$$$$$$$$$$$$$)
   chomp($crm_errors);
   chomp($attr_errors);
   chomp($log_errors);
+  my $nextUrl=".";
 
   if ($format eq "txt") {
       my $syncArrow="-?-";
       my $SID=uc($sid);
       if ( $syncdir eq "right" ) { $syncArrow = "==>"; }
       if ( $syncdir eq "left" ) { $syncArrow = "<=="; }
-      my $myPage = <<EOF;  
+      my $myPage = <<EOF;
 OVERALL:   $SID: $sid_color                   $mydate
 SR:        $syncstat $node1 $syncArrow $node2
 
@@ -124,7 +117,7 @@ EOF
 <html lang="en">
 <head>
 <title>SAPHanaSR status</title>
-<meta http-equiv="refresh" content="10; url=." />
+<meta http-equiv="refresh" content="10; url=$nextUrl" />
 <meta charset="utf-8"/>
 </head>
 <body class="">
@@ -217,18 +210,26 @@ sub processMonitor() {
     my $shost;
     my $laststate="";
     #
+    my %Global;
+    my %GName;
+    my %HName;
+    my %Site;
+    my %SName;
     $sid=$sids[0];   # currently ony one sid is supported
     ( $sid, $ino ) = split(":", $sid);
     $sid=lc("$sid");
-    get_hana_attributes($sid, \%Host, \%HName, \%Global, \%GName, \%Site,   \%SName);
-    if ( keys(%Host) == 0 ) {
-        printf "No attributes found for SID=%s\n", $sid;
-        exit 1;
-} 
+    %Host=(); %HName=(); %Global=(); %GName=(); %Site=(); %SName=();
+    set_Host(\%Host);
     set_HName(\%HName);
+    set_Global(\%Global);
     set_GName(\%GName);
     set_SName(\%SName);
     set_Site(\%Site);
+    get_hana_attributes($sid, \%Host, \%HName, \%Global, \%GName, \%Site,   \%SName);
+    if ( keys(%Host) == 0 ) {
+        printf "No attributes found for SID=%s\n", $sid;
+        exit 1;
+    }
     my $crm_out="CRM: TODO <==========="; # crm_mon -1D
     my $attr_out1=print_host_attr(\%Global, \%GName, "Global", "");
 	my $attr_out2=print_host_attr(\%Site,   \%SName, "Sites",  "");
@@ -268,7 +269,8 @@ sub processMonitor() {
     #unset %hanaStatus;
     @msn_list = get_master_nameserver();
 
-    foreach my $thenode ( @node_list ) {
+    my $thenode;
+    foreach $thenode ( @node_list ) {
         $hanaStatus{$thenode}="grey";
         if ( check_node_status($sid, "34" , $thenode) ) { $hanaStatus{$thenode}="green"; }
         if ( check_node_status($sid, "2" , $thenode) ) { $hanaStatus{$thenode}="yellow"; }
@@ -303,14 +305,7 @@ sub processMonitor() {
     if ( get_number_secondary($sid, "1234") != 1 ) { $attr_col="yellow"; $attr_errors .= " A-s";}
     if ( get_number_secondary($sid, "234") != 1 ) { $attr_col="yellow"; $attr_errors .= " A-S";}
     if ( get_number_primary($sid, "234") > 1 ) { $attr_col="red"; $attr_errors .= " A-PP";}
-    if ( get_hana_sync_state($sid) ne "SOK" ) { $attr_col="yellow"; $attr_errors .= " A-SFAIL"; } 
-
-    #printf "\n";
-    
-    #printf "%-16s %-16s %-16s\n", $hanaStatus{$msn_list[0]}, "$sync_direction : $sync_col", $hanaStatus{$msn_list[1]};
-    #printf "%-16s %-16s %-16s\n", $msn_list[0], $sid, $msn_list[1];
-
-    #printf "\n";
+    if ( get_hana_sync_state($sid) ne "SOK" ) { $attr_col="yellow"; $attr_errors .= " A-SFAIL"; }
     # log checks
     my $log_errors="";
     my $check_lpa_status_col;
@@ -318,23 +313,39 @@ sub processMonitor() {
 
     ( $check_lpa_status_col, $check_lpa_msg)=check_lpa_status($sid, $msn_list[0], $msn_list[1]);
 
-    if ( ( $attr_col eq "yellow" ) || ( $crm_col eq "yellow" ) || 
-         ( $log_col eq "yellow" ) || ( $attr_col eq "yellow" ) || 
-         ( $score_col eq "yellow" ) || ( $check_lpa_status_col eq "yellow") ) 
+    if ( ( $attr_col eq "yellow" ) || ( $crm_col eq "yellow" ) ||
+         ( $log_col eq "yellow" ) || ( $attr_col eq "yellow" ) ||
+         ( $score_col eq "yellow" ) || ( $check_lpa_status_col eq "yellow") )
        { $complete_col="yellow"; }
-    if ( ( $attr_col eq "red" ) || ( $crm_col eq "red" ) || 
-         ( $log_col eq "red" ) || ( $attr_col eq "red" ) || 
-         ( $score_col eq "red" ) || ( $check_lpa_status_col eq "red")) 
+    if ( ( $attr_col eq "red" ) || ( $crm_col eq "red" ) ||
+         ( $log_col eq "red" ) || ( $attr_col eq "red" ) ||
+         ( $score_col eq "red" ) || ( $check_lpa_status_col eq "red"))
        { $complete_col="red"; }
-    print_page($Format,$sid, $complete_col,
-               $hanaStatus{$msn_list[0]}, $msn_list[0],
-               $hanaStatus{$msn_list[1]}, $msn_list[1],
-               $sync_col, $sync_direction,
-               $crm_out, $crm_col, $crm_errors,
-               $attr_out, $attr_col, $attr_errors,
-               $score_out, $attr_col, $attr_errors,
-               $log_out, $log_col, $log_errors,
-               $ftd_out, $ftd_col, $check_lpa_status_col, $check_lpa_msg
+    print_page(  format => $Format,
+                  sid    => $sid,
+                  sidColor => $complete_col,
+                  hanaSattusA => $hanaStatus{$msn_list[0]},
+                  nodeListA  => $msn_list[0],
+                  hanaStatusB => $hanaStatus{$msn_list[1]},
+                  nodeListB  => $msn_list[1],
+                  syncColor  => $sync_col,
+                  syncDirection => $sync_direction,
+                  crmOut => $crm_out,
+                  crmColor => $crm_col,
+                  crmErrors => $crm_errors,
+                  attrOut => $attr_out,
+                  attrColor => $attr_col,
+                  attrErrors => $attr_errors,
+                  scoreOut => $score_out,
+                  scoreColor => $attr_col,
+                  scoreErrors => $attr_errors,
+                  logOut => $log_out,
+                  logColor => $log_col,
+                  logErrors => $log_errors,
+                  ftdOut => $ftd_out,
+                  ftdColor => $ftd_col,
+                  lpaColor => $check_lpa_status_col,
+                  lpaMessage => $check_lpa_msg
              );
     #
     $phost=get_host_primary($sid, "1234");
@@ -352,12 +363,12 @@ sub processMonitor() {
         mysyslog $priority, "%s", $message;
     }
 }
-  
+
 processMonitor();
 while ( $Continuous eq "yes" ) {
     sleep $Interval;
     processMonitor();
 }
- 
+
 closelog;
 #
diff --git a/test/SAPHanaSRTools.pm b/test/SAPHanaSRTools.pm
index 0991c02e..d78640e5 100644
--- a/test/SAPHanaSRTools.pm
+++ b/test/SAPHanaSRTools.pm
@@ -6,7 +6,7 @@
 # Copyright:    (c) 2017-2022 SUSE LLC
 # Author: Fabian Herschel
 # License: Check if we publish that under GPL v2+
-# Version: 0.26.2022.11.22
+# Version: 0.27.2024.12.12
 #
 ##################################################################
 
@@ -20,9 +20,47 @@ use Sys::Syslog;
 use Sys::Hostname;
 use File::Path;
 use vars qw(@ISA @EXPORT @EXPORT_OK);
+# use Data::Dumper qw(Dumper);
 @ISA = qw(Exporter);
 # Init immediately so their contents can be used in the 'use vars' below.
-@EXPORT    = qw(max get_nodes_online mysyslog max mysyslog get_nodes_online get_node_status get_sid_and_InstNr get_hana_attributes get_hana_sync_state get_number_primary check_node_status check_node_mode get_number_secondary get_host_primary get_host_secondary check_lpa_status check_all_ok host_attr2string get_lpa_by_host get_site_by_host print_host_attr set_new_attribute_model get_new_attribute_model get_number_HANA_standby get_HANA_nodes get_node_list set_cibFile get_master_nameserver set_GName set_HName set_SName set_Site insertAttribute path_to_table);
+@EXPORT    = qw(
+    check_lpa_status
+    check_all_ok
+    check_node_status
+    check_node_mode
+    get_hana_attributes
+    get_hana_sync_state
+    get_lpa_by_host
+    get_nodes_online
+    get_node_status
+    get_sid_and_InstNr
+    get_number_primary
+    get_number_secondary
+    get_host_primary
+    get_host_secondary
+    get_new_attribute_model
+    get_number_HANA_standby
+    get_HANA_nodes
+    get_node_list
+    get_master_nameserver
+    get_site_by_host
+    host_attr2string
+    insertAttribute
+    max
+    max get_nodes_online
+    mysyslog
+    mysyslog
+    path_to_table
+    print_host_attr
+    set_new_attribute_model
+    set_cibFile
+    set_Host
+    set_GName
+    set_HName
+    set_SName
+    set_Site
+    set_Global
+);
 
 
 my $VERSION="1.0";
@@ -48,16 +86,22 @@ my $cibFile="";
 #
 #
 
+my $refGlobal;
 my $refGName;  # reference to GlobalTableKeyName Hash attribute -> object - value
 my $refHName;  # reference to HostTableKeyName Hash
 my $refSName;  # reference to SiteTableKeyName Hash
 my $refRName;  # reference to ResourceTableKeyName Hash
 my $refSite;   # reference to Site-Hash
+my $refHost;   # reference to Host-Hash
 
 sub set_Site
 {
    $refSite=shift();
 }
+sub set_Host
+{
+   $refHost=shift();
+}
 sub set_HName
 {
    $refHName=shift();
@@ -66,6 +110,10 @@ sub set_GName
 {
    $refGName=shift();
 }
+sub set_Global
+{
+   $refGlobal=shift();
+}
 sub set_RName
 {
    $refRName=shift();
@@ -91,10 +139,10 @@ sub get_new_attribute_model
 }
 
 sub max {
- # thanks to http://www.perlunity.de/perl/forum/thread_018329.shtml
- my $a = shift;
- my $b = shift;
- return $a > $b ? $a : $b;
+    # thanks to http://www.perlunity.de/perl/forum/thread_018329.shtml
+    my $a = shift;
+    my $b = shift;
+    return $a > $b ? $a : $b;
 }
 
 sub mysyslog {
@@ -108,8 +156,10 @@ sub get_nodes_online
     my $sid=shift;
     my $result="";
     foreach my $h ( keys(%{$$refHName{node_state}}) ) {
-        if ( get_node_status($h) eq "online" ) {
-           $result++;
+        if ( not ($h =~ "^_[lt]") ) {
+            if ( get_node_status($h) eq "online" || get_node_status($h) =~ /^\d\d\d+$/ ) {
+                $result++;
+            }
         }
     }
     return $result;
@@ -123,7 +173,7 @@ sub get_node_status
     my $node=shift;
     my $standby;
     $result=$$refHName{"node_state"}->{$node};
-#printf("DBG: node %s node_state %s standby %s\n", $node, $result, $$refHName{"standby"}->{$node});
+    # printf("DBG: node %s node_state %s standby %s\n", $node, $result, $$refHName{"standby"}->{$node});
     if ( defined ($$refHName{"standby"}->{$node})) {
        $standby = $$refHName{"standby"}->{$node};
        if ( $standby eq "on" ) {
@@ -220,139 +270,137 @@ sub get_hana_attributes
     } else  {
        open $CIB, "<", "$cibFile" or die "CIB file $cibFile not found or not able to read it";
     }
-while (<$CIB>) {
-   chomp;
-   my ($host, $name, $site, $value);
-   if ( $_ =~ /cib-last-written="([^"]*)"/ ) {
-      # printf "CIB-time: %s\n", $1;
-      insertAttribute($sid, $refGL, $refGN, uc($sid), "cib-time", $1);
-   }
-
-   # search for is-managed and maintenance attributes
-   my $id, $value;
-    if ( / name=\"?(is-managed|maintenance)\"?/ ) {
-       $name = $1;
-       if ( / id="([^\"]*)"/ ) {
-           $id=$1;
-           if ( $id =~ /([^-]*)-/ ) {
-		   $id=$1;
-           }
-       }
-       if ( / value="([^\"]*)"/ ) {
-           $value=$1;
-       }
-      if ( $id eq "cib" ) {
-	      insertAttribute($sid, $refGL, $refGN, uc($sid), "$name", "$value");
-      } elsif ( $id eq "nodes" ) {
-              # to be processed in node section (below)
-      } else {
-	      insertAttribute($sid, $refRL, $refRN, "$id", "$name", "$value");
-      }
-    }
-   my $SID=uc($sid);
-   if ( $_ =~ /<node / ) {
-      # catch a node definition line
-      my $nodeID="";
-      my $nodeUNAME="";
-      if ( $_ =~ /id="([^"]+)"/ ) {
-          $nodeID=$1;
-      }
-      if ( $_ =~ /uname="([^"].+)"/ ) {
-          $nodeUNAME=$1;
-      }
-      if (($nodeID ne "") && ($nodeUNAME ne "")) {
-         $id2uname{$nodeID}=$nodeUNAME;
-         # printf STDERR "%s -> %s\n", $nodeID, $id2uname{$nodeID};
-      }
-   }
-   #
-   #  <nvpair id="nodes-1234567890-standby" name="standby" value="off"/>
-   #
-   if ( $_ =~ /id="nodes-(.+)-(standby|maintenance)"/ ) {
-       my $host=$1; my $attribute=$2;
-         if (defined $id2uname{$host}) {
-             $host = $id2uname{$host}
-         }
-       if ( $_ =~ /value="([a-zA-Z0-9\-\_]+)"/ ) {
-           my $value=$1;
-#printf "STANDBY <%s> VALUE <%s>\n", $host, $value;
-           insertAttribute($sid, $refHH, $refHN, $host, $attribute, $value);
-       }
-   }
-   #
-   #  <node_state id="1234567890" uname="node01" in_ccm="true" crmd="online" crm-debug-origin="do_update_resource" join="member" expected="member">
-   #
-   #if ( $_ =~ /node_state id=".+" uname="([a-zA-Z0-9\-\_]+)" .*crmd="([a-zA-Z0-9\-\_]+)"/ ) {
-   #    # insertAttribute($sid, \%Host, \%HName, $1, "node_status", $2);
-   #    insertAttribute($sid, $refHH, $refHN, $1, "node_status", $2);
-   #}
-   if ( $_ =~ /nvpair.*name="([a-zA-Z0-9\_\-]+_${sid}_([a-zA-Z0-9\-\_]+)|(terminate))"/) {
-      $name=$1;
-      # Bug 1192963 - L3: SAPHanaSR-monitor not reporting correctly
-      #  - catch also ids: id="host15-instance_attributes-hana_ha1_srmode"
-      #
-      if (( $_ =~ /id=.((.*)-instance_attributes)-([a-zA-Z0-9\_\-]+)/ )
-         || ( $_ =~ /id=.(status|nodes)-([a-zA-Z0-9\_\-]+)-/ )) {
-         # found attribute in nodes forever and reboot store
-         $host=$2;
-         if (defined $id2uname{$host}) {
-             $host = $id2uname{$host}
-         }
-         if ( $_ =~ /value="([^"]+)"/ ) {
-             $value=$1;
-             # printf "insert $sid HOST $host $name $value\n";
-             insertAttribute($sid, $refHH, $refHN, $host, $name, $value);
-         }
-      } elsif ( $_ =~ /id=.SAPHanaSR-[a-zA-Z0-9\_\-]+_site_[a-zA-Z0-9\-]+_([a-zA-Z0-9\_\-]+)/) {
-         # found a site attribute
-         $site=$1;
-         if ( $name =~ /[a-zA-Z0-9\_\-]+_site_([a-zA-Z0-9\-]+)/ ) {
+    while (<$CIB>) {
+        chomp;
+        my ($host, $name, $site, $value);
+        if ( $_ =~ /cib-last-written="([^"]*)"/ ) {
+            # printf "CIB-time: %s\n", $1;
+            insertAttribute($sid, $refGL, $refGN, uc($sid), "cib-time", $1);
+        }
+        # search for is-managed and maintenance attributes
+        my $id, $value;
+        if ( / name=\"?(is-managed|maintenance)\"?/ ) {
             $name = $1;
-         }
-         if ( $_ =~ /value="([^"]+)"/ ) {
-             $value=$1;
-#printf "insert $sid SITE $site $name $value\n";
-             insertAttribute($sid, $refST, $refSN, $site, $name, $value);
-         }
-      } elsif ( $_ =~ /id=.SAPHanaSR-[a-zA-Z0-9\_\-]+_glob_[a-zA-Z0-9\_\-]+/) {
-         # found a global attribute
-         $host="GLOBAL";
-         if ( $name =~ /([a-zA-Z0-9\_\-]+)_glob_([a-zA-Z0-9\_\-]+)/ ) {
-            $name = $2;
-         }
-         if ( $_ =~ /value="([^"]+)"/ ) {
-             $value=$1;
-#printf "insert $sid GLOB global $name $value\n";
-             insertAttribute($sid, $refGL, $refGN, uc($sid), $name, $value);
-         }
-      }
-   } elsif ( $_ =~ /nvpair.*name="master.([a-zA-Z0-9\_\-]+_${SID}_([a-zA-Z0-9\-\_]+))"/ ) {
-       # lines with master scores:
-       # <nvpair id="status-suse05-master-rsc_SAPHanaCon_HA1_HDB10" name="master-rsc_SAPHanaCon_HA1_HDB10" value="150"/>
-        $name="score";
-        if ( $_ =~ /id=.status-([a-zA-Z0-9\_\-]+)-master/ ) {
-         # found attribute in nodes forever and reboot store
-         $host=$1;
-         if (defined $id2uname{$host}) {
-             $host = $id2uname{$host}
-         }
-         if ( $_ =~ /value="([^"]+)"/ ) {
-             $value=$1;
-             # printf "insert $sid HOST $host $name $value\n";
-             insertAttribute($sid, $refHH, $refHN, $host, $name, $value);
-         }
-      }
-   } elsif ( $_ =~ /node_state.* crmd="([a-zA-Z0-9\-\_]+)"/ ) {
-      my $name = "node_state";
-      my $value = $1;
-      if ( $_ =~ /node_state.* uname="([a-zA-Z0-9\-\_]+)"/ ) {
-          my $host = $1;
-          insertAttribute($sid, $refHH, $refHN, $host, $name, $value);
-
-   }
-   }
-}
-close CIB;
+            if ( / id="([^\"]*)"/ ) {
+                $id=$1;
+                if ( $id =~ /([^-]*)-/ ) {
+                    $id=$1;
+                }
+            }
+            if ( / value="([^\"]*)"/ ) {
+                $value=$1;
+            }
+            if ( $id eq "cib" ) {
+                insertAttribute($sid, $refGL, $refGN, uc($sid), "$name", "$value");
+            } elsif ( $id eq "nodes" ) {
+                # to be processed in node section (below)
+            } else {
+                insertAttribute($sid, $refRL, $refRN, "$id", "$name", "$value");
+            }
+        }
+        my $SID=uc($sid);
+        if ( $_ =~ /<node / ) {
+            # catch a node definition line
+            my $nodeID="";
+            my $nodeUNAME="";
+            if ( $_ =~ /id="([^"]+)"/ ) {
+                $nodeID=$1;
+            }
+            if ( $_ =~ /uname="([^"].+)"/ ) {
+                $nodeUNAME=$1;
+            }
+            if (($nodeID ne "") && ($nodeUNAME ne "")) {
+                $id2uname{$nodeID}=$nodeUNAME;
+                # printf STDERR "%s -> %s\n", $nodeID, $id2uname{$nodeID};
+            }
+        }
+        #
+        #  <nvpair id="nodes-1234567890-standby" name="standby" value="off"/>
+        #
+        if ( $_ =~ /id="nodes-(.+)-(standby|maintenance)"/ ) {
+            my $host=$1; my $attribute=$2;
+            if (defined $id2uname{$host}) {
+                $host = $id2uname{$host}
+            }
+            if ( $_ =~ /value="([a-zA-Z0-9\-\_]+)"/ ) {
+                my $value=$1;
+                #printf "STANDBY <%s> VALUE <%s>\n", $host, $value;
+                insertAttribute($sid, $refHH, $refHN, $host, $attribute, $value);
+            }
+        }
+        #
+        #  <node_state id="1234567890" uname="node01" in_ccm="true" crmd="online" crm-debug-origin="do_update_resource" join="member" expected="member">
+        #
+        #if ( $_ =~ /node_state id=".+" uname="([a-zA-Z0-9\-\_]+)" .*crmd="([a-zA-Z0-9\-\_]+)"/ ) {
+        #    # insertAttribute($sid, \%Host, \%HName, $1, "node_status", $2);
+        #    insertAttribute($sid, $refHH, $refHN, $1, "node_status", $2);
+        #}
+        if ( $_ =~ /nvpair.*name="([a-zA-Z0-9\_\-]+_${sid}_([a-zA-Z0-9\-\_]+)|(terminate))"/) {
+            $name=$1;
+            # Bug 1192963 - L3: SAPHanaSR-monitor not reporting correctly
+            #  - catch also ids: id="host15-instance_attributes-hana_ha1_srmode"
+            #
+            if (( $_ =~ /id=.((.*)-instance_attributes)-([a-zA-Z0-9\_\-]+)/ )
+                || ( $_ =~ /id=.(status|nodes)-([a-zA-Z0-9\_\-]+)-/ )) {
+                # found attribute in nodes forever and reboot store
+                $host=$2;
+                if (defined $id2uname{$host}) {
+                    $host = $id2uname{$host}
+                }
+                if ( $_ =~ /value="([^"]+)"/ ) {
+                    $value=$1;
+                    # printf "insert $sid HOST $host $name $value\n";
+                    insertAttribute($sid, $refHH, $refHN, $host, $name, $value);
+                }
+            } elsif ( $_ =~ /id=.SAPHanaSR-[a-zA-Z0-9\_\-]+_site_[a-zA-Z0-9\-]+_([a-zA-Z0-9\_\-]+)/) {
+                # found a site attribute
+                $site=$1;
+                if ( $name =~ /[a-zA-Z0-9\_\-]+_site_([a-zA-Z0-9\-]+)/ ) {
+                    $name = $1;
+                }
+                if ( $_ =~ /value="([^"]+)"/ ) {
+                    $value=$1;
+                    #printf "insert $sid SITE $site $name $value\n";
+                    insertAttribute($sid, $refST, $refSN, $site, $name, $value);
+                }
+            } elsif ( $_ =~ /id=.SAPHanaSR-[a-zA-Z0-9\_\-]+_glob_[a-zA-Z0-9\_\-]+/) {
+                # found a global attribute
+                $host="GLOBAL";
+                if ( $name =~ /([a-zA-Z0-9\_\-]+)_glob_([a-zA-Z0-9\_\-]+)/ ) {
+                    $name = $2;
+                }
+                if ( $_ =~ /value="([^"]+)"/ ) {
+                    $value=$1;
+                    insertAttribute($sid, $refGL, $refGN, uc($sid), $name, $value);
+                }
+            }
+        } elsif ( $_ =~ /nvpair.*name="master.([a-zA-Z0-9\_\-]+_${SID}_([a-zA-Z0-9\-\_]+))"/ ) {
+            # lines with master scores:
+            # <nvpair id="status-suse05-master-rsc_SAPHanaCon_HA1_HDB10" name="master-rsc_SAPHanaCon_HA1_HDB10" value="150"/>
+            $name="score";
+            if ( $_ =~ /id=.status-([a-zA-Z0-9\_\-]+)-master/ ) {
+                # found attribute in nodes forever and reboot store
+                $host=$1;
+                if (defined $id2uname{$host}) {
+                    $host = $id2uname{$host}
+                }
+                if ( $_ =~ /value="([^"]+)"/ ) {
+                    $value=$1;
+                    # printf "insert $sid HOST $host $name $value\n";
+                    insertAttribute($sid, $refHH, $refHN, $host, $name, $value);
+                }
+            }
+        } elsif ( $_ =~ /node_state.* crmd="([a-zA-Z0-9\-\_]+)"/ ) {
+            my $name = "node_state";
+            my $value = $1;
+            if ( $_ =~ /node_state.* uname="([a-zA-Z0-9\-\_]+)"/ ) {
+                my $host = $1;
+                insertAttribute($sid, $refHH, $refHN, $host, $name, $value);
+
+            }
+        }
+    }
+    close CIB;
     return 0;
 }
 
@@ -393,7 +441,7 @@ sub get_hana_sync_state
     my $sid=shift;
     my $result="";
     if ( $newAttributeModel == 1 ) {
-        $result = $$refGName{sync_state}->{$sid};
+        $result = $$refGName{sync_state}->{uc($sid)};
     } else  {
         foreach my $h ( keys(%{$$refHName{sync_state}}) ) {
             if ( $$refHName{sync_state}->{$h} =~ /(S.*)/ ) {
@@ -488,6 +536,7 @@ sub check_node_status
     my $h=shift;
     if ( $newAttributeModel == 1 ) {
         my $site1=$$refHName{"site"}{$h};
+        # my $value=$$refSite{$site1}->{lss};
         if ( $$refSName{"lss"}{$site1} =~ /^[$lss]/ ) {
             return 1;
         }
@@ -759,9 +808,9 @@ sub host_attr2string
                 $line_len=$line_len+$len+1;
 
                 if ( $AKey eq $sort ) {
-                   $string.=sprintf "*%-$len.${len}s ", $$refN{$AKey}->{_title};
+                    $string.=sprintf "*%-$len.${len}s ", $$refN{$AKey}->{_title};
                 } else {
-                   $string.=sprintf "%-$len.${len}s ", "$$refN{$AKey}->{_title}";
+                    $string.=sprintf "%-$len.${len}s ", "$$refN{$AKey}->{_title}";
                 }
             }
 	    }
@@ -791,33 +840,29 @@ sub host_attr2string
             }
         }
     } else {
-       # try to sort by site (other attrs to follow)
-       # first try to get a ordered list of attribute values assigned host names
-       my $sortVal;
-       my %GroupedHosts;
-       foreach my $HKey (sort keys %$refH) {
-           $sortVal = $$refH{$HKey} -> {$sort};
-           push(@{$GroupedHosts{$sortVal}}, $HKey);
-           #printf "TST: <%s>\n", $sortVal;
-       }
-       # not ready so far only print the grouped hosts
-       foreach my $sortV (sort keys %GroupedHosts) {
-           #my $StrHosts;
-           #$StrHosts=join(":", @{$GroupedHosts{$sortV}});
-           foreach my $Host (@{$GroupedHosts{$sortV}}) {
-               printf "%-$hclen.${hclen}s ", $Host;
-               foreach my $AKey (sort keys %$refN) {
-                if ($AKey ne "_hosts") {
-                    $len = $$refN{$AKey}->{_length};
-                    $string.=sprintf "%-$len.${len}s ", $$refH{$Host} -> {$AKey};
+        # try to sort by site (other attrs to follow)
+        # first try to get a ordered list of attribute values assigned host names
+        my $sortVal;
+        my %GroupedHosts;
+        foreach my $HKey (sort keys %$refH) {
+            $sortVal = $$refH{$HKey} -> {$sort};
+            push(@{$GroupedHosts{$sortVal}}, $HKey);
+        }
+        # not ready so far only print the grouped hosts
+        foreach my $sortV (sort keys %GroupedHosts) {
+            #$StrHosts=join(":", @{$GroupedHosts{$sortV}});
+            foreach my $Host (@{$GroupedHosts{$sortV}}) {
+                printf "%-$hclen.${hclen}s ", $Host;
+                foreach my $AKey (sort keys %$refN) {
+                    if ($AKey ne "_hosts") {
+                        $len = $$refN{$AKey}->{_length};
+                        $string.=sprintf "%-$len.${len}s ", $$refH{$Host} -> {$AKey};
+                    }
                 }
+                $string.=sprintf "\n";
             }
-            $string.=sprintf "\n";
-           }
-           #printf "TST: <%s> -> <%s>\n", $sortV, $StrHosts;
-       }
+        }
     }
-
     if ( $format eq "tables" ) {
 	    $string.=sprintf "\n";
     }
