Class: SNMPPass::Script::Pass

Inherits:
Object
  • Object
show all
Includes:
SNMPPass::Script
Defined in:
lib/snmp_pass/script/pass.rb

Overview

Handles a script which is invoked using the pass directive in snmpd.conf.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variable_store: SNMPPass::VariableStore.new) ⇒ PassPersist

Create a new pass_Persist.

Parameters:

  • variable_store (VariableStore) (defaults to: SNMPPass::VariableStore.new)

    the variable_store to use for storing the variables


14
15
16
# File 'lib/snmp_pass/script/pass.rb', line 14

def initialize(variable_store: SNMPPass::VariableStore.new)
  @variable_store = variable_store
end

Instance Attribute Details

#variable_storeObject (readonly)

Returns the value of attribute variable_store


8
9
10
# File 'lib/snmp_pass/script/pass.rb', line 8

def variable_store
  @variable_store
end

Instance Method Details

#runObject

Parse the command line and do the required action.


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/snmp_pass/script/pass.rb', line 19

def run
  # Do not buffer stdout
  STDOUT.sync = true

  command = ARGV.shift
  case command
    when '-g'
      get ARGV[0]
    when '-n'
      get_next ARGV[0]
    when '-s'
      set(*ARGV[0..2])
    else
      fail SNMPPass::Error::UnknownCommand, "Unknown command: #{command}"
  end
end