Spaces:
Running
Running
Upload streamlit_app.py with huggingface_hub
Browse files- streamlit_app.py +25 -3
streamlit_app.py
CHANGED
|
@@ -67,17 +67,39 @@ if 'analysis_results' not in st.session_state:
|
|
| 67 |
with st.sidebar:
|
| 68 |
st.header("Configuration")
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
# Zabbix API Configuration
|
| 71 |
with st.expander("Zabbix API Settings", expanded=True):
|
| 72 |
zabbix_url = st.text_input("Zabbix API URL", value=ZABBIX_API_URL)
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
if st.button("Connect to Zabbix"):
|
| 77 |
with st.spinner("Connecting to Zabbix..."):
|
| 78 |
try:
|
| 79 |
zabbix = ZabbixAPI(zabbix_url)
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
if auth_token:
|
| 82 |
st.session_state.zabbix_auth_token = auth_token
|
| 83 |
st.success("Successfully connected to Zabbix!")
|
|
|
|
| 67 |
with st.sidebar:
|
| 68 |
st.header("Configuration")
|
| 69 |
|
| 70 |
+
# Authentication method selection
|
| 71 |
+
auth_method = st.radio(
|
| 72 |
+
"Authentication Method",
|
| 73 |
+
["Username/Password", "API Token"],
|
| 74 |
+
index=0
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
# Zabbix API Configuration
|
| 78 |
with st.expander("Zabbix API Settings", expanded=True):
|
| 79 |
zabbix_url = st.text_input("Zabbix API URL", value=ZABBIX_API_URL)
|
| 80 |
+
|
| 81 |
+
if auth_method == "Username/Password":
|
| 82 |
+
zabbix_user = st.text_input("Username", value="Admin")
|
| 83 |
+
zabbix_password = st.text_input("Password", type="password")
|
| 84 |
+
else:
|
| 85 |
+
zabbix_token = st.text_input("API Token", type="password")
|
| 86 |
|
| 87 |
if st.button("Connect to Zabbix"):
|
| 88 |
with st.spinner("Connecting to Zabbix..."):
|
| 89 |
try:
|
| 90 |
zabbix = ZabbixAPI(zabbix_url)
|
| 91 |
+
|
| 92 |
+
if auth_method == "Username/Password":
|
| 93 |
+
auth_token = zabbix.authenticate(zabbix_user, zabbix_password)
|
| 94 |
+
else:
|
| 95 |
+
# For API token authentication, we'll validate it by making a simple API call
|
| 96 |
+
auth_token = zabbix_token
|
| 97 |
+
# Test the token by making a simple API call
|
| 98 |
+
test_result = zabbix.test_token_auth(auth_token)
|
| 99 |
+
if not test_result:
|
| 100 |
+
st.error("Invalid API token")
|
| 101 |
+
auth_token = None
|
| 102 |
+
|
| 103 |
if auth_token:
|
| 104 |
st.session_state.zabbix_auth_token = auth_token
|
| 105 |
st.success("Successfully connected to Zabbix!")
|