Ejemplo n.º 1
0
    def __init__(self, host, port, timeout, retries, community):
        """
        Starts a SNMP V2 connection with the given parameters

        Args:
            host (str): The host to interact with SNMP
            port (int): The port on the host
            timeout (int): Non-zero seconds to wait for connection and replies
            retries (int): The number of times to retry a failed query
            community (str): The community string to use

        Returns:
            None: The session is initiated and stored locally
        """

        super(PanoptesSNMPV2Connection, self).__init__(host, port, timeout, retries)
        assert PanoptesValidators.valid_nonempty_string(community), u'community_string must a non-empty string'

        self._community = community

        try:
            self._easy_snmp_session = easysnmp.Session(hostname=self._host, remote_port=self._port,
                                                       timeout=self._timeout, retries=self._retries,
                                                       version=2, use_numeric=True,
                                                       community=self._community)

        except Exception as e:
            raise self._wrap_panoptes_snmp_exception(e)
Ejemplo n.º 2
0
    def __init__(self, host, port, timeout, retries, context, our_identity, their_identity):
        """
        Starts a SNMP V3 connection with the given parameters - works only with TLS

        Args:
            host (str): The host to interact with SNMP
            port (int): The port on the host
            timeout (int): Non-zero seconds to wait for connection and replies
            retries (int): The number of times to retry a failed query
            context (str): A non-empty SNMP v3 context
            our_identity (str): The fingerprint or filename of the certificate to present to the host
            their_identity (str): The fingerprint or filename of the certificate to expect from the host

        Returns:
            None: The session is initiated and stored locally
        """
        super(PanoptesSNMPV3TLSConnection, self).__init__(host, port, timeout, retries)
        assert PanoptesValidators.valid_nonempty_string(context), u'context must be a non-empty string'
        assert PanoptesValidators.valid_nonempty_string(our_identity), u'our_identity must be a non-empty string'
        assert PanoptesValidators.valid_nonempty_string(their_identity), u'their_identity must be a non-empty string'

        self._context = context
        self._our_identity = our_identity
        self._their_identity = their_identity

        try:
            self._easy_snmp_session = easysnmp.Session(hostname=self._host, remote_port=self._port,
                                                       timeout=self._timeout, retries=self._retries,
                                                       version=3, use_numeric=True,
                                                       transport=u'tlstcp',
                                                       context=self._context,
                                                       our_identity=self._our_identity,
                                                       their_identity=self._their_identity)
        except Exception as e:
            raise self._wrap_panoptes_snmp_exception(e)
Ejemplo n.º 3
0
def sess_v3():
    return yahoo_panoptes_snmp.Session(**sess_v3_args())