Top Level Namespace

Defined Under Namespace

Modules: Fluent, Google Classes: Class_stats, CounterStats, Counters, CpuMemoryUtilization, CpuMemoryUtilizationPerApplication, CpuMemoryUtilizationSummary, Edge_stats, EgressInterfaceErrors, EgressInterfaceStats, EnterpriseSensors, Ero_ipv4_type, Ero_type_entry, Event_subcode, ExtendedPolicerStats, Fabric_message, FieldType, Firewall, FirewallStats, ForwardingClassAccounting, HierarchicalPolicerStats, IETFSensors, IngressInterfaceErrors, IngressInterfaceStats, InlineJflow, InlineJflowNpuStats, InterfaceExpInfos, InterfaceInfos, InterfaceStats, JuniperNetworksSensors, Key, LogicalInterfaceInfo, LogicalInterfaceQueueStats, LogicalPort, LspStats, LspStatsRecord, Lsp_event, Lsp_mon, Lsp_monitor_data_event, Lsp_monitor_data_property, MemoryLoad, MemoryUsage, NetworkProcessorMemoryUtilization, NetworkProcessorUtilization, NpuMemory, NpuMemoryPartition, NpuMemorySummary, OperationalState, Optics, OpticsDiagLaneStats, OpticsDiagStats, OpticsInfos, PBJOptions, PacketLoad, PacketStatistics, PacketStatsClass, PacketStatsCounter, PacketStatsPacketForwardingEngine, PolicerStats, Port, Port_exp, QueueMonitor, QueueMonitorDirection, QueueMonitorElement, QueueMonitorStats, QueueStats, Rro_ipv4_type, Rro_type_entry, SegmentRoutingIfStats, SegmentRoutingIngIfRecord, SegmentRoutingIngIfStats, SegmentRoutingInterfaceRecord, SegmentRoutingRecord, SegmentRoutingStats, SrStatsPerIfEgress, SrStatsPerIfIngress, SrStatsPerSid, TelemetryFieldOptions, TelemetryStream, Utilization

Instance Method Summary collapse

Instance Method Details

#build_record(type, data_to_build) ⇒ Object



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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/juniper_telemetry_lib.rb', line 36

def build_record(type, data_to_build)

  if type.to_s == 'flat'

    record = {}

    # initialize variables
    name = ""
    sensor_value = ""

    ## Concatene all key/value into a string and stop at "value"
    data_to_build.each do |entry|
      entry.each do |key, value|

        if key == "value"
          sensor_value = value
          next
        end

        if name == ""
          name = key + "." + clean_up_name(value)
        else
          name = name + "." + key + "." + clean_up_name(value)
        end
      end
    end

    record = { name => sensor_value }
    return record

  elsif output_format.to_s == 'structured'

    record = {}
    ## Convert list into Hash
    ## Each entry on the list is a hash with 1 key/value
    data_to_build.each do |entry|
      entry.each do |key, value|
        record[key] = value
      end
    end

    return record

  elsif output_format.to_s == 'statsd'

      record = {}

      # initialize variables
      name = ""
      sensor_value = ""

      ## Concatene all key/value into a string, exclude device & stop at "value"
      data_to_build.each do |entry|
        entry.each do |key, value|

          if key == "value"
            sensor_value = value
            next
          elsif key == "device"
            next
          else
            if name == ""
              name = key + "." + clean_up_name(value)
            else
              name = name + "." + key + "." + clean_up_name(value)
            end
          end
        end
      end

      record[:statsd_type] = 'gauge'
      record[:statsd_key] = name.downcase
      record[:statsd_gauge] = sensor_value

      return record
  else
    $log.warn "Output_format '#{type.to_s}' not supported"
  end
end

#clean_up_name(name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/juniper_telemetry_lib.rb', line 22

def clean_up_name(name)

    ## Create a clean copy of Name and convert to string
    tmp = name.to_s.dup

    ## Clean up device name and interface name to remove restricted caracter
    tmp.gsub!('/', '_')
    tmp.gsub!(':', '_')
    tmp.gsub!('.', '_')
    tmp.gsub!(' ', '_')

    return tmp
end

#epoc_to_sec(epoc) ⇒ Object

Supporting functions ##



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/juniper_telemetry_lib.rb', line 6

def epoc_to_sec(epoc)

  # Check if sec, usec or msec
  nbr_digit = epoc.to_s.size

  if nbr_digit == 10
    return epoc.to_i
  elsif nbr_digit == 13
    return (epoc.to_i/1000).to_i
  elsif nbr_digit == 16
    return (epoc.to_i/1000000).to_i
  end

  return epoc
end

#protobufObject

This file is auto-generated. DO NOT EDIT!



6
# File 'lib/pbj.pb.rb', line 6

require 'protobuf'