new: Fetch the exiting collection names from the monitoring interface

pull/628/head
Raphaël Vinot 2023-03-02 20:51:14 +01:00
parent 089c007280
commit 7a96ae9767
3 changed files with 21 additions and 1 deletions

View File

@ -120,6 +120,8 @@ class Lookyloo():
self.monitoring = PyLookylooMonitoring(monitoring_config['url'], get_useragent_for_requests())
if self.monitoring.is_up:
self.monitoring_enabled = True
# NOTE: maybe move that somewhere else: we'll need to restart the webserver
# if we change the settings in the monitoring instance
self.monitoring_settings = self.monitoring.instance_settings()
self.logger.info('Initializing context...')

View File

@ -709,6 +709,13 @@ def tree(tree_uuid: str, node_uuid: Optional[str]=None):
if cache.error:
flash(cache.error, 'warning')
if lookyloo.monitoring_enabled:
try:
monitoring_collections = lookyloo.monitoring.collections()
except Exception as e:
monitoring_collections = []
flash(f'Unable to get existing connections from the monitoring : {e}', 'warning')
return render_template('tree.html', tree_json=ct.to_json(),
info=cache,
tree_uuid=tree_uuid, public_domain=lookyloo.public_domain,
@ -717,6 +724,7 @@ def tree(tree_uuid: str, node_uuid: Optional[str]=None):
meta=meta, enable_mail_notification=enable_mail_notification,
enable_monitoring=lookyloo.monitoring_enabled,
monitoring_settings=lookyloo.monitoring_settings if lookyloo.monitoring_enabled else None,
monitoring_collections=monitoring_collections if lookyloo.monitoring_enabled else [],
enable_context_by_users=enable_context_by_users,
enable_categorization=enable_categorization,
enable_bookmark=enable_bookmark,

View File

@ -740,8 +740,18 @@
{% endif %}
</div>
<div class="mb-3">
<label for="collection" class="form-label">Collection</label>
{% if monitoring_collections %}
<label for="collection" class="form-label">Pick a collection.</label>
<input type="text" class="form-control" list="collections" id="collection" name="collection" placeholder="Type a collection name, or select an existing one (arrow down to see them)">
<datalist id="collections">
{% for name in monitoring_collections %}
<option value="{{name}}">{{name}}</option>
{% endfor %}
</datalist>
{%else%}
<label for=collection" class="form-label">Add to a collection.</label>
<input type="text" class="form-control" name="collection" id="collection" placeholder="Name of the collection">
{% endif %}
</div>
<div class="mb-3 form-check">
<input class="form-check-input" type="checkbox" name="confirm" onchange="document.getElementById('btn-notification').disabled = !this.checked;"></input>