This is a demo django app to view how we're laying out the model for NATS UPTIME BOT
the model's architecture looks like the following
from django.db import models
from django.contrib.postgres.fields import JSONField
class Target(models.Model):
domain_name = models.CharField(max_length=255)
class Check(models.Model):
target = models.ForeignKey(Target, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
data = JSONField()
class Result(models.Model):
check = models.ForeignKey(Check, on_delete=models.CASCADE)
timestamp = models.DateTimeField()
data = JSONField()
- make sure you have
docker
anddocker compose
installed. Installation Guid - make sure you have
cmake
installed. Installation Guid
-
clone the repo
$ git clone git@github.com:ahmed-kino/natsUptimeBot.git
-
change directory to the repo
$ cd natsUptimeBot
-
copy the env example to a new file
$ cp .envrc.example .envrc
-
Then run
$ make compose
to run the server
-
Run
$ make shell
to execute into the container -
Run migration
$ make init
- Run
make shell
to execute into the container - Run format
make format
- Run
make shell
to execute into the container - Run sort
make sort
- Run
make shell
to execute into the container - Run
make fmt
to format and sort
- Run
make shell
to execute into the container - Run tests
make test
- Run
make shell
to execute into the container - Run
make clean
to reset the database NOTE that this command will remove*/migrations
directories from the code
-
if you want to add data to the target run the following command:
curl -X POST -H "Content-Type: application/json" -d '{ "domain_name": "first_domain" }' http://127.0.0.1:8000/api/targets/
-
if you want to add data to the checks run the following command:
curl -X POST -H "Content-Type: application/json" -d '{ "target": { "domain_name": "first_domain" }, "name": "http", "data": { "http_method": "GET", "status_code": 200, "port": 443, "headers": {"auth": "some token"} } }' http://127.0.0.1:8000/api/checks/
-
if you want to add data to the results run the following command:
curl -X POST -H "Content-Type: application/json" -d '{ "check_field": { "target": { "domain_name": "first_domain" }, "name": "https", "data": { "http_method": "GET", "status_code": 200, "port": 443, "headers": {"auth": "some token"} } }, "timestamp": "2023-07-18T09:30:00+02:00", "data": { "http_method": "GET", "status_code": 404, "port": 443, "headers": {"auth": "some token"} } }' http://127.0.0.1:8000/api/results/
-
if you want get a list of targets
curl http://127.0.0.1:8000/api/targets/
response:
[ { "id": 1, "domain_name": "first_domain" }, { "id": 2, "domain_name": "second_domain" }, ... ]
-
if you want get a list of checks
curl http://127.0.0.1:8000/api/checks/
results:
[ { "id": 1, "target": { "id": 7, "domain_name": "second_domain" }, "name": "ssh", "data": { "port": 22 } }, { "id": 2, "target": { "id": 8, "domain_name": "first_domain" }, "name": "http", "data": { "port": 443, "headers": { "auth": "some token" }, "http_method": "GET", "status_code": 200 } }, ... ]
-
if you want get a list of results
curl http://127.0.0.1:8000/api/results/
results:
[ { "id": 1, "check_field": { "id": 8, "target": { "id": 14, "domain_name": "first_domain" }, "name": "ssh", "data": { "port": 22 } }, "timestamp": "2023-07-18T07:30:00Z", "data": { "status": "timeout" } }, { "id": 2, "check_field": { "id": 9, "target": { "id": 15, "domain_name": "second_domain" }, "name": "ssh", "data": { "port": 22 } }, "timestamp": "2023-07-18T07:30:00Z", "data": { "status": "timeout" } }, ... ]
-
if you want to probe http check for a specific target
./checks/http_check.py -d "https://api.github.com"