diff --git a/broadview_collector/config/broadviewcollector.conf b/broadview_collector/config/broadviewcollector.conf index 81f5aa7..baef5bc 100644 --- a/broadview_collector/config/broadviewcollector.conf +++ b/broadview_collector/config/broadviewcollector.conf @@ -44,3 +44,13 @@ port: 8082 #auth_url: http://127.0.0.1:35357/v3 #endpoint: http://127.0.0.1:8070/v2.0 #api_version: 2_0 + +# uncomment for stacklight + +#[stacklight] + +# ip address and port of Heka HttpListenInput plugin + +#ip_address: 172.16.170.184 +#port: 8088 + diff --git a/broadview_collector/plugins/stacklight.py b/broadview_collector/plugins/stacklight.py new file mode 100644 index 0000000..38f0789 --- /dev/null +++ b/broadview_collector/plugins/stacklight.py @@ -0,0 +1,66 @@ +# (C) Copyright Broadcom Corporation 2016 +# +# 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. + +from broadviewpublisherbase import BroadViewPublisherBase +from broadview_collector.serializers.bst_to_stacklight import BSTToStacklight +import json +import ConfigParser +import requests + +from oslo_log import log + +LOG = log.getLogger(__name__) + +class BroadViewPublisher(BroadViewPublisherBase): + + def readConfig(self): + self._ipaddr = "127.0.0.1" + self._port = 8088 + self._timeout = 0.5 + try: + bvcfg = ConfigParser.ConfigParser() + bvcfg.read("/etc/broadviewcollector.conf") + self._ipaddr = bvcfg.get("stacklight", "ip_address") + self._port = bvcfg.get("stacklight", "port") + self._timeout = bvcfg.get("stacklight", "timeout") + except: + LOG.error("BroadViewPublisher: unable to read configuration") + + def __init__(self): + self.readConfig() + + def publish(self, host, data): + code = 500 + success, sdata = BSTToStacklight().serialize(host, data) + if success: + sdata = json.loads(sdata) + for x in sdata: + try: + r = requests.post('http://{}:{}'.format(self._ipaddr, self._port), json=sdata, timeout=self._timeout) + code = r.status_code + except requests.exceptions.Timeout: + LOG.error('BroadViewPublisher timeout {} seconds {}:{}'.format(self._timeout, self._ipaddr, self._port)) + code = 500 + break + except requests.exceptions.RequestException as e: + LOG.error('BroadViewPublisher {} {}:{}'.format(e, self._ipaddr, self._port)) + code = 500 + break + if r.status_code != 200: + LOG.error('BroadViewPublisher received {}'.format(r.status_code)) + break + return code + + def __repr__(self): + return "BroadView Stacklight Publisher" diff --git a/broadview_collector/serializers/bst_to_stacklight.py b/broadview_collector/serializers/bst_to_stacklight.py new file mode 100644 index 0000000..d5ac9b3 --- /dev/null +++ b/broadview_collector/serializers/bst_to_stacklight.py @@ -0,0 +1,2253 @@ +# (C) Copyright Broadcom Corporation 2016 +# +# 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. + +from broadviewserializerbase import BroadViewSerializerBase +from broadview_lib.bst.bst_parser import BSTParser, ReportTypes +import json +import unittest +import datetime +import time + +class BSTToStacklight(BroadViewSerializerBase): + ''' + Class that converts BST object model to Stacklight metrics + ''' + + def __init__(self): + pass + + def __serializeToJSON(self, host, report, data): + ret = [] + timestamp = time.mktime(data.getTimestamp()) * 1000 + asic = data.getASICId() + x = data.getDeviceData() + + if x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["value"] = x.getValue() + ret.append(m) + + d = data.getIngressPortPriorityGroup() + for x in d: + for y in x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["port"] = y.getPort() + m["priority-group"] = y.getPriorityGroup() + m["metric"] = "um-share-buffer-count" + m["value"] = y.getUmShareBufferCount() + ret.append(m) + + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["port"] = y.getPort() + m["priority-group"] = y.getPriorityGroup() + m["metric"] = "um-headroom-buffer-count" + m["value"] = y.getUmHeadroomBufferCount() + ret.append(m) + + d = data.getIngressPortServicePool() + for x in d: + for y in x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["port"] = y.getPort() + m["service-pool"] = y.getServicePool() + m["metric"] = "um-share-buffer-count" + m["value"] = y.getUmShareBufferCount() + ret.append(m) + + d = data.getIngressServicePool() + for x in d: + for y in x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["service-pool"] = y.getServicePool() + m["metric"] = "um-share-buffer-count" + m["value"] = y.getUmShareBufferCount() + ret.append(m) + + d = data.getEgressCPUQueue() + for x in d: + for y in x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["queue"] = y.getQueue() + m["metric"] = "cpu-buffer-count" + m["value"] = y.getCPUBufferCount() + ret.append(m) + + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["queue"] = y.getQueue() + m["metric"] = "cpu-queue-entries" + m["value"] = y.getCPUQueueEntries() + ret.append(m) + + d = data.getEgressMcQueue() + for x in d: + for y in x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["port"] = y.getPort() + m["queue"] = y.getQueue() + m["metric"] = "mc-buffer-count" + m["value"] = y.getMCBufferCount() + ret.append(m) + + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["bv-agent"] = host + m["asic-id"] = asic + m["port"] = y.getPort() + m["queue"] = y.getQueue() + m["metric"] = "mc-queue-entries" + m["value"] = y.getMCQueueEntries() + ret.append(m) + + d = data.getEgressPortServicePool() + for x in d: + for y in x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["bv-agent"] = host + m["asic-id"] = asic + m["port"] = y.getPort() + m["service-pool"] = y.getServicePool() + m["metric"] = "um-share-buffer-count" + m["value"] = y.getUmShareBufferCount() + ret.append(m) + + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["port"] = y.getPort() + m["service-pool"] = y.getServicePool() + m["metric"] = "mc-share-buffer-count" + m["value"] = y.getMCShareBufferCount() + ret.append(m) + + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["port"] = y.getPort() + m["service-pool"] = y.getServicePool() + m["metric"] = "mc-share-queue-entries" + m["value"] = y.getMCShareQueueEntries() + ret.append(m) + + d = data.getEgressRQEQueue() + for x in d: + for y in x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["queue"] = y.getQueue() + m["metric"] = "rqe-buffer-count" + m["value"] = y.getRQEBufferCount() + ret.append(m) + + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["queue"] = y.getQueue() + m["metric"] = "rqe-queue-entries" + m["value"] = y.getRQEQueueEntries() + ret.append(m) + + d = data.getEgressServicePool() + for x in d: + for y in x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["service-pool"] = y.getServicePool() + m["metric"] = "um-share-buffer-count" + m["value"] = y.getUmShareBufferCount() + ret.append(m) + + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["service-pool"] = y.getServicePool() + m["metric"] = "mc-share-buffer-count" + m["value"] = y.getMCShareBufferCount() + ret.append(m) + + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["service-pool"] = y.getServicePool() + m["metric"] = "mc-share-queue-entries" + m["value"] = y.getMCShareQueueEntries() + ret.append(m) + + d = data.getEgressUcQueue() + for x in d: + for y in x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["port"] = y.getPort() + m["queue"] = y.getQueue() + m["metric"] = "uc-queue-buffer-count" + m["value"] = y.getUcQueueBufferCount() + ret.append(m) + + d = data.getEgressUcQueueGroup() + for x in d: + for y in x: + m = {} + m["entity"] = "broadview-bst" + m["name"] = repr(x) + m["timestamp"] = timestamp + m["asic-id"] = asic + m["bv-agent"] = host + m["queue-group"] = y.getQueueGroup() + m["metric"] = "uc-buffer-count" + m["value"] = y.getUcBufferCount() + ret.append(m) + + return json.dumps(ret) + + def _toReport(self, host, data): + return self.__serializeToJSON(host, "bst-report", data) + + def _toTrigger(self, host, data): + return self.__serializeToJSON(host, "bst-trigger", data) + + def _toThreshold(self, host, data): + return self.__serializeToJSON(host, "bst-thresholds", data) + + def serialize(self, host, data): + # serialize a parsed BST report to Monasca mtrics + ret = (False, None) + + rpt = data.getReportType() + + s = None + if rpt == ReportTypes.Report: + s = self._toReport(host, data) + elif rpt == ReportTypes.Trigger: + s = self._toTrigger(host, data) + elif rpt == ReportTypes.Threshold: + s = self._toThreshold(host, data) + + if s: + ret = (True, s) + + return ret + + def __repr__(self): + return "BST To Stacklight Serializer" + +class TestSerializer(unittest.TestCase): + + def setUp(self): + self._host = "127.0.0.1" + self.bst_report1 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "device", + "data": 46 + }] + } + + self.bst_report2 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "ingress-port-priority-group", + "data": [{ + "port": "2", + "data": [[5, 45500, 44450]] + }, { + "port": "3", + "data": [[6, 25500, 24450]] + }] + }] + } + + self.bst_report3 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "ingress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 324]] + }, { + "port": "3", + "data": [[6, 366]] + }] + }] + } + + self.bst_report4 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "ingress-service-pool", + "data": [[1, 3240], [2, 3660]] + }] + } + + self.bst_report5 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "egress-cpu-queue", + "data": [[3, 4566, 0]] + }] + } + + self.bst_report6 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "egress-mc-queue", + "data": [[1, "1", 34, 89], [2, "4", 1244, 0], [3, "5", 0, +3]] + }] + } + + self.bst_report7 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "egress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 0, 324, 0]] + }, { + "port": "3", + "data": [[6, 0, 366, 0]] + }] + }] + } + + self.bst_report8 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "egress-rqe-queue", + "data": [[2, 3333, 4444], [5, 25, 45]] + }] + } + + self.bst_report9 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "egress-service-pool", + "data": [[2, 0, 0, 3240], [3, 3660, 0, 0]] + }] + } + + self.bst_report10 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "egress-uc-queue", + "data": [[6, "0", 1111]] + }] + } + + self.bst_report11 = { + "jsonrpc": "2.0", + "method": "get-bst-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:15:04 ", + "report": [ + { + "realm": "egress-uc-queue-group", + "data": [[6, 2222]] + }] + } + + + self.trigger1 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "device", + "data": 46 + }] + } + + self.trigger2 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "ingress-port-priority-group", + + "data": [{ + "port": "2", + "data": [[5, 45500, 44450]] + }, { + "port": "3", + "data": [[6, 25500, 24450]] + }] + }] + } + + self.trigger3 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "ingress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 324]] + }, { + "port": "3", + "data": [[6, 366]] + }] + }] + } + + self.trigger4 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "ingress-service-pool", + "data": [[1, 3240], [2, 3660]] + }] + } + + self.trigger5 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "egress-cpu-queue", + "data": [[3, 4566, 0]] + }] + } + + self.trigger6 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "egress-mc-queue", + "data": [[1, "1", 34, 89], [2, "4", 1244, 0], [3, "5", 0, +3]] + }] + } + + self.trigger7 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "egress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 0, 324, 0]] + }, { + "port": "3", + "data": [[6, 0, 366, 0]] + }] + }] + } + + self.trigger8 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "egress-rqe-queue", + "data": [[2, 3333, 4444], [5, 25, 45]] + }] + } + + self.trigger9 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "egress-service-pool", + "data": [[2, 0, 0, 3240], [3, 3660, 0, 0]] + }] + } + + self.trigger10 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "egress-uc-queue", + "data": [[6, "0", 1111]] + }] + } + + self.trigger11 = { + "jsonrpc": "2.0", + "method": "trigger-report", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-18 - 00:13:08 ", + "realm": "ingress-port-priority-group", + "counter": "um-share-buffer-count", + "port": "2", + "priority-group": "5", + "report": [ + { + "realm": "egress-uc-queue-group", + "data": [[6, 2222]] + }] + } + + + self.thresholds1 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "device", + "data": 46 + }] + } + + self.thresholds2 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "ingress-port-priority-group", + "data": [{ + "port": "2", + "data": [[5, 45500, 44450]] + }, { + "port": "3", + "data": [[6, 25500, 24450]] + }] + }] + } + + self.thresholds3 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "ingress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 324]] + }, { + "port": "3", + "data": [[6, 366]] + }] + }] + } + + self.thresholds4 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "ingress-service-pool", + "data": [[1, 3240], [2, 3660]] + }] + } + + self.thresholds5 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "egress-cpu-queue", + "data": [[3, 4566, 0]] + }] + } + + self.thresholds6 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "egress-mc-queue", + "data": [[1, "1", 34, 89], [2, "4", 1244, 0], [3, "5", 0, 3]] + }] + } + + self.thresholds7 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "egress-port-service-pool", + "data": [{ + "port": "2", + "data": [[5, 0, 324, 0]] + }, { + "port": "3", + "data": [[6, 0, 366, 0]] + }] + }] + } + + self.thresholds8 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "egress-rqe-queue", + "data": [[2, 3333, 4444], [5, 25, 45]] + }] + } + + self.thresholds9 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "egress-service-pool", + "data": [[2, 0, 0, 3240], [3, 3660, 0, 0]] + }] + } + + self.thresholds10 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "egress-uc-queue", + "data": [[6, "0", 1111]] + }] + } + + self.thresholds11 = { + "jsonrpc": "2.0", + "method": "get-bst-thresholds", + "asic-id": "20", + "version": "1", + "time-stamp": "2014-11-14 - 00:15:04 ", + "report": [ + { + "realm": "egress-uc-queue-group", + "data": [[6, 2222]] + }] + } + + + def test_bst_report1(self): + rep = BSTParser() + rep.process(self.bst_report1) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 1) + data = data[0] + self.assertTrue("timestamp" in data) + data["timestamp"] = data["timestamp"] / 1000 + self.assertTrue("entity" in data) + self.assertTrue(data["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in data) + self.assertTrue("name" in data) + self.assertTrue("value" in data) + t1 = datetime.datetime.fromtimestamp(int(data["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = self.bst_report1["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(data["name"], "device") + self.assertEqual(data["value"], 46) + self.assertTrue("asic-id" in data) + self.assertEqual(data["asic-id"], self.bst_report1["asic-id"]) + + + def test_bst_report2(self): + rep = BSTParser() + rep.process(self.bst_report2) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 4) + i = 0 + y = self.bst_report2 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "ingress-port-priority-group") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("priority-group" in x) + self.assertTrue("port" in x) + if x["port"] == "2": + self.assertEqual(x["priority-group"], 5) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 45500) + elif x["metric"] == "um-headroom-buffer-count": + self.assertTrue(x["value"] == 44450) + else: + self.assertTrue(x["metric"] == True) + elif x["port"] == "3": + self.assertEqual(x["priority-group"], 6) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 25500) + elif x["metric"] == "um-headroom-buffer-count": + self.assertTrue(x["value"] == 24450) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["port"] == True) + + + def test_bst_report3(self): + rep = BSTParser() + rep.process(self.bst_report3) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 2) + i = 0 + y = self.bst_report3 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + self.assertTrue("name" in x) + self.assertTrue("metric" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"]) / 1000) + x["timestamp"] = x["timestamp"] / 1000 + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "ingress-port-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + self.assertTrue("port" in x) + if x["port"] == "2": + self.assertEqual(x["service-pool"], 5) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 324) + else: + self.assertTrue(x["metric"] == True) + elif x["port"] == "3": + self.assertEqual(x["service-pool"], 6) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 366) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["port"] == True) + + def test_bst_report4(self): + rep = BSTParser() + rep.process(self.bst_report4) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 2) + i = 0 + y = self.bst_report4 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("metric" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "ingress-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + if x["service-pool"] == 1: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 3240) + else: + self.assertTrue(x["metric"] == True) + elif x["service-pool"] == 2: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 3660) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["service-pool"] == True) + + + def test_bst_report5(self): + rep = BSTParser() + rep.process(self.bst_report5) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 2) + i = 0 + y = self.bst_report5 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + self.assertTrue("entity" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-cpu-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + if x["queue"] == 3: + if x["metric"] == "cpu-buffer-count": + self.assertTrue(x["value"] == 4566) + elif x["metric"] == "cpu-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_bst_report6(self): + rep = BSTParser() + rep.process(self.bst_report6) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 6) + i = 0 + y = self.bst_report6 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("metric" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-mc-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + self.assertTrue("port" in x) + if x["queue"] == 1: + self.assertTrue(x["port"] == "1") + if x["metric"] == "mc-buffer-count": + self.assertTrue(x["value"] == 34) + elif x["metric"] == "mc-queue-entries": + self.assertTrue(x["value"] == 89) + else: + self.assertTrue(x["metric"] == True) + elif x["queue"] == 2: + self.assertTrue(x["port"] == "4") + if x["metric"] == "mc-buffer-count": + self.assertTrue(x["value"] == 1244) + elif x["metric"] == "mc-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + elif x["queue"] == 3: + self.assertTrue(x["port"] == "5") + if x["metric"] == "mc-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-queue-entries": + self.assertTrue(x["value"] == 3) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_bst_report7(self): + rep = BSTParser() + rep.process(self.bst_report7) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 6) + i = 0 + y = self.bst_report7 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + self.assertTrue("entity" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-port-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + self.assertTrue("port" in x) + if x["service-pool"] == 5: + self.assertTrue(x["port"] == "2") + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 324) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + elif x["service-pool"] == 6: + self.assertTrue(x["port"] == "3") + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 366) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["service-pool"] == True) + + def test_bst_report8(self): + rep = BSTParser() + rep.process(self.bst_report8) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 4) + i = 0 + y = self.bst_report8 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + self.assertTrue("entity" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-rqe-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + if x["queue"] == 2: + if x["metric"] == "rqe-buffer-count": + self.assertTrue(x["value"] == 3333) + elif x["metric"] == "rqe-queue-entries": + self.assertTrue(x["value"] == 4444) + else: + self.assertTrue(x["metric"] == True) + elif x["queue"] == 5: + if x["metric"] == "rqe-buffer-count": + self.assertTrue(x["value"] == 25) + elif x["metric"] == "rqe-queue-entries": + self.assertTrue(x["value"] == 45) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_bst_report9(self): + rep = BSTParser() + rep.process(self.bst_report9) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 6) + i = 0 + y = self.bst_report9 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + self.assertTrue("entity" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + if x["service-pool"] == 2: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 3240) + else: + self.assertTrue(x["metric"] == True) + elif x["service-pool"] == 3: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 3660) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["service-pool"] == True) + + def test_bst_report10(self): + rep = BSTParser() + rep.process(self.bst_report10) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 1) + i = 0 + y = self.bst_report10 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + self.assertTrue("entity" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-uc-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + self.assertTrue("port" in x) + if x["queue"] == 6: + self.assertEqual(x["port"], "0") + if x["metric"] == "uc-queue-buffer-count": + self.assertTrue(x["value"] == 1111) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_bst_report11(self): + rep = BSTParser() + rep.process(self.bst_report11) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 1) + i = 0 + y = self.bst_report11 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + self.assertTrue("entity" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-uc-queue-group") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue-group" in x) + if x["queue-group"] == 6: + if x["metric"] == "uc-buffer-count": + self.assertTrue(x["value"] == 2222) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue-group"] == True) + + def test_trigger1(self): + rep = BSTParser() + rep.process(self.trigger1) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 1) + data = data[0] + self.assertTrue("timestamp" in data) + data["timestamp"] = data["timestamp"] / 1000 + self.assertTrue("name" in data) + self.assertTrue("value" in data) + self.assertTrue("entity" in data) + self.assertTrue(data["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in data) + t1 = datetime.datetime.fromtimestamp(int(data["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = self.trigger1["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(data["name"], "device") + self.assertEqual(data["value"], 46) + self.assertTrue("asic-id" in data) + self.assertEqual(data["asic-id"], self.trigger1["asic-id"]) + + + def test_trigger2(self): + rep = BSTParser() + rep.process(self.trigger2) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 4) + i = 0 + y = self.trigger2 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "ingress-port-priority-group") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("priority-group" in x) + self.assertTrue("port" in x) + if x["port"] == "2": + self.assertEqual(x["priority-group"], 5) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 45500) + elif x["metric"] == "um-headroom-buffer-count": + self.assertTrue(x["value"] == 44450) + else: + self.assertTrue(x["metric"] == True) + elif x["port"] == "3": + self.assertEqual(x["priority-group"], 6) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 25500) + elif x["metric"] == "um-headroom-buffer-count": + self.assertTrue(x["value"] == 24450) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["port"] == True) + + + def test_trigger3(self): + rep = BSTParser() + rep.process(self.trigger3) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 2) + i = 0 + y = self.trigger3 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "ingress-port-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + self.assertTrue("port" in x) + if x["port"] == "2": + self.assertEqual(x["service-pool"], 5) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 324) + else: + self.assertTrue(x["metric"] == True) + elif x["port"] == "3": + self.assertEqual(x["service-pool"], 6) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 366) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["port"] == True) + + def test_trigger4(self): + rep = BSTParser() + rep.process(self.trigger4) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 2) + i = 0 + y = self.trigger4 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "ingress-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + if x["service-pool"] == 1: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 3240) + else: + self.assertTrue(x["metric"] == True) + elif x["service-pool"] == 2: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 3660) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["service-pool"] == True) + + + def test_trigger5(self): + rep = BSTParser() + rep.process(self.trigger5) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 2) + i = 0 + y = self.trigger5 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-cpu-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + if x["queue"] == 3: + if x["metric"] == "cpu-buffer-count": + self.assertTrue(x["value"] == 4566) + elif x["metric"] == "cpu-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_trigger6(self): + rep = BSTParser() + rep.process(self.trigger6) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 6) + i = 0 + y = self.trigger6 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-mc-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + self.assertTrue("port" in x) + if x["queue"] == 1: + self.assertTrue(x["port"] == "1") + if x["metric"] == "mc-buffer-count": + self.assertTrue(x["value"] == 34) + elif x["metric"] == "mc-queue-entries": + self.assertTrue(x["value"] == 89) + else: + self.assertTrue(x["metric"] == True) + elif x["queue"] == 2: + self.assertTrue(x["port"] == "4") + if x["metric"] == "mc-buffer-count": + self.assertTrue(x["value"] == 1244) + elif x["metric"] == "mc-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + elif x["queue"] == 3: + self.assertTrue(x["port"] == "5") + if x["metric"] == "mc-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-queue-entries": + self.assertTrue(x["value"] == 3) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_trigger7(self): + rep = BSTParser() + rep.process(self.trigger7) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 6) + i = 0 + y = self.trigger7 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-port-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + self.assertTrue("port" in x) + if x["service-pool"] == 5: + self.assertTrue(x["port"] == "2") + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 324) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + elif x["service-pool"] == 6: + self.assertTrue(x["port"] == "3") + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 366) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["service-pool"] == True) + + def test_trigger8(self): + rep = BSTParser() + rep.process(self.trigger8) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 4) + i = 0 + y = self.trigger8 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-rqe-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + if x["queue"] == 2: + if x["metric"] == "rqe-buffer-count": + self.assertTrue(x["value"] == 3333) + elif x["metric"] == "rqe-queue-entries": + self.assertTrue(x["value"] == 4444) + else: + self.assertTrue(x["metric"] == True) + elif x["queue"] == 5: + if x["metric"] == "rqe-buffer-count": + self.assertTrue(x["value"] == 25) + elif x["metric"] == "rqe-queue-entries": + self.assertTrue(x["value"] == 45) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_trigger9(self): + rep = BSTParser() + rep.process(self.trigger9) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 6) + i = 0 + y = self.trigger9 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + if x["service-pool"] == 2: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 3240) + else: + self.assertTrue(x["metric"] == True) + elif x["service-pool"] == 3: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 3660) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["service-pool"] == True) + + def test_trigger10(self): + rep = BSTParser() + rep.process(self.trigger10) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 1) + i = 0 + y = self.trigger10 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-uc-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + self.assertTrue("port" in x) + if x["queue"] == 6: + self.assertEqual(x["port"], "0") + if x["metric"] == "uc-queue-buffer-count": + self.assertTrue(x["value"] == 1111) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_trigger11(self): + rep = BSTParser() + rep.process(self.trigger11) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 1) + i = 0 + y = self.trigger11 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("entity" in x) + self.assertTrue("metric" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-uc-queue-group") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue-group" in x) + if x["queue-group"] == 6: + if x["metric"] == "uc-buffer-count": + self.assertTrue(x["value"] == 2222) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue-group"] == True) + + def test_thresholds1(self): + rep = BSTParser() + rep.process(self.thresholds1) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 1) + data = data[0] + self.assertTrue("timestamp" in data) + data["timestamp"] = data["timestamp"] / 1000 + self.assertTrue("name" in data) + self.assertTrue("value" in data) + self.assertTrue("entity" in data) + self.assertTrue(data["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in data) + t1 = datetime.datetime.fromtimestamp(int(data["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = self.thresholds1["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(data["name"], "device") + self.assertEqual(data["value"], 46) + self.assertTrue("asic-id" in data) + self.assertEqual(data["asic-id"], self.thresholds1["asic-id"]) + + + def test_thresholds2(self): + rep = BSTParser() + rep.process(self.thresholds2) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 4) + i = 0 + y = self.thresholds2 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + self.assertTrue("entity" in x) + self.assertTrue(x["entity"] == "broadview-bst") + self.assertTrue("bv-agent" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "ingress-port-priority-group") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("priority-group" in x) + self.assertTrue("port" in x) + if x["port"] == "2": + self.assertEqual(x["priority-group"], 5) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 45500) + elif x["metric"] == "um-headroom-buffer-count": + self.assertTrue(x["value"] == 44450) + else: + self.assertTrue(x["metric"] == True) + elif x["port"] == "3": + self.assertEqual(x["priority-group"], 6) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 25500) + elif x["metric"] == "um-headroom-buffer-count": + self.assertTrue(x["value"] == 24450) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["port"] == True) + + + def test_thresholds3(self): + rep = BSTParser() + rep.process(self.thresholds3) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 2) + i = 0 + y = self.thresholds3 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "ingress-port-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + self.assertTrue("port" in x) + if x["port"] == "2": + self.assertEqual(x["service-pool"], 5) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 324) + else: + self.assertTrue(x["metric"] == True) + elif x["port"] == "3": + self.assertEqual(x["service-pool"], 6) + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 366) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["port"] == True) + + def test_thresholds4(self): + rep = BSTParser() + rep.process(self.thresholds4) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 2) + i = 0 + y = self.thresholds4 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "ingress-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + if x["service-pool"] == 1: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 3240) + else: + self.assertTrue(x["metric"] == True) + elif x["service-pool"] == 2: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 3660) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["service-pool"] == True) + + + def test_thresholds5(self): + rep = BSTParser() + rep.process(self.thresholds5) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 2) + i = 0 + y = self.thresholds5 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-cpu-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + if x["queue"] == 3: + if x["metric"] == "cpu-buffer-count": + self.assertTrue(x["value"] == 4566) + elif x["metric"] == "cpu-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_thresholds6(self): + rep = BSTParser() + rep.process(self.thresholds6) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 6) + i = 0 + y = self.thresholds6 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-mc-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + self.assertTrue("port" in x) + if x["queue"] == 1: + self.assertTrue(x["port"] == "1") + if x["metric"] == "mc-buffer-count": + self.assertTrue(x["value"] == 34) + elif x["metric"] == "mc-queue-entries": + self.assertTrue(x["value"] == 89) + else: + self.assertTrue(x["metric"] == True) + elif x["queue"] == 2: + self.assertTrue(x["port"] == "4") + if x["metric"] == "mc-buffer-count": + self.assertTrue(x["value"] == 1244) + elif x["metric"] == "mc-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + elif x["queue"] == 3: + self.assertTrue(x["port"] == "5") + if x["metric"] == "mc-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-queue-entries": + self.assertTrue(x["value"] == 3) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_thresholds7(self): + rep = BSTParser() + rep.process(self.thresholds7) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 6) + i = 0 + y = self.thresholds7 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-port-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + self.assertTrue("port" in x) + if x["service-pool"] == 5: + self.assertTrue(x["port"] == "2") + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 324) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + elif x["service-pool"] == 6: + self.assertTrue(x["port"] == "3") + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 366) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["service-pool"] == True) + + def test_thresholds8(self): + rep = BSTParser() + rep.process(self.thresholds8) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 4) + i = 0 + y = self.thresholds8 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-rqe-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + if x["queue"] == 2: + if x["metric"] == "rqe-buffer-count": + self.assertTrue(x["value"] == 3333) + elif x["metric"] == "rqe-queue-entries": + self.assertTrue(x["value"] == 4444) + else: + self.assertTrue(x["metric"] == True) + elif x["queue"] == 5: + if x["metric"] == "rqe-buffer-count": + self.assertTrue(x["value"] == 25) + elif x["metric"] == "rqe-queue-entries": + self.assertTrue(x["value"] == 45) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_thresholds9(self): + rep = BSTParser() + rep.process(self.thresholds9) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 6) + i = 0 + y = self.thresholds9 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-service-pool") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("service-pool" in x) + if x["service-pool"] == 2: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 3240) + else: + self.assertTrue(x["metric"] == True) + elif x["service-pool"] == 3: + if x["metric"] == "um-share-buffer-count": + self.assertTrue(x["value"] == 3660) + elif x["metric"] == "mc-share-buffer-count": + self.assertTrue(x["value"] == 0) + elif x["metric"] == "mc-share-queue-entries": + self.assertTrue(x["value"] == 0) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["service-pool"] == True) + + def test_thresholds10(self): + rep = BSTParser() + rep.process(self.thresholds10) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 1) + i = 0 + y = self.thresholds10 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-uc-queue") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue" in x) + self.assertTrue("port" in x) + if x["queue"] == 6: + self.assertEqual(x["port"], "0") + if x["metric"] == "uc-queue-buffer-count": + self.assertTrue(x["value"] == 1111) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue"] == True) + + def test_thresholds11(self): + rep = BSTParser() + rep.process(self.thresholds11) + serializer = BSTToStacklight() + ret = serializer.serialize(self._host, rep) + self.assertEqual(ret[0], True) + data = json.loads(ret[1]) + self.assertTrue(len(data) == 1) + i = 0 + y = self.thresholds11 + for x in data: + i = i + 1 + self.assertTrue("timestamp" in x) + x["timestamp"] = x["timestamp"] / 1000 + self.assertTrue("name" in x) + self.assertTrue("value" in x) + self.assertTrue("metric" in x) + t1 = datetime.datetime.fromtimestamp(int(x["timestamp"])) + t1 = t1.strftime("%Y-%m-%d - %H:%M:%S") + t2 = y["time-stamp"].strip() + self.assertEqual(t1, t2) + self.assertEqual(x["name"], "egress-uc-queue-group") + self.assertEqual(x["asic-id"], y["asic-id"]) + self.assertTrue("metric" in x) + self.assertTrue("queue-group" in x) + if x["queue-group"] == 6: + if x["metric"] == "uc-buffer-count": + self.assertTrue(x["value"] == 2222) + else: + self.assertTrue(x["metric"] == True) + else: + self.assertTrue(x["queue-group"] == True) + +if __name__ == "__main__": + unittest.main() + diff --git a/doc/bst_to_stacklight_serializer.md b/doc/bst_to_stacklight_serializer.md new file mode 100644 index 0000000..00e10ee --- /dev/null +++ b/doc/bst_to_stacklight_serializer.md @@ -0,0 +1,209 @@ +Stacklight BST Serializer Format +================================ + +Stacklight serializer generates a JSON object with the following common +key/value pairs: + +* entity - for BST statistics, the string "broadview-bst" +* name - the statistic name (see below for the set of possible names) +* timestamp - event time in microseconds (floating point) +* value - metric value +* asic-id - the number of the ASIC for which the stat is being reported +* metric - metric name (not present for "device" statistic) +* bv-agent - the IP address of the BroadView agent that reported the data + +The data is hierarchical - the entity "broadview-bst" is the parent to a +number of statistics, and a statistic can have 0 or more metrics. + +This document details the format of Stacklight metrics as generated by the +BST to Stacklight serializer (serializers/bst_to_stacklight.py) + +BST +--- + +This section describes in more detail the format currently used for BST +metrics published to Stacklight. + +# entity + +The name field consists of the string "broadview-bst". + +# name + +BST statistic names consist of the following: + +* device +* ingress-port-priority-group +* ingress-port-service-pool +* ingress-service-pool +* egress-cpu-queue +* egress-mc-queue +* egress-port-service-pool +* egress-rqe-queue +* egress-service-pool +* egress-uc-queue +* egress-uc-queue-group + +###Example: "name": "egress-port-service-pool" + +# timestamp + +The timestamp field is a floating point value which represents that time in +microseconds of the statistic. + +###Example: "timestamp": 1459361118000.0 + +# value + +The value field represents that reported value for the statistic. + +###Example: "value": 366 + +# asic-id + +The ID of the ASIC on the device to which the report corresponds. + +###Example: "asic-id": 3 + +# bv-agent + +This is the IPV4 internet address of the device (e.g., switch) that hosts +the BroadView agent from which the report originated. + +###Example: "bv-agent": "192.168.3.47" + +# metric + +Note the structure of the "name" field values for BST. Except for "device", +the name consists of the string "ingress" or "egress", followed by a '-' +separated list of strings. These names imply some of the metadata that +is associated with the named stat. For example, names which contain +the "-port-" substring will have "port" metadata. Similarly, a name with +"-service-pool-" substring will have "service-pool" metadata. + +Finally, be aware that a statistic reported by BroadView often comes in +the form of an aggregate. For a given named statistic, there might be +multiple metrics reported. In the case of ingress-port-priority-group, +for example, both um-share-buffer-count and um-headroom-count are reported +together in an array. They share the same metadata: asic-id, port, and +priority-group (as implied by the name of the statistic). broadview-lib +flattens this aggregate report into two separate metrics, one for +um-share-bufffer-count, and one for um-headroom-count. This flattening +aids indexers of the data; both metrics can be retrieved by searching +on ingress-port-priority-group, or a more refined search can obtain just +the um-share-bufffer-count data by providing that metadata as a search +key. + +The following sections define the metrics and related metadata that are +generated by the BST to Stacklight serializer for each BST statistic. + +## device + +The device "name" has no metric field. + +###Example: + + {"asic-id": "20", "name": "device", "timestamp": 1463014303000.0, "bv-agent": "172.16.170.184", "value": 46000, "entity": "broadview-bst"} + +## ingress-port-priority-group + +* priority-group - the priority group associated with the stat +* port - the port impacted by the statistic +* metric - either um-share-buffer-count or um-headroom-buffer-count + +###Example: + + {"asic-id": "20", "name": "ingress-port-priority-group", "bv-agent": "172.16.170.184", "metric": "um-share-buffer-count", "priority-group": 5, "value": 45500, "entity": "broadview-bst", "timestamp": 1463014303000.0, "port": "2"} + {"asic-id": "20", "name": "ingress-port-priority-group", "bv-agent": "172.16.170.184", "metric": "um-headroom-buffer-count", "priority-group": 5, "value": 44450, "entity": "broadview-bst", "timestamp": 1463014303000.0, "port": "2"} + +## ingress-port-service-pool + +* service-pool - the service pool associated with the stat +* port - the port impacted by the statistic +* metric - um-share-buffer-count + +###Example: + + {"asic-id": "20", "service-pool": 5, "name": "ingress-port-service-pool", "timestamp": 1463014303000.0, "metric": "um-share-buffer-count", "bv-agent": "172.16.170.184", "value": 10000, "entity": "broadview-bst", "port": "2"} + +## ingress-service-pool + +* service-pool - the service pool associated with the stat +* metric - um-share-buffer-count + +###Example: + + {"asic-id": "20", "service-pool": 1, "name": "ingress-service-pool", "timestamp": 1463014303000.0, "metric": "um-share-buffer-count", "bv-agent": "172.16.170.184", "value": 3240, "entity": "broadview-bst"} + +## egress-cpu-queue + +* queue - the queue associated with the statistic +* metric - either cpu-buffer-count or cpu-queue-entries + +###Example: + + {"asic-id": "20", "name": "egress-cpu-queue", "timestamp": 1463014303000.0, "metric": "cpu-buffer-count", "bv-agent": "172.16.170.184", "value": 4566, "entity": "broadview-bst", "queue": 3} + {"asic-id": "20", "name": "egress-cpu-queue", "timestamp": 1463014303000.0, "metric": "cpu-queue-entries", "bv-agent": "172.16.170.184", "value": 0, "entity": "broadview-bst", "queue": 3} + +## egress-mc-queue + +* queue - the queue associated with the statistic +* port - the port associated with the statistic +* metric - either mc-buffer-count or mc-queue-entries + +###Example: + + {"asic-id": "20", "name": "egress-mc-queue", "timestamp": 1463014303000.0, "metric": "mc-buffer-count", "bv-agent": "172.16.170.184", "value": 34, "entity": "broadview-bst", "queue": 1, "port": "1"} + {"asic-id": "20", "name": "egress-mc-queue", "timestamp": 1463014303000.0, "metric": "mc-queue-entries", "bv-agent": "172.16.170.184", "value": 89, "entity": "broadview-bst", "queue": 1, "port": "1"} + +## egress-port-service-pool + +* service-pool - the service pool associated with the statistic +* port - the port associated with the statistic +* metric - either um-share-buffer-count, mc-share-buffer-count or mc-share-queue-entries + +###Example: + + {"asic-id": "20", "service-pool": 5, "name": "egress-port-service-pool", "timestamp": 1463014303000.0, "metric": "um-share-buffer-count", "bv-agent": "172.16.170.184", "value": 0, "entity": "broadview-bst", "port": "2"} + {"asic-id": "20", "service-pool": 5, "name": "egress-port-service-pool", "timestamp": 1463014303000.0, "metric": "mc-share-buffer-count", "bv-agent": "172.16.170.184", "value": 24000, "entity": "broadview-bst", "port": "2"} + {"asic-id": "20", "service-pool": 5, "name": "egress-port-service-pool", "timestamp": 1463014303000.0, "metric": "mc-share-queue-entries", "bv-agent": "172.16.170.184", "value": 0, "entity": "broadview-bst", "port": "2"} + +## egress-rqe-queue + +* metric - either rqe-buffer-count or rqe-queue-entries + +###Example: + + {"asic-id": "20", "name": "egress-rqe-queue", "timestamp": 1463014303000.0, "metric": "rqe-buffer-count", "bv-agent": "172.16.170.184", "value": 3333, "entity": "broadview-bst", "queue": 2} + {"asic-id": "20", "name": "egress-rqe-queue", "timestamp": 1463014303000.0, "metric": "rqe-queue-entries", "bv-agent": "172.16.170.184", "value": 4444, "entity": "broadview-bst", "queue": 2} + +## egress-service-pool + +* service-pool - the service pool associated with the statistic +* metric - either um-share-buffer-count, mc-share-buffer-count or mc-share-queue-entries + +###Example: + + {"asic-id": "20", "service-pool": 2, "name": "egress-service-pool", "timestamp": 1463014303000.0, "metric": "um-share-buffer-count", "bv-agent": "172.16.170.184", "value": 5700, "entity": "broadview-bst"} + {"asic-id": "20", "service-pool": 2, "name": "egress-service-pool", "timestamp": 1463014303000.0, "metric": "mc-share-buffer-count", "bv-agent": "172.16.170.184", "value": 4567, "entity": "broadview-bst"} + {"asic-id": "20", "service-pool": 2, "name": "egress-service-pool", "timestamp": 1463014303000.0, "metric": "mc-share-queue-entries", "bv-agent": "172.16.170.184", "value": 3240, "entity": "broadview-bst"} + +## egress-uc-queue + +* queue - the queue associated with the statistic +* port - the port associated with the statistic +* metric - uc-queue-buffer-count + +###Example: + + {"asic-id": "20", "name": "egress-uc-queue", "timestamp": 1463014303000.0, "metric": "uc-queue-buffer-count", "bv-agent": "172.16.170.184", "value": 1111, "entity": "broadview-bst", "queue": 6, "port": "0"} + +## egress-uc-queue-group + +* queue-group - the queue group associated with the statistic +* metric - uc-buffer-count + +###Example: + + {"asic-id": "20", "name": "egress-uc-queue-group", "queue-group": 6, "timestamp": 1463014303000.0, "metric": "uc-buffer-count", "bv-agent": "172.16.170.184", "value": 2222, "entity": "broadview-bst"} +