Class: Fluent::TelemetryIosxeInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_telemetry_iosxe.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



31
32
33
# File 'lib/fluent/plugin/in_telemetry_iosxe.rb', line 31

def configure(conf)
  super
end

#shutdownObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/fluent/plugin/in_telemetry_iosxe.rb', line 89

def shutdown
  log.info "shutdown ..."
  delete_subscription = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n<delete-subscription xmlns=\"urn:ietf:params:xml:ns:yang:ietf-event-notifications\" xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n<subscription-id>\#{@subscription_id}</subscription-id>\n</delete-subscription>\n</rpc>]]>]]>\n"
  close_session = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n<close-session/>\n</rpc>]]>]]>\n"
  @channel.send_data(delete_subscription)
  @channel.send_data(close_session)
  @ssh.close
  super
end

#startObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fluent/plugin/in_telemetry_iosxe.rb', line 35

def start
  super
  @sigint = false
  trap :INT do
    log.info "got SIGINT ..."
    @sigint = true
  end
  @hello_done = false
  @buffer = ""
  @parser = Nori.new(:parser => @parser, :advanced_typecasting => false)
  hello = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n<capabilities>\n<capability>urn:ietf:params:netconf:base:1.0</capability>\n</capabilities>\n</hello>]]>]]>\n"

  subscription = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n<establish-subscription xmlns=\"urn:ietf:params:xml:ns:yang:ietf-event-notifications\" xmlns:yp=\"urn:ietf:params:xml:ns:yang:ietf-yang-push\">\n<stream>yp:yang-push</stream>\n<yp:xpath-filter>\#{@xpath_filter}</yp:xpath-filter>\n<yp:period>\#{@period}</yp:period>\n</establish-subscription>\n</rpc>\n"
  
  @ssh = Net::SSH.start(@server, @user, :port => @port, :password => @password, :timeout => 10)
  @channel = @ssh.open_channel do |channel|
    channel.subsystem("netconf") do |ch, success|
      raise "subsystem could not be started" unless success
      ch.on_data do |c, data|
        log.debug "on data ..."
        log.debug data
        receive_data(data)
      end
      ch.on_close do |c|
        log.debug "on close ..."
      end
      ch.on_eof do |c|
        log.debug "on eof ..."
      end
      log.info "send hello"
      ch.send_data(hello)
      log.info "send subscription"
      ch.send_data(subscription)
    end
  end
  @ssh.loop(1) { not @sigint } # if we get sigint, we need to end loop 
end