Skip to content

Commit

Permalink
feat: add healthchecks hit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrochas committed Sep 13, 2018
1 parent 65bc000 commit 24945d5
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
.idea

# Generated files
.idea/**/contentModel.xml
Expand Down
7 changes: 7 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
- name: Google
url: https://www.google.com.br
- name: Twitter
url: https://twitter.com
- name: Failed API
url: https://mustfail.com
27 changes: 25 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
import npyscreen
import yaml
import requests
from requests import RequestException

with open("config.yml", 'r') as stream:
try:
yml_content = yaml.load(stream)
except yaml.YAMLError as exc:
print(exc)

class MainWidgetTUI(npyscreen.Form):

class MainWidgetTUI(npyscreen.ActionForm):

def activate(self):
self.edit()
self.parentApp.setNextForm(None)

def while_waiting(self):
for service in yml_content['services']:
current_service = self.SERVICES.get(service['name'])
try:
resp = requests.get(service['url'])
if resp.status_code == 200:
current_service.value = '[OK]'
except RequestException as e:
current_service.value = '[FAILED]'
current_service.display()

def create(self):
self.serviceX = self.add(npyscreen.TitleText, name="Service X", value="[OK]", editable=False)
self.SERVICES = {}
for service in yml_content['services']:
self.SERVICES.update({service['name']: self.add(npyscreen.TitleText, name=service['name'], value="Not started", editable=False)})


class MonitoringTUI(npyscreen.NPSAppManaged):

def onStart(self):
self.keypress_timeout_default = 10
self.addForm("MAIN", MainWidgetTUI, name="Monitoring TUI")


Expand Down
69 changes: 69 additions & 0 deletions monitoring-curses.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import yaml\n",
"\n",
"with open(\"config.yml\", 'r') as stream:\n",
" try:\n",
" yml_content = yaml.load(stream)\n",
" except yaml.YAMLError as exc:\n",
" print(exc)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"200\n",
"200\n"
]
}
],
"source": [
"import requests\n",
"\n",
"for services in yml_content['services']:\n",
" resp = requests.get(services['url'])\n",
" print(resp.status_code)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 24945d5

Please sign in to comment.