Skip to content

Commit

Permalink
Merge branch 'issue3042' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Dec 22, 2024
2 parents a20362d + 0e9e74f commit 077d5fe
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
32 changes: 30 additions & 2 deletions glances/outputs/glances_restful_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from urllib.parse import urljoin

from glances import __apiversion__, __version__
from glances.events_list import glances_events
from glances.globals import json_dumps
from glances.logger import logger
from glances.password import GlancesPassword
Expand Down Expand Up @@ -211,9 +212,17 @@ def _router(self) -> APIRouter:
# Create the main router
router = APIRouter(prefix=self.url_prefix)

# REST API
# REST API route definition
# ==========================

# HEAD
router.add_api_route(f'{base_path}/status', self._api_status, methods=['HEAD', 'GET'])

# POST
router.add_api_route(f'{base_path}/events/clear/warning', self._events_clear_warning, methods=['POST'])
router.add_api_route(f'{base_path}/events/clear/all', self._events_clear_all, methods=['POST'])

# GET
route_mapping = {
f'{base_path}/config': self._api_config,
f'{base_path}/config/{{section}}': self._api_config_section,
Expand Down Expand Up @@ -242,7 +251,6 @@ def _router(self) -> APIRouter:
f'{plugin_path}/{{item}}/{{key}}': self._api_key,
f'{plugin_path}/{{item}}/{{key}}/views': self._api_key_views,
}

for path, endpoint in route_mapping.items():
router.add_api_route(path, endpoint)

Expand Down Expand Up @@ -357,6 +365,26 @@ def _api_status(self):

return GlancesJSONResponse({'version': __version__})

def _events_clear_warning(self):
"""Glances API RESTful implementation.
Return a 200 status code.
It's a post message to clean warning events
"""
glances_events.clean()
return GlancesJSONResponse({})

def _events_clear_all(self):
"""Glances API RESTful implementation.
Return a 200 status code.
It's a post message to clean all events
"""
glances_events.clean(critical=True)
return GlancesJSONResponse({})

def _api_help(self):
"""Glances API RESTful implementation.
Expand Down
15 changes: 15 additions & 0 deletions glances/outputs/static/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ body {
margin-bottom: 1em;
}

.clear-button {
background-color: $glances-link-hover-color !important;
color: white;
border: none;
text-align: center;
text-decoration: none;
display: inline-block;
transition-duration: 0.4s;
}

.clear-button:hover {
background-color: white;
color: black;
}

#system {
span {
padding-left: 10px;
Expand Down
12 changes: 12 additions & 0 deletions glances/outputs/static/js/components/plugin-alert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<section class="plugin" id="alerts">
<span class="title" v-if="hasAlerts">
Warning or critical alerts (last {{ countAlerts }} entries)
<span>
<button class="clear-button" v-on:click="clear()">Clear alerts</button>
</span>
</span>
<span class="title" v-else>No warning or critical alert detected</span>
<table class="table table-sm table-borderless">
Expand Down Expand Up @@ -105,6 +108,15 @@ export default {
':' + String(date.getMinutes()).padStart(2, '0') +
':' + String(date.getSeconds()).padStart(2, '0') +
'(' + tzString + ')';
},
clear() {
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
};
fetch('api/4/events/clear/all', requestOptions)
.then(response => response.json())
.then(data => product.value = data);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion glances/outputs/static/public/browser.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions glances/outputs/static/public/glances.js

Large diffs are not rendered by default.

0 comments on commit 077d5fe

Please sign in to comment.