tests: add pingdom test and supporting json examples
This commit is contained in:
parent
d964f75c84
commit
b5912a8b6c
4 changed files with 147 additions and 0 deletions
33
tests/example_pingdom_dns.json
Normal file
33
tests/example_pingdom_dns.json
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"check_id": 12345,
|
||||||
|
"check_name": "Pingdom-dns build test",
|
||||||
|
"check_type": "DNS",
|
||||||
|
"check_params": {
|
||||||
|
"hostname": "www.example.com",
|
||||||
|
"basic_auth": false,
|
||||||
|
"expected_ip": "123.4.5.6",
|
||||||
|
"ipv6": false,
|
||||||
|
"nameserver": "example.com"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"example_tag"
|
||||||
|
],
|
||||||
|
"previous_state": "UP",
|
||||||
|
"current_state": "DOWN",
|
||||||
|
"importance_level": "HIGH",
|
||||||
|
"state_changed_timestamp": 1451610061,
|
||||||
|
"state_changed_utc_time": "2016-01-01T01:01:01",
|
||||||
|
"long_description": "Long error message",
|
||||||
|
"description": "Short error message",
|
||||||
|
"first_probe": {
|
||||||
|
"ip": "123.4.5.6",
|
||||||
|
"ipv6": "2001:4800:1020:209::5",
|
||||||
|
"location": "Stockholm, Sweden"
|
||||||
|
},
|
||||||
|
"second_probe": {
|
||||||
|
"ip": "123.4.5.6",
|
||||||
|
"ipv6": "2001:4800:1020:209::5",
|
||||||
|
"location": "Austin, US",
|
||||||
|
"version": 1
|
||||||
|
}
|
||||||
|
}
|
36
tests/example_pingdom_http.json
Normal file
36
tests/example_pingdom_http.json
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
{
|
||||||
|
"check_id": 12345,
|
||||||
|
"check_name": "Pingdom-http build test",
|
||||||
|
"check_type": "HTTP",
|
||||||
|
"check_params": {
|
||||||
|
"basic_auth": false,
|
||||||
|
"encryption": true,
|
||||||
|
"full_url": "https://www.example.com/path",
|
||||||
|
"header": "User-Agent:Pingdom.com_bot",
|
||||||
|
"hostname": "www.example.com",
|
||||||
|
"ipv6": false,
|
||||||
|
"port": 443,
|
||||||
|
"url": "/path"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"example_tag"
|
||||||
|
],
|
||||||
|
"previous_state": "UP",
|
||||||
|
"current_state": "DOWN",
|
||||||
|
"importance_level": "HIGH",
|
||||||
|
"state_changed_timestamp": 1451610061,
|
||||||
|
"state_changed_utc_time": "2016-01-01T01:01:01",
|
||||||
|
"long_description": "Long error message",
|
||||||
|
"description": "Short error message",
|
||||||
|
"first_probe": {
|
||||||
|
"ip": "123.4.5.6",
|
||||||
|
"ipv6": "2001:4800:1020:209::5",
|
||||||
|
"location": "Stockholm, Sweden"
|
||||||
|
},
|
||||||
|
"second_probe": {
|
||||||
|
"ip": "123.4.5.6",
|
||||||
|
"ipv6": "2001:4800:1020:209::5",
|
||||||
|
"location": "Austin, US",
|
||||||
|
"version": 1
|
||||||
|
}
|
||||||
|
}
|
34
tests/example_pingdom_tcp.json
Normal file
34
tests/example_pingdom_tcp.json
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"body":{
|
||||||
|
"check_id": 12345,
|
||||||
|
"check_name": "Pingdom-tcp build test",
|
||||||
|
"check_type": "PORT_TCP",
|
||||||
|
"check_params": {
|
||||||
|
"hostname": "www.example.com",
|
||||||
|
"basic_auth": false,
|
||||||
|
"ipv6": false,
|
||||||
|
"port": 80
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"example_tag"
|
||||||
|
],
|
||||||
|
"previous_state": "UP",
|
||||||
|
"current_state": "DOWN",
|
||||||
|
"importance_level": "HIGH",
|
||||||
|
"state_changed_timestamp": 1451610061,
|
||||||
|
"state_changed_utc_time": "2016-01-01T01:01:01",
|
||||||
|
"long_description": "Long error message",
|
||||||
|
"description": "Short error message",
|
||||||
|
"first_probe": {
|
||||||
|
"ip": "123.4.5.6",
|
||||||
|
"ipv6": "2001:4800:1020:209::5",
|
||||||
|
"location": "Stockholm, Sweden"
|
||||||
|
},
|
||||||
|
"second_probe": {
|
||||||
|
"ip": "123.4.5.6",
|
||||||
|
"ipv6": "2001:4800:1020:209::5",
|
||||||
|
"location": "Austin, US",
|
||||||
|
"version": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
44
tests/test_pingdom.py
Normal file
44
tests/test_pingdom.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
"""
|
||||||
|
Test module for pingdom formatter.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
import nio
|
||||||
|
|
||||||
|
from .start import BOT_URL, FULL_ID, KEY, MATRIX_ID, MATRIX_PW, MATRIX_URL
|
||||||
|
|
||||||
|
|
||||||
|
class PingdomFormatterTest(unittest.IsolatedAsyncioTestCase):
|
||||||
|
"""Grafana formatter test class."""
|
||||||
|
|
||||||
|
async def test_pingdom_http_body(self):
|
||||||
|
"""Send a markdown message, and check the result."""
|
||||||
|
messages = []
|
||||||
|
client = nio.AsyncClient(MATRIX_URL, MATRIX_ID)
|
||||||
|
|
||||||
|
await client.login(MATRIX_PW)
|
||||||
|
room = await client.room_create()
|
||||||
|
|
||||||
|
with open("tests/example_pingdom_http.json") as f:
|
||||||
|
example_pingdom_request = f.read()
|
||||||
|
self.assertEqual(
|
||||||
|
httpx.post(
|
||||||
|
f"{BOT_URL}/{room.room_id}",
|
||||||
|
params={"formatter": "pingdom", "key": KEY},
|
||||||
|
content=example_pingdom_request,
|
||||||
|
).json(),
|
||||||
|
{"status": 200, "ret": "OK"},
|
||||||
|
)
|
||||||
|
|
||||||
|
sync = await client.sync()
|
||||||
|
messages = await client.room_messages(room.room_id, sync.next_batch)
|
||||||
|
await client.close()
|
||||||
|
|
||||||
|
message = messages.chunk[0]
|
||||||
|
self.assertEqual(message.sender, FULL_ID)
|
||||||
|
self.assertEqual(
|
||||||
|
message.body,
|
||||||
|
"#### [Alerting] Panel Title alert\nNotification Message\n\n* Count: 1\n",
|
||||||
|
)
|
Loading…
Reference in a new issue