def test_get_state_update_points(self): tags = {'host_name': 'testname'} #the state type changes data = { 'last_chk': 1403618279, 'state': 'WARNING', 'last_state': 'WARNING', 'state_type': 'HARD', 'last_state_type': 'SOFT', 'output': 'BOB IS NOT HAPPY', } result = InfluxdbBroker.get_state_update_points(data, tags) expected = [ {'fields': {'state_type': 'HARD', 'output': 'BOB IS NOT HAPPY', 'state': 'WARNING', 'event_type': 'ALERT'}, 'tags': {'host_name': 'testname'}, 'time': 1403618279, 'measurement': 'EVENT'}] self.assertEqual(expected, result) #The state changes data = { 'last_chk': 1403618279, 'state': 'WARNING', 'last_state': 'CRITICAL', 'state_type': 'SOFT', 'last_state_type': 'SOFT', 'output': 'BOB IS NOT HAPPY', } result = InfluxdbBroker.get_state_update_points(data, tags) print result expected = [ {'fields': {'state_type': 'SOFT', 'output': 'BOB IS NOT HAPPY', 'state': 'WARNING', 'event_type': 'ALERT'}, 'tags': {'host_name': 'testname'}, 'time': 1403618279, 'measurement': 'EVENT'}] self.assertEqual(expected, result) #Nothing changes data = { 'last_chk': 1403618279, 'state': 'WARNING', 'last_state': 'WARNING', 'state_type': 'SOFT', 'last_state_type': 'SOFT', 'output': 'BOB IS NOT HAPPY', } result = InfluxdbBroker.get_state_update_points(data, tags) expected = [] self.assertEqual(expected, result)
def test_get_state_update_points(self): tags = {"host_name": "testname"} # the state type changes data = { "last_chk": 1403618279, "state": "WARNING", "last_state": "WARNING", "state_type": "HARD", "last_state_type": "SOFT", "output": "BOB IS NOT HAPPY", } result = InfluxdbBroker.get_state_update_points(data, tags) expected = [ { "timestamp": 1403618279, "name": "ALERT", "tags": {"host_name": "testname"}, "fields": {"state_type": "HARD", "output": "BOB IS NOT HAPPY", "state": "WARNING"}, } ] self.assertEqual(expected, result) # The state changes data = { "last_chk": 1403618279, "state": "WARNING", "last_state": "CRITICAL", "state_type": "SOFT", "last_state_type": "SOFT", "output": "BOB IS NOT HAPPY", } result = InfluxdbBroker.get_state_update_points(data, tags) expected = [ { "timestamp": 1403618279, "name": "ALERT", "tags": {"host_name": "testname"}, "fields": {"state_type": "SOFT", "output": "BOB IS NOT HAPPY", "state": "WARNING"}, } ] self.assertEqual(expected, result) # Nothing changes data = { "last_chk": 1403618279, "state": "WARNING", "last_state": "WARNING", "state_type": "SOFT", "last_state_type": "SOFT", "output": "BOB IS NOT HAPPY", } result = InfluxdbBroker.get_state_update_points(data, tags) expected = [] self.assertEqual(expected, result)
def test_get_state_update_points(self): name = 'testname' #the state type changes data = { 'last_chk': 1403618279, 'state': 'WARNING', 'last_state': 'WARNING', 'state_type': 'HARD', 'last_state_type': 'SOFT', 'output': 'BOB IS NOT HAPPY', } result = InfluxdbBroker.get_state_update_points(data, name) expected = [{ 'points': [[1403618279, 'WARNING', 'HARD', 'BOB IS NOT HAPPY']], 'name': 'testname._events_.ALERT', 'columns': ['time', 'state', 'state_type', 'output'] }] self.assertEqual(expected, result) #The state changes data = { 'last_chk': 1403618279, 'state': 'WARNING', 'last_state': 'CRITICAL', 'state_type': 'SOFT', 'last_state_type': 'SOFT', 'output': 'BOB IS NOT HAPPY', } result = InfluxdbBroker.get_state_update_points(data, name) expected = [{ 'points': [[1403618279, 'WARNING', 'SOFT', 'BOB IS NOT HAPPY']], 'name': 'testname._events_.ALERT', 'columns': ['time', 'state', 'state_type', 'output'] }] self.assertEqual(expected, result) #Nothing changes data = { 'last_chk': 1403618279, 'state': 'WARNING', 'last_state': 'WARNING', 'state_type': 'SOFT', 'last_state_type': 'SOFT', 'output': 'BOB IS NOT HAPPY', } result = InfluxdbBroker.get_state_update_points(data, name) expected = [] self.assertEqual(expected, result)
def test_get_state_update_points(self): name = 'testname' #the state type changes data = { 'last_chk': 1403618279, 'state': 'WARNING', 'last_state': 'WARNING', 'state_type': 'HARD', 'last_state_type': 'SOFT', 'output': 'BOB IS NOT HAPPY', } result = InfluxdbBroker.get_state_update_points(data, name) expected = [ {'points': [[1403618279, 'WARNING', 'HARD', 'BOB IS NOT HAPPY']], 'name': 'testname>_events_>ALERT', 'columns': ['time', 'state', 'state_type', 'output']} ] self.assertEqual(expected, result) #The state changes data = { 'last_chk': 1403618279, 'state': 'WARNING', 'last_state': 'CRITICAL', 'state_type': 'SOFT', 'last_state_type': 'SOFT', 'output': 'BOB IS NOT HAPPY', } result = InfluxdbBroker.get_state_update_points(data, name) expected = [ {'points': [[1403618279, 'WARNING', 'SOFT', 'BOB IS NOT HAPPY']], 'name': 'testname>_events_>ALERT', 'columns': ['time', 'state', 'state_type', 'output']} ] self.assertEqual(expected, result) #Nothing changes data = { 'last_chk': 1403618279, 'state': 'WARNING', 'last_state': 'WARNING', 'state_type': 'SOFT', 'last_state_type': 'SOFT', 'output': 'BOB IS NOT HAPPY', } result = InfluxdbBroker.get_state_update_points(data, name) expected = [] self.assertEqual(expected, result)