Index: /branches/rel_apv_10_7/usr/click/bin/debug_monitor/slb_monitor.sh
===================================================================
--- /branches/rel_apv_10_7/usr/click/bin/debug_monitor/slb_monitor.sh	(revision 38743)
+++ /branches/rel_apv_10_7/usr/click/bin/debug_monitor/slb_monitor.sh	(working copy)
@@ -31,3 +31,6 @@
 # insert data into database of tcp syn drop
 /usr/local/bin/python /ca/webui/htdocs/new/src/hive/monitor_log/write_monitor_to_db.py tcpsyndrop
 
+# insert data into database of slb real service group
+/usr/local/bin/python /ca/webui/htdocs/new/src/hive/monitor_log/write_monitor_to_db.py slbrsgroup
+
Index: /branches/rel_apv_10_7/usr/click/bin/webui_storemon/userland_db_sql.h
===================================================================
--- /branches/rel_apv_10_7/usr/click/bin/webui_storemon/userland_db_sql.h	(revision 38743)
+++ /branches/rel_apv_10_7/usr/click/bin/webui_storemon/userland_db_sql.h	(working copy)
@@ -65,6 +65,7 @@
     "CREATE TABLE IF NOT EXISTS PROXGroup (pk varchar(512), time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, hits NUMERIC, session_count NUMERIC, staticsession NUMERIC);",
     "CREATE TABLE IF NOT EXISTS DiametersidGroup (pk varchar(512), time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, hits NUMERIC, session_count NUMERIC, staticsession NUMERIC);",
     "CREATE TABLE IF NOT EXISTS GeneralPersistenceGroup (pk varchar(512), time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, hits NUMERIC, session_count NUMERIC, staticsession NUMERIC);",
+    "CREATE TABLE IF NOT EXISTS OrchestratorGroup (pk varchar(512), time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, hits NUMERIC, session_count NUMERIC, staticsession NUMERIC);",
     "CREATE TABLE IF NOT EXISTS HTTPHealthCheck (pk varchar(512), time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, times_server_up NUMERIC, times_server_down NUMERIC, connections_attempted NUMERIC, connections_succeeded NUMERIC, connections_failed_not_time_out NUMERIC, connections_failed_time_out NUMERIC, sent_attempted_num NUMERIC, send_failed_num NUMERIC, response_received_num NUMERIC, failed_response_time_out NUMERIC, failed_response_not_time_out NUMERIC, failed_read_num NUMERIC, response_match_count NUMERIC, response_mismatch_count NUMERIC);",
     "CREATE TABLE IF NOT EXISTS LDAPHealthCheck (pk varchar(512), time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, times_server_up NUMERIC, times_server_down NUMERIC, connections_attempted NUMERIC, connections_succeeded NUMERIC, connections_failed_not_time_out NUMERIC, connections_failed_time_out NUMERIC, bind_request_sent_num NUMERIC, bind_request_sent_failed_num NUMERIC, search_request_sent_num NUMERIC, search_request_sent_failed_num NUMERIC, bind_response_received_num NUMERIC, bind_response_received_failed_num NUMERIC, bind_failed_num NUMERIC, search_response_received_num NUMERIC, search_response_received_failed_num NUMERIC, search_failed_num NUMERIC, unfull_packets_num NUMERIC);",
     "CREATE TABLE IF NOT EXISTS TCPHealthCheck (pk varchar(512), time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, times_server_up NUMERIC, times_server_down NUMERIC, connections_attempted NUMERIC, connections_succeeded NUMERIC, connections_failed_not_time_out NUMERIC, connections_failed_time_out NUMERIC);",
Index: /branches/rel_apv_10_7/usr/click/webui/htdocs/new/src/hive/monitor_log/write_monitor_to_db.py
===================================================================
--- /branches/rel_apv_10_7/usr/click/webui/htdocs/new/src/hive/monitor_log/write_monitor_to_db.py	(revision 38743)
+++ /branches/rel_apv_10_7/usr/click/webui/htdocs/new/src/hive/monitor_log/write_monitor_to_db.py	(working copy)
@@ -39,11 +39,55 @@
 C_PATH_SYSTEM_INTERFACE_DB   = "/var/crash/graphdb/"
 C_DB_SYSTEM_INTERFACE_STATUS = "SystemInterface"
 
+C_GROUP_DB_MATCH_BY_METHOD = {
+    'rr': 'RRGroup',
+    'grr': 'GRRGroup',
+    'lc': 'LCGroup',
+    'sr': 'SRGroup',
+    'snmp': 'SNMPGroup',
+    'hc': 'HCGroup',
+    'ic': 'ICGroup',
+    'rc': 'RCGroup',
+    'pc': 'PCGroup',
+    'ec': 'ECGroup',
+    'hh': 'HHGroup',
+    'ph': 'PHGroup',
+    'pu': 'PUGroup',
+    'chh': 'CHHGroup',
+    'hq': 'HQGroup',
+    'pi': 'PIGroup',
+    'hi': 'HIGroup',
+    'chi': 'CHIGroup',
+    'hip': 'HIPGroup',
+    'lb': 'LBGroup',
+    'sslsid': 'SSLSIDGroup',
+    'sipcid': 'SIPCIDGroup',
+    'sipuid': 'SIPUIDGroup',
+    'pto': 'PTOGroup',
+    'rdprt': 'RDPRTGroup',
+    'radchu': 'RADCHUGroup',
+    'radchs': 'RADCHSGroup',
+    'radpsun': 'RADPSUNGroup',
+    'sipcidps': 'SIPCIDPSGroup',
+    'sipuidps': 'SIPUIDPSGroup',
+    'tuxedo': 'TUXEDOGroup',
+    'prox': 'PROXGroup',
+    'diametersid': 'DiametersidGroup',
+    'persistence': 'GeneralPersistenceGroup',
+    'orchestrator': 'OrchestratorGroup',
+}
+
+C_L2_GROUP_DB_MATCH_BY_METHOD = {
+    'rr': 'L2RRGroup',
+    'hi': 'L2HIGroup',
+    'chi': 'L2CHIGroup',
+}
+
 def main():
     if len(sys.argv) < 1:
         exit(1)
     type = sys.argv[1]
