1212 is_valid_file ,
1313 show_targets ,
1414 prometheus_yml_path ,
15- update_prometheus_container )
15+ update_prometheus_container ,
16+ update_prometheus_config )
17+
1618
1719
1820# Define the Prometheus Blueprint
@@ -61,9 +63,17 @@ def delete_file_path(id):
6163
6264@app .route ('/targets' )
6365def targets ():
66+ update_prometheus_config ()
67+ # update_prometheus_container()
6468 targets_info = show_targets ()
6569 return render_template ('other/targets.html' , targets_info = targets_info )
6670
71+ @app .route ('/targets/restart_prometheus' )
72+ def restart_prometheus ():
73+ update_prometheus_config
74+ update_prometheus_container ()
75+ flash ('Prometheus container restarted successfully!' , 'success' )
76+ return redirect (url_for ('dashboard_network' ))
6777
6878@app .route ('/targets/add_target' , methods = ['POST' ])
6979def add_target ():
@@ -72,6 +82,11 @@ def add_target():
7282 scrape_interval = request .form .get ('scrape_interval' , '15s' ) + 's' # New scrape interval
7383 config = load_yaml (prometheus_yml_path )
7484
85+ # new target should be <ip>:<port> check if it is in the correct format
86+ if ':' not in new_target :
87+ flash ('Invalid target format. It should be in the format <ip>:<port>.' , 'danger' )
88+ return redirect (url_for ('dashboard_network' ))
89+
7590 for scrape_config in config ['scrape_configs' ]:
7691 if scrape_config ['job_name' ] == job_name :
7792 scrape_config ['static_configs' ][0 ]['targets' ].append (new_target )
@@ -127,7 +142,7 @@ def change_interval():
127142 scrape_config ['scrape_interval' ] = new_interval
128143 flash ('Scrape interval updated successfully!' , 'success' )
129144 break
130-
145+
131146 save_yaml (config , prometheus_yml_path )
132147 update_prometheus_container ()
133148 return redirect (url_for ('targets' ))
0 commit comments