summaryrefslogtreecommitdiffstats
path: root/pnda-ztt-app/src/test/scala/com/cisco/ztt/cisco/telemetry/xr/TelemetryMapperTest.scala
blob: b133c9e4f410abcc904ac87bb38c82a2536313b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
88
89
90
91
92
93
94
95
/*
 * Copyright (c) 2018 Cisco Systems. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cisco.ztt.cisco.telemetry.xr

import org.scalatest.FlatSpec
import org.scalatest.Matchers
import com.cisco.ztt.cisco.xr.telemetry.TimeseriesMapper
import com.cisco.ztt.meta.YamlReader
import com.cisco.ztt.cisco.xr.telemetry.JsonParser

class TelemetryMapperTest extends FlatSpec with Matchers {

    val ipv6_yaml = """
input_topic: telemetry.avro
output_topic: timeseries
timeseries_namespace: ipv6

xr_telemetry:
  - path: Cisco-IOS-XR-ipv6-io-oper:ipv6-io/nodes/node/statistics/traffic
    keys:
      - name: node-name
        display_name: "Node Name"
    content:
      - name: ipv6.total-packets
        display_name: "Total IPV6 Packets"
        ts_name: total-ipv6-packets

      - name: icmp.total-messages
        display_name: "Total ICMP Messages"
"""

    val ipv6_json = """
{
  "Source": "172.16.1.157:56197",
  "Telemetry": {
    "node_id_str": "IOS-XRv9k-edge-1",
    "subscription_id_str": "ipv6-io",
    "encoding_path": "Cisco-IOS-XR-ipv6-io-oper:ipv6-io/nodes/node/statistics/traffic",
    "collection_id": 282962,
    "collection_start_time": 1506008887021,
    "msg_timestamp": 1506008887021,
    "collection_end_time": 1506008887039
  },
  "Rows": [
    {
      "Timestamp": 1506008887031,
      "Keys": {
        "node-name": "0/RP0/CPU0"
      },
      "Content": {
        "icmp": {
          "output-messages": 0,
          "total-messages": 4,
          "unknown-error-type-messages": 0
        },
        "ipv6": {
          "bad-header-packets": 0,
          "total-packets": 12,
          "unknown-protocol-packets": 0
        },
        "ipv6-node-discovery": {
          "received-redirect-messages": 0,
          "sent-redirect-messages": 0
        }
      }
    }
  ]
}
"""

    "TelemetryMapper" should "Map to wanted timeseries values" in {
        val meta = YamlReader.parse(ipv6_yaml)
        val mapper = new TimeseriesMapper(meta.xr_telemetry(0), "demo")

        val event = JsonParser.parse(ipv6_json)
        val timeseries = mapper.transform(event).toList

        timeseries.length should be (2)
        timeseries(0).metric should be ("demo.icmp.total-messages")
        timeseries(1).metric should be ("demo.total-ipv6-packets")
    }
}