Пример #1
0
    def from_json(cls, serialized: Dict[str, Any]) -> 'SNMPFetcher':
        # The SNMPv3 configuration is represented by a tuple of different lengths (see
        # SNMPCredentials). Since we just deserialized from JSON, we have to convert the
        # list used by JSON back to a tuple.
        # SNMPv1/v2 communities are represented by a string: Leave it untouched.
        if isinstance(serialized["snmp_config"]["credentials"], list):
            serialized["snmp_config"]["credentials"] = tuple(
                serialized["snmp_config"]["credentials"])

        return cls(
            file_cache=SNMPFileCache.from_json(serialized.pop("file_cache")),
            snmp_section_trees={
                SectionName(name): [SNMPTree.from_json(tree) for tree in trees
                                   ] for name, trees in serialized["snmp_section_trees"].items()
            },
            snmp_section_detects=[
                (
                    SectionName(name),
                    # The cast is necessary as mypy does not infer types in a list comprehension.
                    # See https://github.com/python/mypy/issues/5068
                    SNMPDetectSpec([[cast(SNMPDetectAtom, tuple(inner))
                                     for inner in outer]
                                    for outer in specs]),
                )
                for name, specs in serialized["snmp_section_detects"]
            ],
            configured_snmp_sections={
                SectionName(name) for name in serialized["configured_snmp_sections"]
            },
            on_error=serialized["on_error"],
            missing_sys_description=serialized["missing_sys_description"],
            use_snmpwalk_cache=serialized["use_snmpwalk_cache"],
            snmp_config=SNMPHostConfig(**serialized["snmp_config"]),
        )
Пример #2
0
 def deserialize(cls, serialized: Dict[str, Any]) -> "SNMPPluginStoreItem":
     try:
         return cls(
             [SNMPTree.from_json(tree) for tree in serialized["trees"]],
             SNMPDetectSpec.from_json(serialized["detect_spec"]),
         )
     except (LookupError, TypeError, ValueError) as exc:
         raise ValueError(serialized) from exc
Пример #3
0
 def from_json(cls, serialized: Dict[str, Any]) -> 'SNMPDataFetcher':
     return cls(
         {
             name: [SNMPTree.from_json(tree) for tree in trees]
             for name, trees in serialized["oid_infos"].items()
         },
         serialized["use_snmpwalk_cache"],
         SNMPHostConfig(**serialized["snmp_config"]),
     )
Пример #4
0
 def from_json(cls, serialized: Dict[str, Any]) -> 'SNMPFetcher':
     return cls(
         SNMPFileCache.from_json(serialized.pop("file_cache")),
         {
             SectionName(name): [SNMPTree.from_json(tree) for tree in trees
                                ] for name, trees in serialized["oid_infos"].items()
         },
         serialized["use_snmpwalk_cache"],
         SNMPHostConfig(**serialized["snmp_config"]),
     )
Пример #5
0
 def from_json(cls, serialized: Dict[str, Any]) -> 'SNMPFetcher':
     return cls(
         file_cache=SNMPFileCache.from_json(serialized.pop("file_cache")),
         snmp_section_trees={
             SectionName(name): [SNMPTree.from_json(tree) for tree in trees
                                ] for name, trees in serialized["snmp_section_trees"].items()
         },
         snmp_section_detects=[
             (SectionName(name), specs) for name, specs in serialized["snmp_section_detects"]
         ],
         configured_snmp_sections={
             SectionName(name) for name in serialized["configured_snmp_sections"]
         },
         on_error=serialized["on_error"],
         missing_sys_description=serialized["missing_sys_description"],
         use_snmpwalk_cache=serialized["use_snmpwalk_cache"],
         snmp_config=SNMPHostConfig(**serialized["snmp_config"]),
     )