import coshsh
from coshsh.monitoringdetail import MonitoringDetail

def __detail_ident__(params={}):
    if params["monitoring_type"] == "KEYVALUES":
        return MonitoringDetailKeyvalues
    elif params["monitoring_type"] == "KEYVALUESARRAY":
        return MonitoringDetailKeyvaluesArray


class MonitoringDetailKeyvalues(coshsh.monitoringdetail.MonitoringDetail):
    """
    """
    property = "generic"
    property_type = dict

    def __init__(self, params):
        self.monitoring_type = params["monitoring_type"]
        self.dictionary = { }
        try:
            self.dictionary[params["monitoring_0"]] = params["monitoring_1"]
        except Exception:
            pass
        try:
            self.dictionary[params["monitoring_2"]] = params["monitoring_3"]
        except Exception:
            pass
        try:
            self.dictionary[params["monitoring_4"]] = params["monitoring_5"]
        except Exception:
            pass


class MonitoringDetailKeyvaluesArray(coshsh.monitoringdetail.MonitoringDetail):
    """
    KEYVALUESARRAY, role, dach
    KEYVALUESARRAY, role, master, parents, "sw1"
    KEYVALUESARRAY, role, dmz, role, prod, parents, "sw2"
    -> application.role = [dach, master, dmz, prod]
    -> application.parents = [sw1, sw2]
    """
    property = "generic"
    property_type = list

    def __init__(self, params):
        self.monitoring_type = params["monitoring_type"]
        self.dictionary = { }
        try:
            self.dictionary[params["monitoring_0"]].append(params["monitoring_1"])
        except Exception:
            self.dictionary[params["monitoring_0"]] = [params["monitoring_1"]]
        try:
            self.dictionary[params["monitoring_2"]].append(params["monitoring_3"])
        except Exception:
            self.dictionary[params["monitoring_2"]] = [params["monitoring_3"]]
        try:
            self.dictionary[params["monitoring_4"]].append(params["monitoring_5"])
        except Exception:
            self.dictionary[params["monitoring_4"]] = [params["monitoring_5"]]


@@ -1761,32 +1761,53 @@
 cept Exception:%0A
+            try:%0A    
             self
@@ -1865,24 +1865,75 @@
 toring_3%22%5D%5D%0A
+            except Exception:%0A                pass%0A
         try:
@@ -2034,32 +2034,53 @@
 cept Exception:%0A
+            try:%0A    
             self
@@ -2141,10 +2141,61 @@
 ing_5%22%5D%5D
+%0A            except Exception:%0A                pass
 %0A%0A

make detail KEYVALUESARRAY more robust