# Python package for import
import json
from datetime import datetime
from flask import Flask, render_template, flash
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
from wtforms.widgets import PasswordInput
import requests
# FLASK init with Bootstrap CSS
app = Flask(__name__)
bootstrap = Bootstrap(app)
app.config['SECRET_KEY'] = 'Di4PipeMon2021'
# WTForm
class requestForm(FlaskForm):
di_url = StringField('DI-URL: ', validators=[DataRequired()])
tenant = StringField('Tenant: ', validators=[DataRequired()],default='default')
user = StringField('User: ', validators=[DataRequired()])
pwd = StringField('Password: ', widget=PasswordInput(hide_value=False), validators=[DataRequired()])
verification = BooleanField('TLS Verification', default=True)
submit = SubmitField('Submit')
# Binding of 'index'-page
@app.route('/', methods = ['GET'])
def index():
requestform = requestForm()
data = list()
if requestform.validate_on_submit() :
response, data = call_restapi(user = requestform.user.data,
pwd = requestform.pwd.data,
url=requestform.di_url.data,
tenant= requestform.tenant.data,
verification = requestform.verification.data)
if not response == 200 :
flash("Response: {}".format(response),'warning')
return render_template('request.html', dictlist = data, form=requestform)
return render_template('request.html',dictlist = data, form=requestform)
# RestAPI call
def call_restapi(user, pwd, url, tenant) :
# send request
auth = (tenant+'\\'+user, pwd)
#headers = {'X-Requested-With': 'XMLHttpRequest'}
headers = {}
resturl = url + '/app/pipeline-modeler/service/v1/runtime/graphs'
resp = requests.get(resturl, auth=auth, headers=headers,verify = verification)
data = list()
if resp.status_code == 200 :
rdata = json.loads(resp.text)
for r in rdata :
started = datetime.fromtimestamp(r['started']).strftime('%Y-%m-%d %H:%M:%S') if r['started'] >0 else '-'
submitted = datetime.fromtimestamp(r['submitted']).strftime('%Y-%m-%d %H:%M:%S') if r['submitted'] > 0 else '-'
stopped = datetime.fromtimestamp(r['stopped']).strftime('%Y-%m-%d %H:%M:%S') if r['stopped'] > 0 else '-'
data.append({'Pipeline': r['src'], 'Status': r['status'],'Submitted': submitted,'Started': started,
'Stopped': stopped,'Messages':r['message']})
return resp.status_code, data
# APP CALL
if __name__ == '__main__':
app.run('0.0.0.0',port=8080)
{% extends "bootstrap/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block title %}Runtime Pipelines{% endblock %}
{% block head %}
{{ super() }}
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
{% endblock %}
{% block navbar %}
<nav class="navbar navbar-expand-lg navbar-light">
<div class="container">
<div class="navbar-brand"><H1><img src='/static/SAP_R_grad.png' style="height:50px" class="img-fluid" alt="SAP logo">Data Intelligence</H1></div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
</div>
</div>
</nav>
{% endblock %}
{% block content %}
<div class="container">
{% block page_content %}
<br>
<br>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{category}}">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
<div class="page-header">
</div>
{{ wtf.quick_form(form) }}
<br>
<h2>Runtime Pipelines</h2>
<table class="table">
<thead>
<tr>
{% for hi in dictlist[0] %}
<th scope="col">{{ hi }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in dictlist %}
<tr>
{% for val in row.values() %}
<td>{{ val }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
</div>
{% endblock %}
{% block scripts %}
{{ super() }}
{% endblock %}
web: python app.py
python-3.8.8
Flask
Flask-Bootstrap4
Flask-WTF
jinja2
WTForms
Werkzeug
requests
---
applications:
- name: pipelinemonitor
host: pipelinemonitor
memory: 256M
disk_quota: 256M
timeout: 60
buildpack: https://github.com/cloudfoundry/buildpack-python.git
cf login
cf push pipelinemonitor
cf logs --recent
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
27 | |
25 | |
19 | |
14 | |
13 | |
11 | |
10 | |
9 | |
7 | |
7 |