<commit_before>module Net
  module SNMP
    class TrapSession < Session
      # == Represents a session for sending SNMP traps

      # +options+
      # * :peername The address where the trap will be sent
      # * :port     The port where the trap will be sent (default = 162)
      def initialize(options = {})
        # Unless the port was supplied in the peername...
        unless options[:peername][":"]
          # ...default to standard trap port
          options[:port] ||= 162
        end

        super(options)
      end

      # Send an SNMPv1 trap
      #
      # Options
      #
      # - enterprise: The Oid of the enterprise
      # - trap_type:  The generic trap type.
      # - specific_type: The specific trap type
      # - uptime: The uptime for this agent
      def trap(options = {})
        pdu = PDU.new(Constants::SNMP_MSG_TRAP)
        options[:enterprise] ||= '1.3.6.1.4.1.3.1.1'  # Default =
        pdu.enterprise = OID.new(options[:enterprise].to_s)
        pdu.trap_type = options[:trap_type].to_i || 1  # need to check all these defaults
        pdu.specific_type = options[:specific_type].to_i || 0
        pdu.time = options[:uptime].to_i || 1
        pdu.agent_addr = options[:agent_addr]
        if options[:varbinds]
          options[:varbinds].each do |vb|
            pdu.add_varbind(vb)
          end
        end
        send_pdu(pdu)
        pdu.free
        nil
      end

      # Send an SNMPv2 trap
      # +options
      # * :oid The Oid of the trap
      # * :varbinds A list of Varbind objects to send with the trap
      def trap_v2(options = {})
        if options[:oid].kind_of?(String)
          options[:oid] = Net::SNMP::OID.new(options[:oid])
        end
        pdu = PDU.new(Constants::SNMP_MSG_TRAP2)
        build_trap_pdu(pdu, options)
        send_pdu(pdu)
      end

      # Send an SNMPv2 inform.  Can accept a callback to execute on confirmation of the inform
      # +options<commit_msg>NOTE: Need to fix v1 trap test<commit_after>module Net
  module SNMP
    class TrapSession < Session
      # == Represents a session for sending SNMP traps

      # +options+
      # * :peername The address where the trap will be sent
      # * :port     The port where the trap will be sent (default = 162)
      def initialize(options = {})
        # Unless the port was supplied in the peername...
        unless options[:peername][":"]
          # ...default to standard trap port
          options[:port] ||= 162
        end

        super(options)
      end

      # Send an SNMPv1 trap
      #
      # Options
      #
      # - enterprise: The Oid of the enterprise
      # - trap_type:  The generic trap type.
      # - specific_type: The specific trap type
      # - uptime: The uptime for this agent
      def trap(options = {})
        pdu = PDU.new(Constants::SNMP_MSG_TRAP)
        options[:enterprise] ||= '1.3.6.1.4.1.3.1.1'  # Default =
        pdu.enterprise = OID.new(options[:enterprise].to_s)
        pdu.trap_type = options[:trap_type].to_i || 1  # need to check all these defaults
        pdu.specific_type = options[:specific_type].to_i || 0
        pdu.time = options[:uptime].to_i || 1
        pdu.agent_addr = options[:agent_addr] || '127.0.0.1'
        if options[:varbinds]
          options[:varbinds].each do |vb|
            pdu.add_varbind(vb)
          end
        end
        send_pdu(pdu)
        pdu.free
        nil
      end

      # Send an SNMPv2 trap
      # +options
      # * :oid The Oid of the trap
      # * :varbinds A list of Varbind objects to send with the trap
      def trap_v2(options = {})
        if options[:oid].kind_of?(String)
          options[:oid] = Net::SNMP::OID.new(options[:oid])
        end
        pdu = PDU.new(Constants::SNMP_MSG_TRAP2)
        build_trap_pdu(pdu, options)
        send_pdu(pdu)
      end

      # Send an SNMPv2 inform.  Can accept a callback to execute on confirmation of the inform
      # +options
{'fraction_non_alphanumeric': 0.10243407707910751, 'fraction_numerical': 0.01343813387423935, 'mean_word_length': 1.9841149773071105, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4983784', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1236, 'n_words': 352}