mirror of
https://github.com/FAUSheppy/icinga-webhook-gateway
synced 2026-04-26 22:22:30 +02:00
Compare commits
7 Commits
52569c7687
...
95c3551a5c
| Author | SHA1 | Date | |
|---|---|---|---|
| 95c3551a5c | |||
| 31db0c22d2 | |||
| ce5328da53 | |||
| 1d36a9aaed | |||
| 7fea3bf315 | |||
| 2e37ddcb8e | |||
| 7d612c0ccd |
1
req.txt
1
req.txt
@@ -5,3 +5,4 @@ flask-wtf
|
|||||||
waitress
|
waitress
|
||||||
requests
|
requests
|
||||||
icinga2api
|
icinga2api
|
||||||
|
psycopg2-binary
|
||||||
|
|||||||
32
server.py
32
server.py
@@ -32,6 +32,7 @@ app = flask.Flask("Icinga Report In Gateway")
|
|||||||
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI') or 'sqlite:///database.sqlite'
|
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI') or 'sqlite:///database.sqlite'
|
||||||
app.config['JSON_CONFIG_FILE'] = 'services.json'
|
app.config['JSON_CONFIG_FILE'] = 'services.json'
|
||||||
app.config['JSON_CONFIG_DIR'] = 'config'
|
app.config['JSON_CONFIG_DIR'] = 'config'
|
||||||
|
app.config['AUTH_HEADER'] = os.environ.get("AUTH_HEADER") or "X-Forwarded-Preferred-Username"
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
|
|
||||||
class Service(db.Model):
|
class Service(db.Model):
|
||||||
@@ -91,7 +92,7 @@ def buildReponseDict(status, service=None):
|
|||||||
@app.route('/overview')
|
@app.route('/overview')
|
||||||
def overview():
|
def overview():
|
||||||
|
|
||||||
user = str(flask.request.headers.get("X-Forwarded-Preferred-Username"))
|
user = str(flask.request.headers.get(app.config['AUTH_HEADER']))
|
||||||
|
|
||||||
# query all services #
|
# query all services #
|
||||||
services = db.session.query(Service).filter(Service.owner == user).all()
|
services = db.session.query(Service).filter(Service.owner == user).all()
|
||||||
@@ -161,7 +162,7 @@ def create_entry(form, user):
|
|||||||
@app.route("/service-details")
|
@app.route("/service-details")
|
||||||
def service_details():
|
def service_details():
|
||||||
|
|
||||||
user = str(flask.request.headers.get("X-Forwarded-Preferred-Username"))
|
user = flask.request.headers.get(app.config['AUTH_HEADER'])
|
||||||
service = flask.request.args.get("service")
|
service = flask.request.args.get("service")
|
||||||
|
|
||||||
# query service #
|
# query service #
|
||||||
@@ -189,7 +190,7 @@ def service_details():
|
|||||||
@app.route("/entry-form", methods=["GET", "POST", "DELETE"])
|
@app.route("/entry-form", methods=["GET", "POST", "DELETE"])
|
||||||
def create_interface():
|
def create_interface():
|
||||||
|
|
||||||
user = str(flask.request.headers.get("X-Forwarded-Preferred-Username"))
|
user = flask.request.headers.get(app.config['AUTH_HEADER'])
|
||||||
|
|
||||||
# check if is delete #
|
# check if is delete #
|
||||||
operation = flask.request.args.get("operation")
|
operation = flask.request.args.get("operation")
|
||||||
@@ -448,8 +449,7 @@ def create_app():
|
|||||||
config |= json.load(f)
|
config |= json.load(f)
|
||||||
|
|
||||||
if not config:
|
if not config:
|
||||||
print("No valid configuration found - need at least one service")
|
print("No static services configuration found - loading finished.")
|
||||||
return
|
|
||||||
|
|
||||||
for key in config:
|
for key in config:
|
||||||
timeout = timeparse.timeparse(config[key]["timeout"])
|
timeout = timeparse.timeparse(config[key]["timeout"])
|
||||||
@@ -459,12 +459,34 @@ def create_app():
|
|||||||
owner=config[key]["owner"]))
|
owner=config[key]["owner"]))
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
LOAD_FROM_ENV = [
|
||||||
|
"ICINGA_API_USER",
|
||||||
|
"ICINGA_API_PASS",
|
||||||
|
"ICINGA_API_URL",
|
||||||
|
"ICINGA_WEB_URL",
|
||||||
|
"ASYNC_ICINGA_DUMMY_HOST"
|
||||||
|
]
|
||||||
|
|
||||||
|
enforce_load_from_env = os.environ.get("ENFORCE_LOAD_FROM_ENV") or ""
|
||||||
|
missing = [k for k in LOAD_FROM_ENV if k not in os.environ]
|
||||||
|
if missing and enforce_load_from_env.lower() == "true":
|
||||||
|
print(f"ENFORCE_LOAD_FROM_ENV is 'true' but we are missing: {missing} - Abort.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for key in LOAD_FROM_ENV:
|
||||||
|
if key in os.environ:
|
||||||
|
print(f"Loading/Overwriting {key} from environment", file=sys.stderr)
|
||||||
|
app.config[key] = os.environ[key]
|
||||||
|
|
||||||
|
|
||||||
# create icinga host #
|
# create icinga host #
|
||||||
if not app.config.get("ICINGA_API_URL"):
|
if not app.config.get("ICINGA_API_URL"):
|
||||||
print("ICINGA_API_URL not defined. Not connecting Icinga", file=sys.stderr)
|
print("ICINGA_API_URL not defined. Not connecting Icinga", file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
icingatools.create_master_host(app)
|
icingatools.create_master_host(app)
|
||||||
|
|
||||||
|
print(f"Expected AUTH_HEADER is: {app.config['AUTH_HEADER']}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user