Browse Source

Removed hardcoded Statping endpoint

Nikola Kotur 3 years ago
parent
commit
879467a763
3 changed files with 14 additions and 6 deletions
  1. 2 0
      README.md
  2. 9 5
      main.py
  3. 3 1
      requirements.txt

+ 2 - 0
README.md

@@ -15,6 +15,8 @@ version: "2"
 services:
   homer:
     image: statping_homer:latest
+    environment:
+      - STATPING_ENDPOINT=http://192.168.88.50:8085/ # Use trailing slash
     ports:
       - 8099:8099
     restart: unless-stopped

+ 9 - 5
main.py

@@ -1,16 +1,20 @@
+import os
+
+import requests
 from flask import Flask
 from flask import jsonify
-import requests
 from flask_cors import CORS, cross_origin
 
+
 def get_result():
   services_up = 0
   failure_list = []
   returnResponse = {"style":"", "title":"", "content":""}
-  statping_endpoint = "http://192.168.81.253:8085/api/services/"
+  statping_endpoint = os.getenv('STATPING_ENDPOINT')
 
   try:
-    response = requests.get(statping_endpoint, verify=False)
+    print('%sapi/services/' % statping_endpoint)
+    response = requests.get('%sapi/services/' % statping_endpoint, verify=False)
       # If we get a response
     if response.status_code == 200:
       # Get the total number of services returned
@@ -29,7 +33,7 @@ def get_result():
         # if so, return a success object
         returnResponse["style"] = "is-success"
         returnResponse["title"] = "All good in the hood boss"
-        returnResponse["content"] = "<b>%s / %s Services showing as online. Check <a href=http://192.168.88.50:8085/ target=_blank>here</a> for more info. </br> <p>"%(services_up, total_services)
+        returnResponse["content"] = "<b>%s / %s Services showing as online. Check <a href=%s target=_blank>here</a> for more info. </br> <p>" % (services_up, total_services, statping_endpoint)
 
         return(returnResponse)
       else:
@@ -41,7 +45,7 @@ def get_result():
         for i in failure_list:
           numptyList += "<li>" + i + "</li>"
         numptyList += "</ul>"
-        returnResponse["content"] = "<b>%s / %s Services showing as online. Check <a href=http://192.168.88.50:8085/ target=_blank>here</a> for more info. </br> <p> <br>Here are the numpties that are letting the side down:</br> %s"%(services_up, total_services, numptyList)
+        returnResponse["content"] = "<b>%s / %s Services showing as online. Check <a href=%s target=_blank>here</a> for more info. </br> <p> <br>Here are the numpties that are letting the side down:</br> %s" % (services_up, total_services, numptyList, statping_endpoint)
       
         return(returnResponse)
 

+ 3 - 1
requirements.txt

@@ -1 +1,3 @@
-pip3 install flask requests flask_cors
+flask
+requests
+flask_cors