Skip to content

Commit c39a88d

Browse files
committed
Workshop monitoring initial import
1 parent d9fe10f commit c39a88d

File tree

5 files changed

+108
-1
lines changed

5 files changed

+108
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ workshop/aws/ec2/terraform.tfvars.us1.1.pre copy.tfvars
5151
workshop/aws/ec2/*.conf
5252
workshop/aws/ec2/*.key
5353
workshop/aws/ec2/*.csv
54-
.idea/
54+
.idea/
55+
workshop/demo-client/venv/*
56+
workshop/demo-server/venv/*

workshop/demo-client/app.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import requests
2+
import streamlit as st # type: ignore
3+
from datetime import datetime
4+
import pandas as pd
5+
6+
year = datetime.now().year
7+
8+
VERSION = "1.9.0"
9+
CAPTION = f"© {year} Splunk Inc. All rights reserved. **Version {VERSION}**"
10+
11+
st.set_page_config(
12+
page_title=f"Demo Client - Splunk",
13+
page_icon=None,
14+
layout="wide",
15+
initial_sidebar_state="auto",
16+
)
17+
18+
#st.image("images/splunk-logo-black-small.png")
19+
st.caption(CAPTION)
20+
21+
if "auth_success" not in st.session_state:
22+
st.session_state.auth_success = False
23+
24+
st.session_state.valid_org = False
25+
26+
if not "valid_inputs_received" in st.session_state:
27+
st.session_state.valid_inputs_received = False
28+
29+
with st.form("demo_form") as form:
30+
host = st.text_input("Host", placeholder="hostname")
31+
query = st.selectbox("Query", ("pods", "health"))
32+
submit_button = st.form_submit_button(label="Submit")
33+
34+
if submit_button:
35+
st.cache_data.clear()
36+
st.session_state.valid_inputs_received = True
37+
38+
if st.session_state.valid_inputs_received == False:
39+
st.warning(
40+
"TBD."
41+
)
42+
else:
43+
response = requests.get(f"{host}:5001/{query}")
44+
if query == "pods":
45+
df = pd.DataFrame.from_dict(response.json())
46+
st.dataframe(df)
47+
elif query == "health":
48+
st.write(response.text)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
streamlit
2+
watchdog

workshop/demo-server/app.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from kubernetes import client, config
2+
from flask import Flask, json, jsonify, request
3+
from os import path
4+
import yaml
5+
import pandas as pd
6+
7+
app = Flask(__name__)
8+
9+
config.load_kube_config()
10+
11+
core_v1 = client.CoreV1Api()
12+
apps_v1 = client.AppsV1Api()
13+
14+
15+
@app.route('/pods', methods=['GET'])
16+
def get_pods():
17+
result = core_v1.list_pod_for_all_namespaces(_preload_content=False)
18+
pods = json.loads(result.data)
19+
df = pd.DataFrame(columns=["Namespace", "Name", "Status", "Pod IP"])
20+
21+
for r in pods['items']:
22+
row = (r["metadata"]["namespace"], r["metadata"]["name"], r["status"]["phase"], r["status"]["podIP"])
23+
df.loc[len(df)] = row
24+
25+
return df.to_dict(orient='records')
26+
27+
28+
@app.route('/health', methods=['GET'])
29+
def health():
30+
return "OK"
31+
32+
33+
@app.route('/apply_deployment', methods=['GET'])
34+
def deployment():
35+
filename = request.args.get('type', default = 'deployment.yaml', type = str)
36+
namespace = request.args.get('namespace', default = 'default', type = str)
37+
with open(path.join(path.dirname(__file__), filename)) as f:
38+
deployment = yaml.safe_load(f)
39+
resp = apps_v1.create_namespaced_deployment(
40+
body=deployment, namespace=namespace, _preload_content=False)
41+
return resp.json()
42+
43+
44+
@app.route('/delete_deployment', methods=['GET'])
45+
def delete_deployment():
46+
filename = request.args.get('type', default = 'deployment.yaml', type = str)
47+
namespace = request.args.get('namespace', default = 'default', type = str)
48+
resp = apps_v1.delete_namespaced_deployment(name="nginx-deployment", namespace=namespace, _preload_content=False)
49+
return resp.json()
50+
51+
if __name__ == '__main__':
52+
app.run(host="0.0.0.0", port=5001, debug=True)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
flask
2+
kubernetes
3+
pandas

0 commit comments

Comments
 (0)