-    if type not in ['tcpstatus', 'tcpsyndrop', 'sslstatus', 'systeminterface']:
+    if type not in ['tcpstatus', 'tcpsyndrop', 'sslstatus', 'systeminterface', 'slbrsgroup']:
         exit(1)
     if type == "tcpstatus":
         inset_db_tcp_status()
@@ -53,6 +97,8 @@
         insert_db_ssl_status()
     elif type == "systeminterface":
         insert_db_system_interface_status()
+    elif type == "slbrsgroup":
+        insert_db_slb_rs_group()
 
 def inset_db_tcp_status():
     if not os.path.exists(C_PATH_TCP_STATUS_DB):
@@ -503,11 +549,107 @@
     conn.commit()
     conn.close()
 
+def insert_db_slb_rs_group():
+    cmd = '/ca/bin/backend -c "show statistics slb group"'
+    cmd = cmd.encode('utf-8') + chr(252)
+    (status, output) = commands.getstatusoutput(cmd)
+    if status != 0:
+        exit(1)
+    split_newline = output.splitlines()
+    # The first line is title: Group Name, Method, Hits, SessionCount  Staticsession
+    target_content = "\n".join(split_newline[1:])
+    groups = re.findall(r"(?P<group_name>[^\s]+)\s*?(?P<method>\S+).*?(?P<hits>[0-9\-]+)\s*?(?P<session_count>[0-9\-]+)\s*?(?P<staticsession>[0-9\-]+)", target_content, re.DOTALL)
+
+    db_name = C_PATH_SYSTEM_INTERFACE_DB + get_date_for_db_name()
+    conn = sqlite3.connect(db_name)
+    db = conn.cursor()
+    now = int(time.time())
+
+    for entry in groups:
+        if len(entry) < 5:
+            continue
+        # each entry is a tuple
+        grp_method = str(entry[1]).strip()
+        if grp_method not in C_GROUP_DB_MATCH_BY_METHOD:
+            continue
+        matched_table = C_GROUP_DB_MATCH_BY_METHOD[grp_method]
+        grp_name = str(entry[0]).strip()
+        try:
+            db.execute(" ".join(['INSERT INTO %s (' % matched_table,
+                        'pk,',
+                        'time,',
+                        'hits,',
+                        'session_count,',
+                        'staticsession',
+                        ') VALUES (',
+                        '?,',
+                        '?,',
+                        '?,',
+                        '?,',
+                        '?)']),
+                        ("{\"name\": \"%s\"}" % grp_name,
+                        now,
+                        num(entry[2]), # hits
+                        num(entry[3]), # session_count
+                        num(entry[4]))) # staticsession
+        except Exception as ex:
+            print("Cannot insert data into db %s" % matched_table)
+            print(ex)
+    conn.commit()
+    conn.close()
+
+    conn2 = sqlite3.connect(db_name)
+    db2 = conn2.cursor()
+    l2groups_part = re.findall(r"(L2\sGroup\sName\s+Method\s+Hits\s+Drops\n)((?:[^\n]*\n)+)", target_content, re.DOTALL)
+    if len(l2groups_part) > 0 and len(l2groups_part[0]) > 1:
+        target_content2 = l2groups_part[0][1].splitlines()
+        for l2entry in target_content2:
+            l2groups = l2entry.split()
+            if len(l2groups) < 4:
+                continue
+            l2grp_method = str(l2groups[1]).strip()
+            if l2grp_method not in C_L2_GROUP_DB_MATCH_BY_METHOD:
+                continue
+            matched_l2table = C_L2_GROUP_DB_MATCH_BY_METHOD[l2grp_method]
+            l2grp_name = str(l2groups[0]).strip()
+            try:
+                db2.execute(" ".join(['INSERT INTO %s (' % matched_l2table,
+                            'pk,',
+                            'time,',
+                            'hits,',
+                            'drops',
+                            ') VALUES (',
+                            '?,',
+                            '?,',
+                            '?,',
+                            '?)']),
+                            ("{\"name\": \"%s\"}" % l2grp_name,
+                            now,
+                            num(l2groups[2]), # hits
+                            num(l2groups[3]))) # drops
+            except Exception as ex:
+                print("Cannot insert data into db %s" % matched_l2table)
+                print(ex)
+    conn2.commit()
+    conn2.close()
+
 def get_date_for_db_name():
     now = time.asctime( time.localtime(time.time()) )
     now_date = datetime.strptime(now, '%a %b %d %H:%M:%S %Y')
     db_name = now_date.strftime('%Y-%m-%d') + '.db'
     return db_name
 
+def num(s):
+    if not s or s == '-':
+        return 0
+    try:
+        return int(s)
+    except ValueError:
+        try:
+            return float(s)
+        except ValueError:
+            # not a number string
+            return 0
+
 if __name__ == "__main__":
     main()
