def test_opentsdb_get_metric(self, mocktime): mocktime.return_value = self.time mdata = { 'metric': 'cpmCPUTotal5minRev', 'oid': '.1.3.6.1.4.1.9.9.109.1.1.1.1.8', 'type': 'get', 'tags': {}, 'device': self.mockdevice, } m = Metric(**mdata) result = m.get_opentsdb_commands(self.mockdevice.snmp, self.time)[0] eq_("put cpmCPUTotal5minRev " + str(int(self.time)) + " 123 host=foo", result)
def test_opentsdb_walk_metric(self, mocktime): mocktime.return_value = self.time mdata = { 'metric': 'interface.packets', 'oid': '.1.3.6.1.2.1.31.1.1.1.9', 'type': 'walk', 'tags': { 'direction': "in", 'type': 'broadcast' }, 'resolver': 'cisco_ifname' } m = Metric( data=mdata, device=self.mockdevice ) #test _tags_to_str with empty tags eq_("", m._tags_to_str({})) walkdata = m._get_walk() eq_(10, walkdata["1"]) eq_(20, walkdata["2"]) eq_( "put interface.packets " + str(int(self.time)) + " 20 index=2 direction=in type=broadcast host=foo", m._process_dp(20, 2) ) result = m._process_walk_data(walkdata) eq_(2, len(result)) eq_( 'put interface.packets ' + str(int(self.time)) + ' 10 index=1 direction=in type=broadcast host=foo', result[0] ) result = m.get_opentsdb_commands() eq_(2, len(result)) eq_( 'put interface.packets ' + str(int(self.time)) + ' 10 index=1 direction=in type=broadcast host=foo', result[0] )
def test_opentsdb_get_metric(self, mocktime): mocktime.return_value = self.time mdata = { 'metric': 'cpmCPUTotal5minRev', 'oid': '.1.3.6.1.4.1.9.9.109.1.1.1.1.8', 'type': 'get', 'tags': {}, } m = Metric( data=mdata, device=self.mockdevice ) result = m.get_opentsdb_commands()[0] eq_( "put cpmCPUTotal5minRev " + str(int(self.time)) + " 123 host=foo", result )
def test_opentsdb_walk_metric(self, mocktime): mocktime.return_value = self.time metric = self.walkmetric metric["device"] = self.mockdevice m = Metric(**metric) #test _tags_to_str with empty tags eq_("", m._tags_to_str({})) walkdata = m._get_walk(self.mockdevice.snmp) eq_(10, walkdata["1"]) eq_(20, walkdata["2"]) eq_("0", walkdata["3"]) eq_( "put interface.packets.in.foo " + str(int(self.time)) + " 2.0 index=2 type=broadcast", m._process_dp(20, self.time, key=2)) result = m._process_walk_data(walkdata, self.time) eq_(3, len(result)) eq_( 'put interface.packets.in.foo ' + str(int(self.time)) + ' 1.0 index=1 type=broadcast', result[0]) result = m.get_opentsdb_commands(self.mockdevice.snmp, self.time) eq_(3, len(result)) eq_( 'put interface.packets.in.foo ' + str(int(self.time)) + ' 1.0 index=1 type=broadcast', result[0])